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

1 line
22 KiB
Plaintext

{"version":3,"sources":["js/bootstrap-cascader.js"],"names":["$","DEF_OPTS","splitChar","btnCls","placeHolder","dropUp","lazy","openOnHover","onChange","noop","selectable","item","loaded","children","length","TPLS","enHtml","value","String","replace","DropdownPanel","data","csd","panel","this","selectItem","itemEl","params","call","setItemOpened","panelEl","removeClass","addClass","selectItemByCode","code","trigger","setSelected","setOpen","c","scrollToOpened","isMatchedSelectedItems","currItem","j","level","selectedItem","selectedItems","selectedItemCode","currItemData","originData","parent","find","size","scrollTop","top","position","height","handler","itemCode","loadingItem","loadData","then","refreshPanels","always","appendTo","el","lastPanel","panels","lastPanelEl","lastPanelLeft","Number","css","left","outerWidth","push","each","i","itemData","itemName","name","n","attr","text","bind","openTimeout","clearTimeout","setTimeout","destroy","remove","Cascader","def","initialized","readonly","Array","convertData2Col","isLazy","d","childMap","hasChild","updateBtnText","btn","getValue","setValue","clearValue","names","oldSelectedItems","join","updateViewBySelected","panelNo","rmPanels","splice","rmPanel","unshift","close","open","toggleClass","slice","setReadonly","isReadonly","openedItems","defered","Deferred","resolve","reject","promise","cols","insertAfter","click","e","preventDefault","stopPropagation","hasClass","cascader","target","parents","fn","bsCascader","args","arguments","$this","extend","val","split","apply","prototype","jQuery"],"mappings":"CAAA,SAAWA,GACT,aAGA,IAAIC,EAAW,CACbC,UAAW,IACXC,OAAQ,cACRC,YAAa,MACbC,QAAQ,EACRC,MAAM,EACNC,aAAa,EACbC,SAAUR,EAAES,KACZC,WAAY,SAAUC,GACpB,OAAOA,GAAQA,EAAKC,UAAYD,EAAKE,UAAYF,EAAKE,SAASC,QAAU,GAAKH,EAAKD,cAKnFK,EACY,mDADZA,EAEM,kPAFNA,EAKW,kCALXA,EAMe,mSAUfC,EAAS,SAAUC,GACrB,OAAQA,EAAaC,OAAOD,GAAOE,QAAQ,KAAM,SAASA,QAAQ,KAAM,QAAQA,QAAQ,KAAM,QAA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AI0C,IAChB1C,EAAI6E,IAAItF,SAAS,eAAeiH,MAAM,SAAUC,GAC9CzG,EAAIgF,aACJyB,EAAEC,iBACFD,EAAEE,oBAEJ/B,EAAcvE,EAAOvB,aA8JnBkB,EAAIK,OAAOgE,UAAUrE,EAAI8F,aAAY,GAEzC9F,EAAIqC,WAAWG,OAAO,WACpBxC,EAAIuC,cAAc,EAAGvC,EAAID,MACrBC,EAAIK,OAAOV,OAAOK,EAAI+E,SAAS/E,EAAIK,OAAOV,SAGhDjB,EAAE,QAAQ8H,MAAM,SAAUC,GACxB,GAAKzG,EAAI0C,GAAGkE,SAAS,QAArB,CACA,IAAIC,EAAWnI,EAAE+H,EAAEK,QAAQC,QAAQ,uBACZ,GAAnBF,EAAShF,OAAa7B,EAAI0F,QACrBmB,EAAS,IAAM7G,EAAI0C,GAAG,IAAI1C,EAAI0F,YAI3ChH,EAAEsI,GAAGC,WAAa,SAAU5G,GAC1B,IAAI6G,EAAOC,UACX,OAAOjH,KAAKkD,KAAK,WACf,GAAKlD,KAAL,CACA,IAAIkH,EAAQ1I,EAAEwB,MAEV+G,EAAaG,EAAMrH,KAAK,cACvBkH,IACH5G,EAAS3B,EAAE2I,OAAO,CAChB3E,GAAI0E,EAAOzH,MAAOyH,EAAME,MAAQF,EAAME,MAAMC,MAAMlH,EAAOzB,WAAa,KAAO,IAC5EyB,GACH4G,EAAa,IAAI/C,EAAS7D,GAC1B+G,EAAMrH,KAAK,aAAckH,IAEL,iBAAX5G,GACT4G,EAAW5G,GAAQmH,MAAMP,EAAY3C,MAAMmD,UAAU5B,MAAMvF,KAAK4G,EAAM,QAzX9E,CA6XGQ","file":"bootstrap-cascader-dcbf0e3207.min.js","sourcesContent":["(function ($) {\n 'use strict';\n\n // DEF_OPTS\n var DEF_OPTS = {\n splitChar: ' ',\n btnCls: 'btn-default',\n placeHolder: '请选择',\n dropUp: false,\n lazy: false,\n openOnHover: false,\n onChange: $.noop,\n selectable: function (item) {\n return item && item.loaded && (!item.children || item.children.length <= 0 || item.selectable);\n }\n };\n\n // TPLS\n var TPLS = {\n containerTpl: '<div class=\"btn-group bootstrap-cascader\"></div>',\n btnTpl: '<button class=\"btn dropdown-toggle bs-placeholder\" type=\"button\">\\\n <span class=\"filter-option pull-left\"></span> <span class=\"caret icon-arrow-down\"></span> <span class=\"icon-cross iconfont icon-jiaochacross78\"></span>\\\n </button>',\n dropdownTpl: '<ul class=\"dropdown-menu\"></ul>',\n dropdownItemTpl: '<li>\\\n <a href=\"javascript:\">\\\n <span class=\"text\"></span>\\\n <span class=\"iconfont icon-ico-right-arrow item-right-arrow\"></span>\\\n <span class=\"iconfont icon-loading item-loading\"></span>\\\n <span class=\"iconfont icon-error\"></span>\\\n </a>\\\n </li>'\n };\n\n var enHtml = function (value) {\n return !value ? '' : String(value).replace(/&/g, \"&amp;\").replace(/>/g, \"&gt;\").replace(/</g, \"&lt;\").replace(/\"/g, \"&quot;\");\n };\n\n // DropdownPanel\n var DropdownPanel = function (data, csd) {\n if (!data || !data.children || data.children.length <= 0) return;\n\n var panel = this;\n this.selectItem = function (item, itemEl) {\n var selectable = csd.params.selectable.call(csd, item);\n if (selectable) csd.selectItem(itemEl);\n };\n\n this.setItemOpened = function (item, itemEl) {\n panel.panelEl.children('li').removeClass('open');\n itemEl.addClass('open');\n if (item.loaded && item.children.length == 0) itemEl.addClass('no-child');\n };\n\n this.selectItemByCode = function (code) {\n panel.panelEl.children('li[code=' + enHtml(code) + ']').trigger('selectItem');\n };\n\n this.setSelected = function (item, setOpen) {\n var itemEl = panel.panelEl.children('li[code=' + enHtml(item.code || item.c) + ']');\n itemEl.children('a').addClass('selected');\n if (setOpen) panel.setItemOpened(item, itemEl);\n panel.scrollToOpened();\n };\n\n this.isMatchedSelectedItems = function (item) {\n var currItem = item;\n for (var j = item.level - 1; j >= 0; j--) {\n var selectedItem = csd.selectedItems[j], selectedItemCode = selectedItem.code || selectedItem.c;\n var currItemData = currItem.originData, currItemCode = currItemData.code || currItemData.c;\n if (selectedItemCode != currItemCode) return false;\n currItem = currItem.parent;\n }\n return true;\n };\n\n this.scrollToOpened = function () {\n var panelEl = panel.panelEl, selectedItem = panelEl.find('li a.selected').parent();\n if (selectedItem.size() > 0) {\n var scrollTop = panelEl.scrollTop(), top = selectedItem.position().top + scrollTop;\n if (scrollTop < top) {\n top = top - (panelEl.height() - selectedItem.height()) / 2;\n panelEl.scrollTop(top);\n }\n }\n };\n\n var handler = function (item, itemEl, selectItem) {\n if (csd.params.lazy && item.loaded === false) {\n itemEl.addClass('loading');\n var itemCode = item.code || item.c;\n\n if (panel.loadingItem) panel.loadingItem = false;\n panel.loadingItem = itemCode;\n\n csd.loadData(item).then(function () {\n if (panel.loadingItem == itemCode)\n csd.refreshPanels(item.level + 1, item);\n }, function () {\n if (panel.loadingItem == itemCode)\n itemEl.addClass('load-error');\n }).always(function () {\n if (panel.loadingItem == itemCode) {\n panel.setItemOpened(item, itemEl);\n panel.loadingItem = false;\n }\n itemEl.removeClass('loading');\n });\n } else {\n csd.refreshPanels(item.level + 1, item);\n panel.setItemOpened(item, itemEl);\n if (selectItem) panel.selectItem(item, itemEl);\n }\n };\n\n panel.panelEl = $(TPLS.dropdownTpl).appendTo(csd.el), panel.data = data;\n\n // set panel position\n var lastPanel = csd.panels[csd.panels.length - 1];\n if (lastPanel) {\n var lastPanelEl = lastPanel.panelEl, lastPanelLeft = Number((lastPanelEl.css('left') || '').replace('px', ''));\n panel.panelEl.css({left: lastPanelLeft + lastPanelEl.outerWidth()})\n }\n csd.panels.push(panel);\n\n // update panel style\n if (csd.panels.length > 0) {\n csd.el.children('.dropdown-menu').removeClass('first-child last-child');\n csd.panels[0].panelEl.addClass('first-child');\n csd.panels[csd.panels.length - 1].panelEl.addClass('last-child');\n }\n\n $.each(data.children, function (i, item) {\n var itemEl = $(TPLS.dropdownItemTpl).appendTo(panel.panelEl), itemData = item.originData;\n var itemName = itemData.name || itemData.n, itemCode = itemData.code || itemData.c;\n itemEl.data(\"cascaderItem\", item).attr('code', itemCode).attr('title', itemName).find('.text').text(itemName);\n\n itemEl.bind('selectItem click', function () {\n handler(item, itemEl, true);\n }).bind('openDropdown', function () {\n handler(item, itemEl);\n });\n\n if (csd.params.openOnHover) {\n itemEl.bind('mouseover', function () {\n if (csd.openTimeout) clearTimeout(csd.openTimeout);\n csd.openTimeout = setTimeout(function () {\n handler(item, itemEl);\n }, csd.params.lazy ? 200 : 100);\n });\n }\n\n if (item.loaded && (!item.children || item.children.length <= 0)) itemEl.addClass('no-child');\n\n // update selected items view state\n if (csd.selectedItems.length >= item.level && panel.isMatchedSelectedItems(item)) {\n if (csd.selectedItems.length > item.level) {\n handler(item, itemEl, false);\n } else {\n $.each(csd.selectedItems, function (j, selectedItem) {\n csd.panels[j].setSelected(selectedItem, j < csd.selectedItems.length - 1);\n });\n }\n }\n });\n\n this.destroy = function () {\n panel.panelEl.remove();\n };\n };\n\n // Cascader\n var Cascader = function (params) {\n var csd = this;\n params = params || {};\n for (var def in DEF_OPTS) if (typeof params[def] === 'undefined') params[def] = DEF_OPTS[def];\n csd.params = params, csd.initialized = false, csd.selectedItems = [], csd.readonly = false;\n if (csd.params.value instanceof Array) csd.selectedItems = [];\n\n // initBtn\n var initBtn = function () {\n csd.btn = $(TPLS.btnTpl).addClass(params.btnCls).click(function () {\n csd.open();\n }).appendTo(csd.el);\n csd.btn.children('.icon-cross').click(function (e) {\n csd.clearValue();\n e.preventDefault();\n e.stopPropagation();\n });\n updateBtnText(params.placeHolder);\n };\n\n // convertData2Col\n var convertData2Col = function (data, parent) {\n var isLazy = csd.params.lazy;\n $.each(data, function (i, item) {\n var itemCode = item.code || item.c, children = item.data || item.d;\n var itemData = {\n childMap: {}, children: [], loaded: !isLazy || item.hasChild === false,\n level: parent.level + 1, parent: parent, originData: item\n };\n parent.children.push(itemData);\n parent.childMap[itemCode] = itemData;\n if (children && children.length > 0) convertData2Col(children, itemData);\n });\n };\n\n // updateBtnText\n var updateBtnText = function (text) {\n csd.btn.attr('title', text).children('.filter-option').text(text);\n if (csd.getValue().length > 0) csd.btn.removeClass('bs-placeholder').addClass('selected');\n else csd.btn.addClass('bs-placeholder').removeClass('selected');\n };\n\n // setValue\n csd.setValue = function (value) {\n csd.clearValue();\n\n var names = [], oldSelectedItems = csd.getValue;\n $.each(value, function (i, item) {\n csd.selectedItems.push({code: item.code || item.c, name: item.name || item.n});\n names.push(item.name || item.n);\n });\n updateBtnText(names.join(csd.params.splitChar));\n csd.updateViewBySelected();\n csd.params.onChange(oldSelectedItems, value);\n };\n\n // refreshPanels\n csd.refreshPanels = function (panelNo, data) {\n var rmPanels = csd.panels.splice(panelNo - 1, csd.panels.length);\n if (rmPanels) $.each(rmPanels, function (i, rmPanel) {\n rmPanel.destroy();\n });\n\n new DropdownPanel(data, csd);\n };\n\n // selectItem\n csd.selectItem = function (itemEl) {\n csd.el.find('li a').removeClass('selected');\n itemEl.children('a').addClass('selected');\n csd.el.find('li.open a').addClass('selected');\n\n var item = itemEl.data('cascaderItem'), names = [], oldSelectedItems = csd.getValue();\n csd.selectedItems = [];\n while (item.parent) {\n var itemData = item.originData, code = itemData.code || itemData.c, name = itemData.name || itemData.n;\n csd.selectedItems.unshift({code: code, name: name});\n names.unshift(name);\n item = item.parent;\n }\n\n updateBtnText(names.join(csd.params.splitChar));\n csd.close();\n\n csd.params.onChange(oldSelectedItems, csd.getValue());\n };\n\n // close\n csd.close = function () {\n csd.el.removeClass('open');\n csd.updateViewBySelected();\n };\n\n // update view by selected\n csd.updateViewBySelected = function () {\n if (csd.selectedItems.length > 0)\n csd.panels[0].selectItemByCode(csd.selectedItems[0].code || csd.selectedItems[0].c);\n };\n\n // open\n csd.open = function () {\n if (csd.readonly) return;\n csd.el.toggleClass('open');\n\n $.each(csd.panels, function (i, panel) {\n panel.scrollToOpened();\n });\n };\n\n // getValue\n csd.getValue = function () {\n return csd.selectedItems.slice();\n };\n\n // clearValue\n csd.clearValue = function () {\n if (csd.readonly) return;\n\n csd.selectedItems = [];\n csd.el.find('.dropdown-menu li a').removeClass('selected');\n updateBtnText(csd.params.placeHolder);\n };\n\n // setReadonly\n csd.setReadonly = function (readonly) {\n readonly = readonly !== false;\n csd.readonly = readonly;\n if (readonly) {\n csd.el.addClass('readonly');\n csd.btn.addClass('disabled');\n } else {\n csd.el.removeClass('readonly');\n csd.btn.removeClass('disabled');\n }\n };\n\n // isReadonly\n csd.isReadonly = function () {\n return csd.readonly;\n };\n\n // loadData\n csd.loadData = function (item) {\n // get opened items\n var openedItems = [];\n if (item) {\n var currItem = item;\n while (currItem.parent) {\n openedItems.unshift(currItem.originData);\n currItem = currItem.parent;\n }\n } else item = csd.data;\n\n var defered = $.Deferred();\n csd.params.loadData.call(csd, openedItems, function (data) {\n if (data) {\n if (data.length > 0) {\n if (!openedItems || openedItems.length <= 0) csd.data.originData = data;\n convertData2Col(data, item);\n }\n item.loaded = true;\n defered.resolve(data);\n } else defered.reject();\n });\n return defered.promise();\n };\n\n csd.data = {childMap: {}, children: [], loaded: false, level: 0}, csd.panels = [];\n csd.cols = [], csd.el = $(TPLS.containerTpl);\n if (csd.params.replace) {\n csd.el.insertAfter(params.el);\n params.el.remove();\n } else csd.el.appendTo(params.el);\n params.el = csd.el;\n initBtn();\n if (csd.params.readonly) csd.setReadonly(true);\n\n csd.loadData().always(function () {\n csd.refreshPanels(1, csd.data);\n if (csd.params.value) csd.setValue(csd.params.value);\n });\n\n $('html').click(function (e) {\n if (!csd.el.hasClass('open')) return;\n var cascader = $(e.target).parents('.bootstrap-cascader');\n if (cascader.size() == 0) csd.close();\n else if (cascader[0] != csd.el[0]) csd.close();\n });\n };\n\n $.fn.bsCascader = function (params) {\n var args = arguments;\n return this.each(function () {\n if (!this) return;\n var $this = $(this);\n\n var bsCascader = $this.data(\"bsCascader\");\n if (!bsCascader) {\n params = $.extend({\n el: $this, value: $this.val() ? $this.val().split(params.splitChar || ' ') : ''\n }, params);\n bsCascader = new Cascader(params);\n $this.data(\"bsCascader\", bsCascader);\n }\n if (typeof params === typeof \"a\")\n bsCascader[params].apply(bsCascader, Array.prototype.slice.call(args, 1));\n });\n }\n\n})(jQuery);\n"]}