You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
18 KiB
2 lines
18 KiB
/* jQuery Tree Multiselect v2.6.3 | (c) Patrick Tsai | MIT Licensed */
|
|
!function r(n,s,a){function o(t,e){if(!s[t]){if(!n[t]){var i="function"==typeof require&&require;if(!e&&i)return i(t,!0);if(c)return c(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}i=s[t]={exports:{}},n[t][0].call(i.exports,function(e){return o(n[t][1][e]||e)},i,i.exports,r,n,s,a)}return s[t].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)o(a[e]);return o}({1:[function(e,t,i){"use strict";jQuery.fn.treeMultiselect=e("./tree-multiselect/main")},{"./tree-multiselect/main":6}],2:[function(e,t,i){"use strict";var r="searchhit",n="false";i.addSearchHitMarker=function(e,t){e&&e.setAttribute(r,t=t?"true":n)},i.removeSearchHitMarker=function(e,t){e&&e.removeAttribute(r)},i.isNotSearchHit=function(e){return e&&e.getAttribute(r)===n}},{}],3:[function(e,t,i){"use strict";var r=e("./item"),n=e("./section");i.createLookup=function(e){return{arr:e,children:{}}},i.createSection=function(e){return new n(e)},i.createItem=function(e){return new r(e)}},{"./item":4,"./section":5}],4:[function(e,t,i){"use strict";var r=e("./common"),n=e("../utility");function s(e){this.treeId=(e=e||{}).treeId,this.id=e.id,this.value=e.value,this.text=e.text,this.description=e.description,this.initialIndex=e.initialIndex?parseInt(e.initialIndex):null,this.section=e.section,this.disabled=e.disabled,this.selected=e.selected,this.node=null}s.prototype.isSection=function(){return!1},s.prototype.isItem=function(){return!0},s.prototype.addSearchHitMarker=function(e){r.addSearchHitMarker(this.node,e)},s.prototype.removeSearchHitMarker=function(e){r.removeSearchHitMarker(this.node,e)},s.prototype.isNotSearchHit=function(){return r.isNotSearchHit(this.node)},s.prototype.render=function(e,t){return this.node||(this.node=n.dom.createSelection(this,e,t)),this.node},t.exports=s},{"../utility":12,"./common":2}],5:[function(e,t,i){"use strict";var r=e("./common"),n=e("../utility");function s(e){this.treeId=(e=e||{}).treeId,this.id=e.id,this.name=e.name,this.items=[],this.node=null}s.prototype.isSection=function(){return!0},s.prototype.isItem=function(){return!1},s.prototype.addSearchHitMarker=function(e){r.addSearchHitMarker(this.node,e)},s.prototype.removeSearchHitMarker=function(e){r.removeSearchHitMarker(this.node,e)},s.prototype.isNotSearchHit=function(){return r.isNotSearchHit(this.node)},s.prototype.render=function(e,t){return this.node||(this.node=n.dom.createSection(this,e,t)),this.node},t.exports=s},{"../utility":12,"./common":2}],6:[function(e,t,i){"use strict";var n=e("./tree"),s=0;t.exports=function(e){var i=this,r=jQuery.extend({},{allowBatchSelection:!0,collapsible:!0,enableSelectAll:!1,selectAllText:"Select All",unselectAllText:"Unselect All",freeze:!1,hideSidePanel:!1,maxSelections:0,onChange:null,onlyBatchSelection:!1,searchable:!1,searchParams:["value","text","description","section"],sectionDelimiter:"/",showSectionOnSelected:!0,sortable:!1,startCollapsed:!1},e);return this.map(function(){var e=i,t=(e.attr("multiple","").css("display","none"),new n(s,e,r));return t.initialize(),++s,{reload:function(){t.reload()},remove:function(){t.remove()}}})}},{"./tree":8}],7:[function(e,t,i){"use strict";var a=e("./utility");function r(e,t,i,r){this.searchHitAttr=e,this.index={},this.astItems=t,this.astItemKeys=Object.keys(t),this.astSections=i,this.astSectionKeys=Object.keys(i),this.setSearchParams(r),this.buildIndex()}r.prototype.setSearchParams=function(e){a.assert(Array.isArray(e));var t={value:!0,text:!0,description:!0,section:!0};this.searchParams=[];for(var i=0;i<e.length;++i)t[e[i]]&&this.searchParams.push(e[i])},r.prototype.buildIndex=function(){var e,r=this;for(e in this.astItems)!function(e){var t=r.astItems[e],i=[];r.searchParams.forEach(function(e){i.push(t[e])}),a.array.removeFalseyExceptZero(i),i.map(function(e){return e.toLowerCase()}).forEach(function(e){e.split(" ").forEach(function(e){r._addToIndex(e,t.id)})})}(e)},r.prototype._addToIndex=function(e,t){for(var i=1;i<=3;++i)for(var r=0;r<e.length-i+1;++r){var n=e.substring(r,r+i),s=(this.index[n]||(this.index[n]=[]),this.index[n].length);0!==s&&this.index[n][s-1]===t||this.index[n].push(t)}},r.prototype.search=function(e){var t,i=this;(e=e.trim())?(e=(e=e.toLowerCase()).split(" ").filter(function(e){return e}),t=[],e.forEach(function(e){(function(e){if(a.assert(e),e.length<3)return[e];for(var t=[],i=0;i<e.length-3+1;++i)t.push(e.substring(i,i+3));return t})(e).forEach(function(e){t.push(i.index[e]||[])})}),e=a.array.intersectMany(t),this.handleNodeVisibilities(e)):(this.astItemKeys.forEach(function(e){i.astItems[e].removeSearchHitMarker()}),this.astSectionKeys.forEach(function(e){i.astSections[e].removeSearchHitMarker()}))},r.prototype.handleNodeVisibilities=function(e){var r=this,n={},s={};e.forEach(function(e){n[e]=!0;for(var t=(t=r.astItems[e].node).parentNode;!t.className.match(/tree-multiselect/);){if(t.className.match(/section/)){var i=a.getKey(t);if(a.assert(i||0===i),s[i])break;s[i]=!0}t=t.parentNode}}),this.astItemKeys.forEach(function(e){var t=!!n[e];r.astItems[e].addSearchHitMarker(t)}),this.astSectionKeys.forEach(function(e){var t=!!s[e];r.astSections[e].addSearchHitMarker(t)})},t.exports=r},{"./utility":12}],8:[function(e,t,i){"use strict";function p(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){var i;if(e)return"string"==typeof e?r(e,t):"Map"===(i="Object"===(i=Object.prototype.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:i)||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?r(e,t):void 0}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,r=new Array(t);i<t;i++)r[i]=e[i];return r}var f=e("./ast"),n=e("./search"),s=e("./ui-builder"),m=e("./utility"),a="searchhit";function o(e,t,i){this.id=e,this.$originalSelect=t,this.params=i,this.resetState()}o.prototype.initialize=function(){var e;this.generateSelections(this.$selectionContainer[0]),this.popupDescriptionHover(),this.params.allowBatchSelection&&this.handleSectionCheckboxMarkings(),this.params.collapsible&&this.addCollapsibility(),(this.params.searchable||this.params.enableSelectAll)&&(e=m.dom.createNode("div",{class:"auxiliary"}),this.$selectionContainer.prepend(e,this.$selectionContainer.firstChild),this.params.searchable&&this.createSearchBar(e),this.params.enableSelectAll&&this.createSelectAllButtons(e)),this.armRemoveSelectedOnClick(),this.updateSelectedAndOnChange(),this.render(!0),this.uiBuilder.attach()},o.prototype.remove=function(){this.uiBuilder.remove(),this.resetState()},o.prototype.reload=function(){var t=this,r={};this.selectedKeys.forEach(function(e){e=t.astItems[e].value;r[e]=!0}),this.remove(),this.$originalSelect.children("option").each(function(e,t){var i=t.value;r[i]?t.setAttribute("selected","selected"):t.removeAttribute("selected")}),this.initialize(),this.render(!0)},o.prototype.resetState=function(){this.uiBuilder=new s(this.$originalSelect,this.params.hideSidePanel),this.$treeContainer=this.uiBuilder.$treeContainer,this.$selectionContainer=this.uiBuilder.$selectionContainer,this.$selectedContainer=this.uiBuilder.$selectedContainer,this.astItems={},this.astSections={},this.selectedNodes={},this.selectedKeys=[],this.keysToAdd=[],this.keysToRemove=[]},o.prototype.generateSelections=function(e){var t=this.$originalSelect.children("option"),t=this.createAst(t);this.generateHtml(t,e)},o.prototype.createAst=function(e){var t=[],o=f.createLookup(t),c=this,l=0,d=0,h=[],u=[];return e.each(function(){for(var e=this,e=(e.setAttribute("data-key",l),f.createItem({treeId:c.id,id:l,value:e.value,text:e.text,description:e.getAttribute("data-description"),initialIndex:e.getAttribute("data-index"),section:e.getAttribute("data-section"),disabled:e.hasAttribute("readonly"),selected:e.hasAttribute("selected")})),t=(e.initialIndex&&e.selected?(h[e.initialIndex]=h[e.initialIndex]||[],h[e.initialIndex].push(l)):e.selected&&u.push(l),c.astItems[l]=e,++l,o),i=e.section,r=i&&0<i.length?i.split(c.params.sectionDelimiter):[],n=0;n<r.length;++n)var s,a=r[n],t=t.children[a]||(s=f.createSection({treeId:c.id,id:d,name:a}),++d,t.arr.push(s),s=f.createLookup(s.items),t.children[a]=s);t.arr.push(e)}),this.keysToAdd=m.array.flatten(h),m.array.removeFalseyExceptZero(this.keysToAdd),(e=this.keysToAdd).push.apply(e,u),m.array.uniq(this.keysToAdd),t},o.prototype.generateHtml=function(e,t){for(var i=0;i<e.length;++i){var r,n,s=e[i];s.isSection()?(this.astSections[s.id]=s,n=this.params.allowBatchSelection,r=this.params.freeze,n=s.render(n,r),t.appendChild(n),this.generateHtml(s.items,n)):s.isItem()&&(this.astItems[s.id]=s,r=!this.params.onlyBatchSelection,n=this.params.freeze,s=s.render(r,n),t.appendChild(s))}},o.prototype.popupDescriptionHover=function(){this.$selectionContainer.on("mouseenter","div.item > span.description",function(){var e=jQuery(this).parent(),t=e.attr("data-description"),i=document.createElement("div");i.className="temp-description-popup",i.innerHTML=t,i.style.position="absolute",e.append(i)}),this.$selectionContainer.on("mouseleave","div.item > span.description",function(){jQuery(this).parent().find("div.temp-description-popup").remove()})},o.prototype.handleSectionCheckboxMarkings=function(){var r=this;this.$selectionContainer.on("click","input.section[type=checkbox]",function(){var e,t=jQuery(this).closest("div.section").find("div.item").map(function(e,t){var t=m.getKey(t),i=r.astItems[t];return i.disabled||i.isNotSearchHit()?null:t}).get();this.checked?((e=r.keysToAdd).push.apply(e,p(t)),m.array.uniq(r.keysToAdd)):((e=r.keysToRemove).push.apply(e,p(t)),m.array.uniq(r.keysToRemove)),r.render()})},o.prototype.redrawSectionCheckboxes=function(e){e=e||this.$selectionContainer;var t=3,i=this;if(e.find("> div.section").each(function(){var e=i.redrawSectionCheckboxes(jQuery(this));t&=e}),t)for(var r=e.find("> div.item > input[type=checkbox]"),n=0;n<r.length&&(r[n].checked?t&=-3:t&=-2,0!==t);++n);e=e.find("> div.title > input[type=checkbox]");return e.length&&(e=e[0],1&t?(e.checked=!0,e.indeterminate=!1):2&t?(e.checked=!1,e.indeterminate=!1):(e.checked=!1,e.indeterminate=!0)),t},o.prototype.addCollapsibility=function(){var e="div.title",t=this.$selectionContainer.find(e),i=m.dom.createNode("span",{class:"collapse-section"}),t=(t.prepend(i),this.$selectionContainer.find("div.section"));this.params.startCollapsed&&t.addClass("collapsed"),this.$selectionContainer.on("click",e,function(e){"INPUT"!==e.target.nodeName&&(jQuery(this).parent().toggleClass("collapsed"),e.stopPropagation())})},o.prototype.createSearchBar=function(e){var t=new n(a,this.astItems,this.astSections,this.params.searchParams),i=m.dom.createNode("input",{class:"search",placeholder:"Search..."});e.appendChild(i),this.$selectionContainer.on("input","input.search",function(){var e=this.value;t.search(e)})},o.prototype.createSelectAllButtons=function(e){var t=m.dom.createNode("span",{class:"select-all",text:this.params.selectAllText}),i=m.dom.createNode("span",{class:"unselect-all",text:this.params.unselectAllText}),r=m.dom.createNode("div",{class:"select-all-container"}),n=(r.appendChild(t),r.appendChild(i),e.appendChild(r),this);this.$selectionContainer.on("click","span.select-all",function(){var e;(e=n.keysToAdd).push.apply(e,p(n.unfilteredNodeIds())),n.render()}),this.$selectionContainer.on("click","span.unselect-all",function(){var e;(e=n.keysToRemove).push.apply(e,p(n.unfilteredNodeIds())),n.render()})},o.prototype.unfilteredNodeIds=function(){var t=this;return Object.keys(t.astItems).filter(function(e){return!t.astItems[e].node.hasAttribute(a)||"true"===t.astItems[e].node.getAttribute(a)})},o.prototype.armRemoveSelectedOnClick=function(){var t=this;this.$selectedContainer.on("click","span.remove-selected",function(){var e=this.parentNode,e=m.getKey(e);t.keysToRemove.push(e),t.render()})},o.prototype.updateSelectedAndOnChange=function(){var i,r,n=this;this.$selectionContainer.on("click","input.option[type=checkbox]",function(){var e=this.parentNode,e=m.getKey(e);m.assert(e||0===e),(this.checked?n.keysToAdd:n.keysToRemove).push(e),n.render()}),this.params.sortable&&!this.params.freeze&&(r=i=null,this.$selectedContainer.sortable({start:function(e,t){i=t.item.index()},stop:function(e,t){r=t.item.index(),i!==r&&(m.array.moveEl(n.selectedKeys,i,r),n.render())}}))},o.prototype.render=function(e){var t=this;m.array.uniq(this.keysToAdd),m.array.uniq(this.keysToRemove),m.array.subtract(this.keysToAdd,this.selectedKeys),m.array.intersect(this.keysToRemove,this.selectedKeys),m.isInteger(this.params.maxSelections)&&0<this.params.maxSelections&&((h=this.keysToAdd.length-this.keysToRemove.length+this.selectedKeys.length)>this.params.maxSelections&&(u=[],(h=h-this.params.maxSelections)>this.selectedKeys.length?(u.push.apply(u,p(this.selectedKeys)),h-=this.selectedKeys.length,u.push.apply(u,p(this.keysToAdd.splice(0,h)))):u.push.apply(u,p(this.selectedKeys.slice(0,h))),(h=this.keysToRemove).push.apply(h,u)));for(var i=0;i<this.keysToRemove.length;++i){var r=this.selectedNodes[this.keysToRemove[i]];r&&(r.parentNode.removeChild(r),this.selectedNodes[this.keysToRemove[i]]=null),this.astItems[this.keysToRemove[i]].node.getElementsByTagName("INPUT")[0].checked=!1}m.array.subtract(this.selectedKeys,this.keysToRemove);for(var n=0;n<this.keysToAdd.length;++n){var s=this.keysToAdd[n],a=this.astItems[s],s=(this.selectedKeys.push(s),m.dom.createSelected(a,this.params.freeze,this.params.showSectionOnSelected)),s=(this.selectedNodes[a.id]=s,this.$selectedContainer.append(s),a.node.getElementsByTagName("INPUT")[0]);s&&(s.checked=!0)}(h=this.selectedKeys).push.apply(h,p(this.keysToAdd)),m.array.uniq(this.selectedKeys),this.redrawSectionCheckboxes();for(var o={},c={},l=0;l<this.selectedKeys.length;++l){var d=this.astItems[this.selectedKeys[l]].value;o[this.selectedKeys[l]]=!0,c[d]=l}var h,u=this.$originalSelect.find("option").toArray();u.sort(function(e,t){return(c[e.value]||0)-(c[t.value]||0)}),this.$originalSelect.html(u),this.$originalSelect.find("option").each(function(e,t){this.selected=!!o[m.getKey(t)]}),this.$originalSelect.change(),!e&&this.params.onChange&&(h=this.selectedKeys.map(function(e){return t.astItems[e]}),u=this.keysToAdd.map(function(e){return t.astItems[e]}),e=this.keysToRemove.map(function(e){return t.astItems[e]}),this.params.onChange(h,u,e)),this.keysToRemove=[],this.keysToAdd=[]},t.exports=o},{"./ast":3,"./search":7,"./ui-builder":9,"./utility":12}],9:[function(e,t,i){"use strict";function r(e,t){var i=jQuery('<div class="tree-multiselect"></div>'),r=jQuery('<div class="selections"></div>'),n=(t&&r.addClass("no-border"),i.append(r),jQuery('<div class="selected"></div>'));t||i.append(n),this.$el=e,this.$treeContainer=i,this.$selectionContainer=r,this.$selectedContainer=n}r.prototype.attach=function(){this.$el.after(this.$treeContainer)},r.prototype.remove=function(){this.$treeContainer.remove()},t.exports=r},{}],10:[function(e,t,r){"use strict";function n(e,t){for(var i=0,r=0;r<e.length;++r)t(e[r])&&(e[i]=e[r],++i);e.length=i}r.flatten=function(e,t){if(!Array.isArray(e))return e;t=t||[];for(var i=0;i<e.length;++i)Array.isArray(e[i])?t.concat(r.flatten(e[i],t)):t.push(e[i]);return t},r.uniq=function(e){var i={};n(e,function(e){var t=!i[e];return i[e]=!0,t})},r.removeFalseyExceptZero=function(e){n(e,function(e){return e||0===e})},r.moveEl=function(e,t,i){var r=e[t];e.splice(t,1),e.splice(i,0,r)},r.subtract=function(e,t){for(var i={},r=0;r<t.length;++r)i[t[r]]=!0;n(e,function(e){return!i[e]})},r.intersect=function(e,t){for(var i={},r=0;r<t.length;++r)i[t[r]]=!0;n(e,function(e){return i[e]})},r.intersectMany=function(e){for(var t=[],i=[],r=(e.forEach(function(e){t.push(0),i.push(e.length-1)}),[]);0<t.length&&t[0]<=i[0];++t[0]){for(var n=!1,s=1;s<e.length;++s){for(;e[s][t[s]]<e[0][t[0]]&&t[s]<=i[s];)++t[s];if(t[s]>i[s]){n=!0;break}}if(n)break;for(var a=!0,o=1;o<e.length;++o)if(e[0][t[0]]!==e[o][t[o]]){a=!1;break}a&&r.push(e[0][t[0]])}return r}},{}],11:[function(e,t,s){"use strict";s.createNode=function(e,t){var i=document.createElement(e);if(t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&"text"!==r&&i.setAttribute(r,t[r]);t.text&&(i.textContent=t.text)}return i},s.createSelection=function(e,t,i){var r={class:"item","data-key":e.id,"data-value":e.value},n=!!e.description,r=(n&&(r["data-description"]=e.description),e.initialIndex&&(r["data-index"]=e.initialIndex),s.createNode("div",r));return n&&(n=s.createNode("span",{class:"description",text:"?"}),r.appendChild(n)),t?(t={class:"option",type:"checkbox",id:n="treemultiselect-".concat(e.treeId,"-").concat(e.id)},(i||e.disabled)&&(t.disabled=!0),i=s.createNode("input",t),r.insertBefore(i,r.firstChild),t={class:e.disabled?"disabled":"",for:n,text:e.text||e.value},i=s.createNode("label",t),r.appendChild(i)):r.innerText=e.text||e.value,r},s.createSelected=function(e,t,i){var r=s.createNode("div",{class:"item","data-key":e.id,"data-value":e.value,text:e.text});return t||e.disabled||(t=s.createNode("span",{class:"remove-selected",text:"×"}),r.insertBefore(t,r.firstChild)),i&&(t=s.createNode("span",{class:"section-name",text:e.section}),r.appendChild(t)),r},s.createSection=function(e,t,i){var r=s.createNode("div",{class:"section","data-key":e.id}),e=s.createNode("div",{class:"title",text:e.name});return t&&(t={class:"section",type:"checkbox"},i&&(t.disabled=!0),i=s.createNode("input",t),e.insertBefore(i,e.firstChild)),r.appendChild(e),r}},{}],12:[function(e,t,i){"use strict";i.array=e("./array"),i.assert=function(e,t){if(!e)throw new Error(t||"Assertion failed")},i.dom=e("./dom"),i.getKey=function(e){return i.assert(e),parseInt(e.getAttribute("data-key"))},i.isInteger=function(e){return!isNaN(e)&&(0|(e=parseFloat(e)))===e}},{"./array":10,"./dom":11}]},{},[1]);
|