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

3 lines
6.8 KiB
JavaScript
Raw Normal View History

2019-11-13 09:54:59 +00:00
!function(i){"use strict";var l={splitChar:" ",btnCls:"btn-default",placeHolder:"请选择",dropUp:!1,lazy:!1,openOnHover:!1,onChange:i.noop,selectable:function(e){return e&&e.loaded&&(!e.children||e.children.length<=0||e.selectable)}},n='<div class="btn-group bootstrap-cascader"></div>',t='<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 iconfont icon-jiaochacross78"></span> </button>',s='<ul class="dropdown-menu"></ul>',d='<li> <a href="javascript:"> <span class="text"></span> <span class="iconfont icon-ico-right-arrow item-right-arrow"></span> <span class="iconfont icon-loading item-loading"></span> <span class="iconfont icon-error"></span> </a> </li>',p=function(e){return e?String(e).replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/"/g,"&quot;"):""},o=function(e,o){if(e&&e.children&&!(e.children.length<=0)){var c=this;this.selectItem=function(e,a){o.params.selectable.call(o,e)&&o.selectItem(a)},this.setItemOpened=function(e,a){c.panelEl.children("li").removeClass("open"),a.addClass("open"),e.loaded&&0==e.children.length&&a.addClass("no-child")},this.selectItemByCode=function(e){c.panelEl.children("li[code="+p(e)+"]").trigger("selectItem")},this.setSelected=function(e,a){var l=c.panelEl.children("li[code="+p(e.code||e.c)+"]");l.children("a").addClass("selected"),a&&c.setItemOpened(e,l),c.scrollToOpened()},this.isMatchedSelectedItems=function(e){for(var a=e,l=e.level-1;0<=l;l--){var n=o.selectedItems[l],t=n.code||n.c,s=a.originData;if(t!=(s.code||s.c))return!1;a=a.parent}return!0},this.scrollToOpened=function(){var e=c.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))}};var r=function(e,a,l){if(o.params.lazy&&!1===e.loaded){a.addClass("loading");var n=e.code||e.c;c.loadingItem&&(c.loadingItem=!1),c.loadingItem=n,o.loadData(e).then(function(){c.loadingItem==n&&o.refreshPanels(e.level+1,e)},function(){c.loadingItem==n&&a.addClass("load-error")}).always(function(){c.loadingItem==n&&(c.setItemOpened(e,a),c.loadingItem=!1),a.removeClass("loading")})}else o.refreshPanels(e.level+1,e),c.setItemOpened(e,a),l&&c.selectItem(e,a)};c.panelEl=i(s).appendTo(o.el),c.data=e;var a=o.panels[o.panels.length-1];if(a){var l=a.panelEl,n=Number((l.css("left")||"").replace("px",""));c.panelEl.css({left:n+l.outerWidth()})}o.panels.push(c),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")),i.each(e.children,function(e,a){var l=i(d).appendTo(c.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.bind("selectItem click",function(){r(a,l,!0)}).bind("openDropdown",function(){r(a,l)}),o.params.openOnHover&&l.bind("mouseover",function(){o.openTimeout&&clearTimeout(o.openTimeout),o.openTimeout=setTimeout(function(){r(a,l)},o.params.lazy?200:100)}),a.loaded&&(!a.children||a.children.length<=0)&&l.addClass("no-child"),o.selectedItems.length>=a.level&&c.isMatchedSelectedItems(a)&&(o.selectedItems.length>a.level?r(a,l,!1):i.each(o.selectedItems,function(e,a){o.panels[e].setSelected(a,e<o.selectedItems.length-1)}))}),this.destroy=function(){c.panelEl.remove()}}},c=function(e){var c=this;for(var a in e=e||{},l)"undefined"==typeof e[a]&&(e[a]=l[a]);c.params=e,c.initialized=!1,c.selectedItems=[],c.readonly=!1,c.params.value instanceof Array&&(c.selectedItems=[]);var r=function(e,s){var o=c.params.lazy;i.each(e,function(e,a){var l=a.code||a.c,n=a.data||a.d,t={childMap:{},children:[],loaded:!o||!1===a.hasChild,level:s.level+1,parent:s,originData:a};s.children.push(t),s.childMap[l]=t,n&&0<n.length&&r(n,t)})},d=function(e){c.btn.attr("title",e).children(".filter-option").text(e),0<c.getValue().length?c.btn.removeClass("bs-placeh
//# sourceMappingURL=bootstrap-cascader-dcbf0e3207.min.js.map