linbei/static/bootstrap.dropdown.cascade/js/bootstrap-cascader.min.js

3 lines
8.1 KiB
JavaScript
Raw Normal View History

2019-11-13 09:54:59 +00:00
!function(p){"use strict";var n={splitChar:" ",cls:"",btnCls:"btn-default",placeHolder:"请选择",dropUp:!1,lazy:!1,openOnHover:!1,openOnHoverDelay:100,openOnHoverDelay4Lazy:200,isSelectable:function(e){return e&&e.loaded&&(!e.children||e.children.length<=0||e.selectable)}},t='<div class="btn-group bootstrap-cascader form-control"></div>',s='<button class="btn dropdown-toggle bs-placeholder" type="button"> <span class="filter-option pull-left"></span> <span class="caret icon-arrow-down"></span> <span class="icon-cross bsfont icon-jiaochacross78"></span> </button>',u='<ul class="dropdown-menu"></ul>',h='<li> <a href="javascript:"> <span class="text"></span> <span class="bsfont icon-ico-right-arrow item-right-arrow"></span> <span class="bsfont icon-loading item-loading"></span> <span class="bsfont icon-error"></span> </a> </li>',m=function(e){return e?String(e).replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/"/g,"&quot;"):""},r=function(e,o){if(e&&e.children&&!(e.children.length<=0)){var r=this;this.selectItem=function(e,a){o.params.isSelectable.call(o,e)&&o.selectItem(a)},this.setItemOpened=function(e,a){r.panelEl.children("li").removeClass("open"),a.addClass("open"),e.loaded&&0==e.children.length&&a.addClass("no-child")},this.selectItemByCode=function(e){r.panelEl.children("li[code="+m(e)+"]").trigger("selectItem")},this.setSelected=function(e,a){var l=r.panelEl.children("li[code="+m(e.code||e.c)+"]");l.children("a").addClass("selected"),a&&r.setItemOpened(e,l),r.scrollToOpened()},this.isMatchedSelectedItems=function(e,a){for(var l=e,n=e.level-1;0<=n;n--){var t=o.selectedItems[n],s=t.code||t.c,r=l.originData;if(s!=(r.code||r.c))return!1;if(!1===a)return!0;l=l.parent}return!0},this.scrollToOpened=function(){var e=r.panelEl,a=e.find("li a.selected").parent();if(0<a.size()){var l=e.scrollTop(),n=a.position().top+l;l<n&&(n-=(e.height()-a.height())/2,e.scrollTop(n))}},this.destroy=function(){r.panelEl.remove()};var d=function(e,a,l){if(o.params.lazy&&!1===e.loaded){a.addClass("bs-loading");var n=e.code||e.c;r.loadingItem&&(r.loadingItem=!1),r.loadingItem=n,o.loadData(e).then(function(){r.loadingItem==n&&o.refreshPanels(e.level+1,e)},function(){r.loadingItem==n&&a.addClass("load-error")}).always(function(){r.loadingItem==n&&(r.setItemOpened(e,a),r.loadingItem=!1),a.removeClass("bs-loading")})}else o.refreshPanels(e.level+1,e),r.setItemOpened(e,a),l&&r.selectItem(e,a)};r.panelEl=p(u).appendTo(o.el),r.data=e;var a=o.panels[o.panels.length-1];if(a){var l=a.panelEl,n=Number((l.css("left")||"").replace("px",""));r.panelEl.css({left:n+l.outerWidth()})}o.panels.push(r),0<o.panels.length&&(o.el.children(".dropdown-menu").removeClass("first-child last-child"),o.panels[0].panelEl.addClass("first-child"),o.panels[o.panels.length-1].panelEl.addClass("last-child"));var c=!1,i=!1;o.selectedItems.length>e.level&&(c=r.isMatchedSelectedItems(e)),p.each(e.children,function(e,a){var l=p(h).appendTo(r.panelEl),n=a.originData,t=n.name||n.n,s=n.code||n.c;l.data("cascaderItem",a).attr("code",s).attr("title",t).find(".text").text(t),l.on({"selectItem click":function(){d(a,l,!0)},openDropdown:function(){d(a,l)}}),o.params.openOnHover&&l.on("mouseover",function(){o.openTimeout&&clearTimeout(o.openTimeout),o.openTimeout=setTimeout(function(){d(a,l)},o.params.lazy?o.params.openOnHoverDelay4Lazy:o.params.openOnHoverDelay)}),a.loaded&&(!a.children||a.children.length<=0)&&l.addClass("no-child"),o.selectedItems.length>=a.level&&c&&r.isMatchedSelectedItems(a,!1)&&(i=!0,o.selectedItems.length>a.level?d(a,l,!1):(o.selectedItems.length==o.panels.length&&p.each(o.selectedItems,function(e,a){o.panels[e].setSelected(a,e<o.selectedItems.length-1)}),o.inited(),o.reloaded()))}),(!o.isInited||o.reloading)&&o.selectedItems.length>e.level&&!i&&o.params.lazy&&(o.isInited?o.reloaded():o.inited())}},o=function(e){var d=this;for(var a in e=e||{},n)"undefined"==typeof e[a]&&(e[a]=n[a]);d.params=e,d.initialized=!1,d.selectedItems=[],d.readonly=!1,d.params.value instanceof Array&&(d.se
//# sourceMappingURL=bootstrap-cascader.min.js.map