2025-01-12 04:36:52 +08:00

2 lines
56 KiB
JavaScript

(function(d,k){typeof define=="function"&&define.amd?define(["jquery"],k):typeof module=="object"&&typeof module.exports=="object"?module.exports=k(require("jquery")):d.Selectize=k(d.jQuery)})(this,function(d){"use strict";var k=function(e,t){if(!(typeof t=="string"&&!t.length)){var i=typeof t=="string"?new RegExp(t,"i"):t,n=function(r){var s=0;if(r.nodeType===3){var o=r.data.search(i);if(o>=0&&r.data.length>0){var a=r.data.match(i),l=document.createElement("span");l.className="highlight";var c=r.splitText(o),u=c.splitText(a[0].length),f=c.cloneNode(!0);l.appendChild(f),c.parentNode.replaceChild(l,c),s=1}}else if(r.nodeType===1&&r.childNodes&&!/(script|style)/i.test(r.tagName)&&(r.className!=="highlight"||r.tagName!=="SPAN"))for(var h=0;h<r.childNodes.length;++h)h+=n(r.childNodes[h]);return s};return e.each(function(){n(this)})}};d.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;var e=this.parentNode;e.replaceChild(this.firstChild,this),e.normalize()}).end()};var N=function(){};N.prototype={on:function(e,t){this._events=this._events||{},this._events[e]=this._events[e]||[],this._events[e].push(t)},off:function(e,t){var i=arguments.length;if(i===0)return delete this._events;if(i===1)return delete this._events[e];this._events=this._events||{},e in this._events&&this._events[e].splice(this._events[e].indexOf(t),1)},trigger:function(e){const t=this._events=this._events||{};if(e in t)for(var i=0;i<t[e].length;i++)t[e][i].apply(this,Array.prototype.slice.call(arguments,1))}},N.mixin=function(e){for(var t=["on","off","trigger"],i=0;i<t.length;i++)e.prototype[t[i]]=N.prototype[t[i]]};var Y={};Y.mixin=function(e){e.plugins={},e.prototype.initializePlugins=function(t){var i,n,r,s=this,o=[];if(s.plugins={names:[],settings:{},requested:{},loaded:{}},we(t))for(i=0,n=t.length;i<n;i++)typeof t[i]=="string"?o.push(t[i]):(s.plugins.settings[t[i].name]=t[i].options,o.push(t[i].name));else if(t)for(r in t)t.hasOwnProperty(r)&&(s.plugins.settings[r]=t[r],o.push(r));for(;o.length;)s.require(o.shift())},e.prototype.loadPlugin=function(t){var i=this,n=i.plugins,r=e.plugins[t];if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin');n.requested[t]=!0,n.loaded[t]=r.fn.apply(i,[i.plugins.settings[t]||{}]),n.names.push(t)},e.prototype.require=function(t){var i=this,n=i.plugins;if(!i.plugins.loaded.hasOwnProperty(t)){if(n.requested[t])throw new Error('Plugin has circular dependency ("'+t+'")');i.loadPlugin(t)}return n.loaded[t]},e.define=function(t,i){e.plugins[t]={name:t,fn:i}}};const G=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,i)=>t+=(i&=63)<36?i.toString(36):i<62?(i-26).toString(36).toUpperCase():i>62?"-":"_","");var A=function(e,t){this.items=e,this.settings=t||{diacritics:!0}};A.prototype.tokenize=function(e,t){if(e=se(String(e||"").toLowerCase()),!e||!e.length)return[];var i,n,r,s,o=[],a=e.split(/ +/);for(i=0,n=a.length;i<n;i++){if(r=oe(a[i]),this.settings.diacritics)for(s in D)D.hasOwnProperty(s)&&(r=r.replace(new RegExp(s,"g"),D[s]));t&&(r="\\b"+r),o.push({string:a[i],regex:new RegExp(r,"i")})}return o},A.prototype.iterator=function(e,t){var i;H(e)?i=Array.prototype.forEach||function(n){for(var r=0,s=this.length;r<s;r++)n(this[r],r,this)}:i=function(n){for(var r in this)this.hasOwnProperty(r)&&n(this[r],r,this)},i.apply(e,[t])},A.prototype.getScoreFunction=function(e,t){var i,n,r,s,o;i=this,e=i.prepareSearch(e,t),r=e.tokens,n=e.options.fields,s=r.length,o=e.options.nesting;var a=function(c,u){var f,h;return!c||(c=String(c||""),h=c.search(u.regex),h===-1)?0:(f=u.string.length/c.length,h===0&&(f+=.5),f)},l=function(){var c=n.length;return c?c===1?function(u,f){return a(W(f,n[0],o),u)}:function(u,f){for(var h=0,g=0;h<c;h++)g+=a(W(f,n[h],o),u);return g/c}:function(){return 0}}();return s?s===1?function(c){return l(r[0],c)}:e.options.conjunction==="and"?function(c){for(var u,f=0,h=0;f<s;f++){if(u=l(r[f],c),u<=0)return 0;h+=u}return h/s}:function(c){for(var u=0,f=0;u<s;u++)f+=l(r[u],c);return f/s}:function(){return 0}},A.prototype.getSortFunction=function(e,t){var i,n,r,s,o,a,l,c,u,f,h;if(r=this,e=r.prepareSearch(e,t),h=!e.query&&t.sort_empty||t.sort,u=function(g,v){return g==="$score"?v.score:W(r.items[v.id],g,t.nesting)},o=[],h)for(i=0,n=h.length;i<n;i++)(e.query||h[i].field!=="$score")&&o.push(h[i]);if(e.query){for(f=!0,i=0,n=o.length;i<n;i++)if(o[i].field==="$score"){f=!1;break}f&&o.unshift({field:"$score",direction:"desc"})}else for(i=0,n=o.length;i<n;i++)if(o[i].field==="$score"){o.splice(i,1);break}for(c=[],i=0,n=o.length;i<n;i++)c.push(o[i].direction==="desc"?-1:1);return a=o.length,a?a===1?(s=o[0].field,l=c[0],function(g,v){return l*Q(u(s,g),u(s,v))}):function(g,v){var y,O,p,x,_;for(y=0;y<a;y++)if(_=o[y].field,O=c[y]*Q(u(_,g),u(_,v)),O)return O;return 0}:null},A.prototype.prepareSearch=function(e,t){if(typeof e=="object")return e;t=re({},t);var i=t.fields,n=t.sort,r=t.sort_empty;return i&&!H(i)&&(t.fields=[i]),n&&!H(n)&&(t.sort=[n]),r&&!H(r)&&(t.sort_empty=[r]),{options:t,query:String(e||"").toLowerCase(),tokens:this.tokenize(e,t.respect_word_boundaries),total:0,items:[]}},A.prototype.search=function(e,t){var i=this,n,r,s,o,a,l;return s=this.prepareSearch(e,t),t=s.options,e=s.query,l=t.score||i.getScoreFunction(s),e.length?i.iterator(i.items,function(c,u){r=l(c),(t.filter===!1||r>0)&&s.items.push({score:r,id:u})}):i.iterator(i.items,function(c,u){s.items.push({score:1,id:u})}),a=i.getSortFunction(s,t),a&&s.items.sort(a),s.total=s.items.length,typeof t.limit=="number"&&(s.items=s.items.slice(0,t.limit)),s};var Q=function(e,t){return typeof e=="number"&&typeof t=="number"?e>t?1:e<t?-1:0:(e=U(String(e||"")),t=U(String(t||"")),e>t?1:t>e?-1:0)},re=function(e,t){var i,n,r,s;for(i=1,n=arguments.length;i<n;i++)if(s=arguments[i],!!s)for(r in s)s.hasOwnProperty(r)&&(e[r]=s[r]);return e},W=function(e,t,i){if(!(!e||!t)){if(!i)return e[t];for(var n=t.split(".");n.length&&(e=e[n.shift()]););return e}},se=function(e){return(e+"").replace(/^\s+|\s+$|/g,"")},oe=function(e){return(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},H=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"},D={a:"[a\u1E00\u1E01\u0102\u0103\xC2\xE2\u01CD\u01CE\u023A\u2C65\u0226\u0227\u1EA0\u1EA1\xC4\xE4\xC0\xE0\xC1\xE1\u0100\u0101\xC3\xE3\xC5\xE5\u0105\u0104\xC3\u0105\u0104]",b:"[b\u2422\u03B2\u0392B\u0E3F\u{10301}\u16D2]",c:"[c\u0106\u0107\u0108\u0109\u010C\u010D\u010A\u010BC\u0304c\u0304\xC7\xE7\u1E08\u1E09\u023B\u023C\u0187\u0188\u0255\u1D04\uFF23\uFF43]",d:"[d\u010E\u010F\u1E0A\u1E0B\u1E10\u1E11\u1E0C\u1E0D\u1E12\u1E13\u1E0E\u1E0F\u0110\u0111D\u0326d\u0326\u0189\u0256\u018A\u0257\u018B\u018C\u1D6D\u1D81\u1D91\u0221\u1D05\uFF24\uFF44\xF0]",e:"[e\xC9\xE9\xC8\xE8\xCA\xEA\u1E18\u1E19\u011A\u011B\u0114\u0115\u1EBC\u1EBD\u1E1A\u1E1B\u1EBA\u1EBB\u0116\u0117\xCB\xEB\u0112\u0113\u0228\u0229\u0118\u0119\u1D92\u0246\u0247\u0204\u0205\u1EBE\u1EBF\u1EC0\u1EC1\u1EC4\u1EC5\u1EC2\u1EC3\u1E1C\u1E1D\u1E16\u1E17\u1E14\u1E15\u0206\u0207\u1EB8\u1EB9\u1EC6\u1EC7\u2C78\u1D07\uFF25\uFF45\u0258\u01DD\u018F\u0190\u03B5]",f:"[f\u0191\u0192\u1E1E\u1E1F]",g:"[g\u0262\u20B2\u01E4\u01E5\u011C\u011D\u011E\u011F\u0122\u0123\u0193\u0260\u0120\u0121]",h:"[h\u0124\u0125\u0126\u0127\u1E28\u1E29\u1E96\u1E96\u1E24\u1E25\u1E22\u1E23\u0266\u02B0\u01F6\u0195]",i:"[i\xCD\xED\xCC\xEC\u012C\u012D\xCE\xEE\u01CF\u01D0\xCF\xEF\u1E2E\u1E2F\u0128\u0129\u012E\u012F\u012A\u012B\u1EC8\u1EC9\u0208\u0209\u020A\u020B\u1ECA\u1ECB\u1E2C\u1E2D\u0197\u0268\u0268\u0306\u1D7B\u1D96\u0130iI\u0131\u026A\uFF29\uFF49]",j:"[j\u0237\u0134\u0135\u0248\u0249\u029D\u025F\u02B2]",k:"[k\u0198\u0199\uA740\uA741\u1E30\u1E31\u01E8\u01E9\u1E32\u1E33\u1E34\u1E35\u03BA\u03F0\u20AD]",l:"[l\u0141\u0142\u013D\u013E\u013B\u013C\u0139\u013A\u1E36\u1E37\u1E38\u1E39\u1E3C\u1E3D\u1E3A\u1E3B\u013F\u0140\u023D\u019A\u2C60\u2C61\u2C62\u026B\u026C\u1D85\u026D\u0234\u029F\uFF2C\uFF4C]",n:"[n\u0143\u0144\u01F8\u01F9\u0147\u0148\xD1\xF1\u1E44\u1E45\u0145\u0146\u1E46\u1E47\u1E4A\u1E4B\u1E48\u1E49N\u0308n\u0308\u019D\u0272\u0220\u019E\u1D70\u1D87\u0273\u0235\u0274\uFF2E\uFF4E\u014A\u014B]",o:"[o\xD8\xF8\xD6\xF6\xD3\xF3\xD2\xF2\xD4\xF4\u01D1\u01D2\u0150\u0151\u014E\u014F\u022E\u022F\u1ECC\u1ECD\u019F\u0275\u01A0\u01A1\u1ECE\u1ECF\u014C\u014D\xD5\xF5\u01EA\u01EB\u020C\u020D\u0555\u0585]",p:"[p\u1E54\u1E55\u1E56\u1E57\u2C63\u1D7D\u01A4\u01A5\u1D71]",q:"[q\uA756\uA757\u02A0\u024A\u024B\uA758\uA759q\u0303]",r:"[r\u0154\u0155\u024C\u024D\u0158\u0159\u0156\u0157\u1E58\u1E59\u0210\u0211\u0212\u0213\u1E5A\u1E5B\u2C64\u027D]",s:"[s\u015A\u015B\u1E60\u1E61\u1E62\u1E63\uA7A8\uA7A9\u015C\u015D\u0160\u0161\u015E\u015F\u0218\u0219S\u0308s\u0308]",t:"[t\u0164\u0165\u1E6A\u1E6B\u0162\u0163\u1E6C\u1E6D\u01AE\u0288\u021A\u021B\u1E70\u1E71\u1E6E\u1E6F\u01AC\u01AD]",u:"[u\u016C\u016D\u0244\u0289\u1EE4\u1EE5\xDC\xFC\xDA\xFA\xD9\xF9\xDB\xFB\u01D3\u01D4\u0170\u0171\u016C\u016D\u01AF\u01B0\u1EE6\u1EE7\u016A\u016B\u0168\u0169\u0172\u0173\u0214\u0215\u222A]",v:"[v\u1E7C\u1E7D\u1E7E\u1E7F\u01B2\u028B\uA75E\uA75F\u2C71\u028B]",w:"[w\u1E82\u1E83\u1E80\u1E81\u0174\u0175\u1E84\u1E85\u1E86\u1E87\u1E88\u1E89]",x:"[x\u1E8C\u1E8D\u1E8A\u1E8B\u03C7]",y:"[y\xDD\xFD\u1EF2\u1EF3\u0176\u0177\u0178\xFF\u1EF8\u1EF9\u1E8E\u1E8F\u1EF4\u1EF5\u024E\u024F\u01B3\u01B4]",z:"[z\u0179\u017A\u1E90\u1E91\u017D\u017E\u017B\u017C\u1E92\u1E93\u1E94\u1E95\u01B5\u01B6]"},U=function(){var e,t,i,n,r="",s={};for(i in D)if(D.hasOwnProperty(i))for(n=D[i].substring(2,D[i].length-1),r+=n,e=0,t=n.length;e<t;e++)s[n.charAt(e)]=i;var o=new RegExp("["+r+"]","g");return function(a){return a.replace(o,function(l){return s[l]}).toLowerCase()}}(),P=ne("macOS",/Mac/),ae=65,Se=188,le=13,ue=27,B=37,ce=38,pe=80,J=39,de=40,fe=78,z=8,q=46,he=16,ge=P?91:17,ve=P?18:17,X=9,K=1,me=2,Z=!ne("Android",/android/i)&&!!document.createElement("input").validity,ee=function(e){return typeof e!="undefined"},we=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"},F=function(e){return typeof e=="undefined"||e===null?null:typeof e=="boolean"?e?"1":"0":e+""},T=function(e){return(e+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},Ie=function(e){return(e+"").replace(/\$/g,"$$$$")},L={};L.before=function(e,t,i){var n=e[t];e[t]=function(){return i.apply(e,arguments),n.apply(e,arguments)}},L.after=function(e,t,i){var n=e[t];e[t]=function(){var r=n.apply(e,arguments);return i.apply(e,arguments),r}};var ye=function(e){var t=!1;return function(){t||(t=!0,e.apply(this,arguments))}},Oe=function(e,t){var i;return function(){var n=this,r=arguments;window.clearTimeout(i),i=window.setTimeout(function(){e.apply(n,r)},t)}},te=function(e,t,i){var n,r=e.trigger,s={};e.trigger=function(){var o=arguments[0];if(t.indexOf(o)!==-1)s[o]=arguments;else return r.apply(e,arguments)},i.apply(e,[]),e.trigger=r;for(n in s)s.hasOwnProperty(n)&&r.apply(e,s[n])},be=function(e,t,i,n){e.on(t,i,function(r){for(var s=r.target;s&&s.parentNode!==e[0];)s=s.parentNode;return r.currentTarget=s,n.apply(this,[r])})},R=function(e){var t={};if(e===void 0)return console.warn("WARN getInputSelection cannot locate input control"),t;if("selectionStart"in e)t.start=e.selectionStart,t.length=e.selectionEnd-t.start;else if(document.selection){e.focus();var i=document.selection.createRange(),n=document.selection.createRange().text.length;i.moveStart("character",-e.value.length),t.start=i.text.length-n,t.length=n}return t},_e=function(e,t,i){var n,r,s={};if(i)for(n=0,r=i.length;n<r;n++)s[i[n]]=e.css(i[n]);else s=e.css();t.css(s)},ie=function(e,t){return e?(w.$testInput||(w.$testInput=d("<span />").css({position:"absolute",width:"auto",padding:0,whiteSpace:"pre"}),d("<div />").css({position:"absolute",width:0,height:0,overflow:"hidden"}).attr({"aria-hidden":!0}).append(w.$testInput).appendTo("body")),w.$testInput.text(e),_e(t,w.$testInput,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]),w.$testInput.width()):0},Ce=function(e){var t=null,i=function(n,r){var s,o,a,g,l,c,u,f,h;if(n=n||window.event||{},r=r||{},!(n.metaKey||n.altKey)&&!(!r.force&&e.data("grow")===!1)){s=e.val(),n.type&&n.type.toLowerCase()==="keydown"&&(o=n.keyCode,a=o>=48&&o<=57||o>=65&&o<=90||o>=96&&o<=111||o>=186&&o<=222||o===32,o===q||o===z?(h=R(e[0]),h.length?s=s.substring(0,h.start)+s.substring(h.start+h.length):o===z&&h.start?s=s.substring(0,h.start-1)+s.substring(h.start+1):o===q&&typeof h.start!="undefined"&&(s=s.substring(0,h.start)+s.substring(h.start+1))):a&&(u=n.shiftKey,f=String.fromCharCode(n.keyCode),u?f=f.toUpperCase():f=f.toLowerCase(),s+=f));var g=e.attr("readonly")?0:4;l=e.attr("placeholder"),l?c=ie(l,e)+g:c=0,g=Math.max(ie(s,e),c)+g,g!==t&&(t=g,e.width(g),e.triggerHandler("resize"))}};e.on("keydown keyup update blur",i),i()},$e=function(e){var t=document.createElement("div");return t.appendChild(e.cloneNode(!0)),t.innerHTML},Fe=function(e,t){t||(t={});var i="Selectize";console.error(i+": "+e),t.explanation&&(console.group&&console.group(),console.error(t.explanation),console.group&&console.groupEnd())},xe=function(e){try{JSON.parse(e)}catch(t){return!1}return!0};function ne(e,t){return navigator.userAgentData?e===navigator.userAgentData.platform:t.test(navigator.userAgent)}var w=function(e,t){var i,n,r,s,o,a=this;o=e[0],o.selectize=a;var l=window.getComputedStyle&&window.getComputedStyle(o,null);if(s=l?l.getPropertyValue("direction"):o.currentStyle&&o.currentStyle.direction,s=s||e.parents("[dir]:first").attr("dir")||"",a.settings={},++w.count,d.extend(a,{order:0,settings:t,$input:e,tabIndex:e.attr("tabindex")||"",tagType:o.tagName.toLowerCase()==="select"?K:me,rtl:/rtl/i.test(s),eventNS:".selectize-"+new Date().getTime()+"-"+Math.random().toString(36).substr(2,5),highlightedValue:null,isBlurring:!1,isOpen:!1,isDisabled:!1,isRequired:e.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",lastValidValue:"",lastOpenTarget:!1,caretPos:0,loading:0,loadedSearches:{},isDropdownClosing:!1,$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:t.loadThrottle===null?a.onSearchChange:Oe(a.onSearchChange,t.loadThrottle)}),a.sifter=new A(this.options,{diacritics:t.diacritics}),a.settings.options){for(n=0,r=a.settings.options.length;n<r;n++)a.registerOption(a.settings.options[n]);delete a.settings.options}if(a.settings.optgroups){for(n=0,r=a.settings.optgroups.length;n<r;n++)a.registerOptionGroup(a.settings.optgroups[n]);delete a.settings.optgroups}a.settings.mode=a.settings.mode||(a.settings.maxItems===1?"single":"multi"),typeof a.settings.hideSelected!="boolean"&&(a.settings.hideSelected=a.settings.mode==="multi"),a.initializePlugins(a.settings.plugins),a.setupCallbacks(),a.setupTemplates(),a.setup()};return N.mixin(w),Y.mixin(w),d.extend(w.prototype,{setup:function(){var e=this,t=e.settings,i=e.eventNS,n=d(window),r=d(document),s=e.$input,o,a,l,c,u,f,h,g,v,y,O,p,x;if(h=e.settings.mode,y=s.attr("class")||"",x=t.showArrow?"":" no-arrow",o=d("<div>").addClass(t.wrapperClass).addClass(y+" selectize-control").addClass(h),a=d("<div>").addClass(t.inputClass+x+" selectize-input items").appendTo(o),l=d('<input type="text" autocomplete="new-password" autofill="no" />').appendTo(a).attr("tabindex",s.is(":disabled")?"-1":e.tabIndex),f=d(t.dropdownParent||o),c=d("<div>").addClass(t.dropdownClass).addClass(h+" selectize-dropdown").hide().appendTo(f),u=d("<div>").addClass(t.dropdownContentClass+" selectize-dropdown-content").attr("tabindex","-1").appendTo(c),(p=s.attr("id"))&&(l.attr("id",p+"-selectized"),d("label[for='"+p+"']").attr("for",p+"-selectized")),e.settings.copyClassesToDropdown&&c.addClass(y),o.css({width:s[0].style.width}),e.plugins.names.length&&(O="plugin-"+e.plugins.names.join(" plugin-"),o.addClass(O),c.addClass(O)),(t.maxItems===null||t.maxItems>1)&&e.tagType===K&&s.attr("multiple","multiple"),e.settings.placeholder&&l.attr("placeholder",t.placeholder),e.settings.search||(l.attr("readonly",!0),l.attr("inputmode","none"),a.css("cursor","pointer")),!e.settings.splitOn&&e.settings.delimiter){var _=e.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");e.settings.splitOn=new RegExp("\\s*"+_+"+\\s*")}s.attr("autocorrect")&&l.attr("autocorrect",s.attr("autocorrect")),s.attr("autocapitalize")&&l.attr("autocapitalize",s.attr("autocapitalize")),s.is("input")&&(l[0].type=s[0].type),e.$wrapper=o,e.$control=a,e.$control_input=l,e.$dropdown=c,e.$dropdown_content=u,c.on("mouseenter mousedown mouseup click","[data-disabled]>[data-selectable]",function(m){m.stopImmediatePropagation()}),c.on("mouseenter","[data-selectable]",function(){return e.onOptionHover.apply(e,arguments)}),c.on("mouseup click","[data-selectable]",function(){return e.onOptionSelect.apply(e,arguments)}),be(a,"mouseup","*:not(input)",function(){return e.onItemSelect.apply(e,arguments)}),Ce(l),a.on({mousedown:function(){return e.onMouseDown.apply(e,arguments)},click:function(){return e.onClick.apply(e,arguments)}}),l.on({mousedown:function(m){(e.$control_input.val()!==""||e.settings.openOnFocus)&&m.stopPropagation()},keydown:function(){return e.onKeyDown.apply(e,arguments)},keypress:function(){return e.onKeyPress.apply(e,arguments)},input:function(){return e.onInput.apply(e,arguments)},resize:function(){e.positionDropdown.apply(e,[])},blur:function(){return e.onBlur.apply(e,arguments)},focus:function(){return e.onFocus.apply(e,arguments)},paste:function(){return e.onPaste.apply(e,arguments)}}),r.on("keydown"+i,function(m){e.isCmdDown=m[P?"metaKey":"ctrlKey"],e.isCtrlDown=m[P?"altKey":"ctrlKey"],e.isShiftDown=m.shiftKey}),r.on("keyup"+i,function(m){m.keyCode===ve&&(e.isCtrlDown=!1),m.keyCode===he&&(e.isShiftDown=!1),m.keyCode===ge&&(e.isCmdDown=!1)}),r.on("mousedown"+i,function(m){if(e.isFocused){if(m.target===e.$dropdown[0]||e.$dropdown.has(m.target).length)return!1;m.target!==e.$control[0]&&e.blur(m.target)}}),n.on(["scroll"+i,"resize"+i].join(" "),function(){e.isOpen&&e.positionDropdown.apply(e,arguments)}),n.on("mousemove"+i,function(){e.ignoreHover=e.settings.ignoreHover}),this.revertSettings={$children:s.children().detach(),tabindex:s.attr("tabindex")},s.attr("tabindex",-1).hide().after(e.$wrapper),Array.isArray(t.items)&&(e.lastValidValue=t.items,e.setValue(t.items),delete t.items),Z&&s.on("invalid"+i,function(m){m.preventDefault(),e.isInvalid=!0,e.refreshState()}),e.updateOriginalInput(),e.refreshItems(),e.refreshState(),e.updatePlaceholder(),e.isSetup=!0,s.is(":disabled")&&e.disable(),e.on("change",this.onChange),s.data("selectize",e),s.addClass("selectized"),e.trigger("initialize"),t.preload===!0&&e.onSearchChange("")},setupTemplates:function(){var e=this,t=e.settings.labelField,i=e.settings.valueField,n=e.settings.optgroupLabelField,r={optgroup:function(s){return'<div class="optgroup">'+s.html+"</div>"},optgroup_header:function(s,o){return'<div class="optgroup-header">'+o(s[n])+"</div>"},option:function(s,o){var a=s.classes?" "+s.classes:"";a+=s[i]===""?" selectize-dropdown-emptyoptionlabel":"";var l=s.styles?' style="'+s.styles+'"':"";return"<div"+l+' class="option'+a+'">'+o(s[t])+"</div>"},item:function(s,o){return'<div class="item">'+o(s[t])+"</div>"},option_create:function(s,o){return'<div class="create">Add <strong>'+o(s.input)+"</strong>&#x2026;</div>"}};e.settings.render=d.extend({},r,e.settings.render)},setupCallbacks:function(){var e,t,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur",dropdown_item_activate:"onDropdownItemActivate",dropdown_item_deactivate:"onDropdownItemDeactivate"};for(e in i)i.hasOwnProperty(e)&&(t=this.settings[i[e]],t&&this.on(e,t))},onClick:function(e){var t=this;t.isDropdownClosing||(!t.isFocused||!t.isOpen)&&(t.focus(),e.preventDefault())},onMouseDown:function(e){var t=this,i=e.isDefaultPrevented(),n=d(e.target);if(t.isFocused||i||window.setTimeout(function(){t.isOpen||t.focus()},0),n!==t.$control_input[0]||t.$control_input.val()==="")return t.settings.mode==="single"?t.isOpen?t.close():t.open():(i||t.setActiveItem(null),t.settings.openOnFocus||(t.isOpen&&n===t.lastOpenTarget?(t.close(),t.lastOpenTarget=!1):(t.isOpen||(t.refreshOptions(),t.open()),t.lastOpenTarget=n))),!1},onChange:function(){var e=this;e.getValue()!==""&&(e.lastValidValue=e.getValue()),this.$input.trigger("input"),this.$input.trigger("change")},onPaste:function(e){var t=this;if(t.isFull()||t.isInputHidden||t.isLocked){e.preventDefault();return}t.settings.splitOn&&setTimeout(function(){var i=t.$control_input.val();if(!!i.match(t.settings.splitOn))for(var n=i.trim().split(t.settings.splitOn),r=0,s=n.length;r<s;r++)t.createItem(n[r])},0)},onKeyPress:function(e){if(this.isLocked)return e&&e.preventDefault();var t=String.fromCharCode(e.keyCode||e.which);if(this.settings.create&&this.settings.mode==="multi"&&t===this.settings.delimiter)return this.createItem(),e.preventDefault(),!1},onKeyDown:function(e){var t=e.target===this.$control_input[0],i=this;if(i.isLocked){e.keyCode!==X&&e.preventDefault();return}switch(e.keyCode){case ae:if(i.isCmdDown){i.selectAll();return}break;case ue:i.isOpen&&(e.preventDefault(),e.stopPropagation(),i.close());return;case fe:if(!e.ctrlKey||e.altKey)break;case de:if(!i.isOpen&&i.hasOptions)i.open();else if(i.$activeOption){i.ignoreHover=!0;var n=i.getAdjacentOption(i.$activeOption,1);n.length&&i.setActiveOption(n,!0,!0)}e.preventDefault();return;case pe:if(!e.ctrlKey||e.altKey)break;case ce:if(i.$activeOption){i.ignoreHover=!0;var r=i.getAdjacentOption(i.$activeOption,-1);r.length&&i.setActiveOption(r,!0,!0)}e.preventDefault();return;case le:i.isOpen&&i.$activeOption&&(i.onOptionSelect({currentTarget:i.$activeOption}),e.preventDefault());return;case B:i.advanceSelection(-1,e);return;case J:i.advanceSelection(1,e);return;case X:i.settings.selectOnTab&&i.isOpen&&i.$activeOption&&(i.onOptionSelect({currentTarget:i.$activeOption}),i.isFull()||e.preventDefault()),i.settings.create&&i.createItem()&&i.settings.showAddOptionOnCreate&&e.preventDefault();return;case z:case q:i.deleteSelection(e);return}if((i.isFull()||i.isInputHidden)&&!(P?e.metaKey:e.ctrlKey)){e.preventDefault();return}},onInput:function(e){var t=this,i=t.$control_input.val()||"";t.lastValue!==i&&(t.lastValue=i,t.onSearchChange(i),t.refreshOptions(),t.trigger("type",i))},onSearchChange:function(e){var t=this,i=t.settings.load;!i||t.loadedSearches.hasOwnProperty(e)||(t.loadedSearches[e]=!0,t.load(function(n){i.apply(t,[e,n])}))},onFocus:function(e){var t=this,i=t.isFocused;if(t.isDisabled)return t.blur(),e&&e.preventDefault(),!1;t.ignoreFocus||(t.isFocused=!0,t.settings.preload==="focus"&&t.onSearchChange(""),i||t.trigger("focus"),t.$activeItems.length||(t.showInput(),t.setActiveItem(null),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())},onBlur:function(e,t){var i=this;if(!!i.isFocused&&(i.isFocused=!1,!i.ignoreFocus)){var n=function(){i.close(),i.setTextboxValue(""),i.setActiveItem(null),i.setActiveOption(null),i.setCaret(i.items.length),i.refreshState(),t&&t.focus&&t.focus(),i.isBlurring=!1,i.ignoreFocus=!1,i.trigger("blur")};i.isBlurring=!0,i.ignoreFocus=!0,i.settings.create&&i.settings.createOnBlur?i.createItem(null,!1,n):n()}},onOptionHover:function(e){this.ignoreHover||this.setActiveOption(e.currentTarget,!1)},onOptionSelect:function(e){var t,i,n,r=this;e.preventDefault&&(e.preventDefault(),e.stopPropagation()),i=d(e.currentTarget),i.hasClass("create")?r.createItem(null,function(){r.settings.closeAfterSelect&&r.close()}):(t=i.attr("data-value"),typeof t!="undefined"&&(r.lastQuery=null,r.setTextboxValue(""),r.addItem(t),r.settings.closeAfterSelect?r.close():!r.settings.hideSelected&&e.type&&/mouse/.test(e.type)&&r.setActiveOption(r.getOption(t))))},onItemSelect:function(e){var t=this;t.isLocked||t.settings.mode==="multi"&&(e.preventDefault(),t.setActiveItem(e.currentTarget,e))},load:function(e){var t=this,i=t.$wrapper.addClass(t.settings.loadingClass);t.loading++,e.apply(t,[function(n){t.loading=Math.max(t.loading-1,0),n&&n.length&&(t.addOption(n),t.refreshOptions(t.isFocused&&!t.isInputHidden)),t.loading||i.removeClass(t.settings.loadingClass),t.trigger("load",n)}])},getTextboxValue:function(){var e=this.$control_input;return e.val()},setTextboxValue:function(e){var t=this.$control_input,i=t.val()!==e;i&&(t.val(e).triggerHandler("update"),this.lastValue=e)},getValue:function(){return this.tagType===K&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(e,t){if((Array.isArray(e)?e:[e]).join("")!==this.items.join("")){var n=t?[]:["change"];te(this,n,function(){this.clear(t),this.addItems(e,t)})}},setMaxItems:function(e){e===0&&(e=null),this.settings.maxItems=e,this.settings.mode=this.settings.mode||(this.settings.maxItems===1?"single":"multi"),this.refreshState()},setActiveItem:function(e,t){var i=this,n,r,s,o,a,l,c,u;if(i.settings.mode!=="single"){if(e=d(e),!e.length){d(i.$activeItems).removeClass("active"),i.$activeItems=[],i.isFocused&&i.showInput();return}if(n=t&&t.type.toLowerCase(),n==="mousedown"&&i.isShiftDown&&i.$activeItems.length){for(u=i.$control.children(".active:last"),o=Array.prototype.indexOf.apply(i.$control[0].childNodes,[u[0]]),a=Array.prototype.indexOf.apply(i.$control[0].childNodes,[e[0]]),o>a&&(c=o,o=a,a=c),r=o;r<=a;r++)l=i.$control[0].childNodes[r],i.$activeItems.indexOf(l)===-1&&(d(l).addClass("active"),i.$activeItems.push(l));t.preventDefault()}else n==="mousedown"&&i.isCtrlDown||n==="keydown"&&this.isShiftDown?e.hasClass("active")?(s=i.$activeItems.indexOf(e[0]),i.$activeItems.splice(s,1),e.removeClass("active")):i.$activeItems.push(e.addClass("active")[0]):(d(i.$activeItems).removeClass("active"),i.$activeItems=[e.addClass("active")[0]]);i.hideInput(),this.isFocused||i.focus()}},setActiveOption:function(e,t,i){var n,r,s,o,a,l=this;l.$activeOption&&(l.$activeOption.removeClass("active"),l.trigger("dropdown_item_deactivate",l.$activeOption.attr("data-value"))),l.$activeOption=null,e=d(e),e.length&&(l.$activeOption=e.addClass("active"),l.isOpen&&l.trigger("dropdown_item_activate",l.$activeOption.attr("data-value")),(t||!ee(t))&&(n=l.$dropdown_content.height(),r=l.$activeOption.outerHeight(!0),t=l.$dropdown_content.scrollTop()||0,s=l.$activeOption.offset().top-l.$dropdown_content.offset().top+t,o=s,a=s-n+r,s+r>n+t?l.$dropdown_content.stop().animate({scrollTop:a},i?l.settings.scrollDuration:0):s<t&&l.$dropdown_content.stop().animate({scrollTop:o},i?l.settings.scrollDuration:0)))},selectAll:function(){var e=this;e.settings.mode!=="single"&&(e.$activeItems=Array.prototype.slice.apply(e.$control.children(":not(input)").addClass("active")),e.$activeItems.length&&(e.hideInput(),e.close()),e.focus())},hideInput:function(){var e=this;e.setTextboxValue(""),e.$control_input.css({opacity:0,position:"absolute",left:e.rtl?1e4:0}),e.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(){var e=this;return e.isDisabled||(e.ignoreFocus=!0,e.$control_input[0].focus(),window.setTimeout(function(){e.ignoreFocus=!1,e.onFocus()},0)),e},blur:function(e){return this.$control_input[0].blur(),this.onBlur(null,e),this},getScoreFunction:function(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())},getSearchOptions:function(){var e=this.settings,t=e.sortField;return typeof t=="string"&&(t=[{field:t}]),{fields:e.searchField,conjunction:e.searchConjunction,sort:t,nesting:e.nesting,filter:e.filter,respect_word_boundaries:e.respect_word_boundaries}},search:function(e){var t,i,n,r,s,o=this,a=o.settings,l=this.getSearchOptions();if(a.score&&(s=o.settings.score.apply(this,[e]),typeof s!="function"))throw new Error('Selectize "score" setting must be a function that returns a function');if(e!==o.lastQuery?(a.normalize&&(e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")),o.lastQuery=e,r=o.sifter.search(e,d.extend(l,{score:s})),o.currentResults=r):r=d.extend(!0,{},o.currentResults),a.hideSelected)for(t=r.items.length-1;t>=0;t--)o.items.indexOf(F(r.items[t].id))!==-1&&r.items.splice(t,1);return r},refreshOptions:function(e){var t,i,n,r,s,o,a,l,c,u,f,h,g,v,y,O;typeof e=="undefined"&&(e=!0);var p=this,x=p.$control_input.val().trim(),_=p.search(x),m=p.$dropdown_content,E=p.$activeOption&&F(p.$activeOption.attr("data-value"));for(r=_.items.length,typeof p.settings.maxOptions=="number"&&(r=Math.min(r,p.settings.maxOptions)),s={},o=[],t=0;t<r;t++)for(a=p.options[_.items[t].id],l=p.render("option",a),c=a[p.settings.optgroupField]||"",u=Array.isArray(c)?c:[c],i=0,n=u&&u.length;i<n;i++){if(c=u[i],!p.optgroups.hasOwnProperty(c)&&typeof p.settings.optionGroupRegister=="function"){var V;(V=p.settings.optionGroupRegister.apply(p,[c]))&&p.registerOptionGroup(V)}p.optgroups.hasOwnProperty(c)||(c=""),s.hasOwnProperty(c)||(s[c]=document.createDocumentFragment(),o.push(c)),s[c].appendChild(l)}for(this.settings.lockOptgroupOrder&&o.sort(function(j,b){var C=p.optgroups[j]&&p.optgroups[j].$order||0,S=p.optgroups[b]&&p.optgroups[b].$order||0;return C-S}),f=document.createDocumentFragment(),t=0,r=o.length;t<r;t++)c=o[t],p.optgroups.hasOwnProperty(c)&&s[c].childNodes.length?(h=document.createDocumentFragment(),h.appendChild(p.render("optgroup_header",p.optgroups[c])),h.appendChild(s[c]),f.appendChild(p.render("optgroup",d.extend({},p.optgroups[c],{html:$e(h),dom:h})))):f.appendChild(s[c]);if(m.html(f),p.settings.highlight&&(m.removeHighlight(),_.query.length&&_.tokens.length))for(t=0,r=_.tokens.length;t<r;t++)k(m,_.tokens[t].regex);if(!p.settings.hideSelected)for(p.$dropdown.find(".selected").removeClass("selected"),t=0,r=p.items.length;t<r;t++)p.getOption(p.items[t]).addClass("selected");p.settings.dropdownSize.sizeType!=="auto"&&p.isOpen&&p.setupDropdownHeight(),p.positionDropdown(),g=p.canCreate(x),g&&p.settings.showAddOptionOnCreate&&(m.prepend(p.render("option_create",{input:x})),O=d(m[0].childNodes[0])),p.hasOptions=_.items.length>0||g&&p.settings.showAddOptionOnCreate||p.settings.setFirstOptionActive,p.hasOptions?(_.items.length>0?(y=E&&p.getOption(E),_.query!==""&&p.settings.setFirstOptionActive?v=m.find("[data-selectable]:first"):_.query!==""&&y&&y.length?v=y:p.settings.mode==="single"&&p.items.length&&(v=p.getOption(p.items[0])),(!v||!v.length)&&(O&&!p.settings.addPrecedence?v=p.getAdjacentOption(O,1):v=m.find("[data-selectable]:first"))):v=O,p.setActiveOption(v),e&&!p.isOpen&&p.open()):(p.setActiveOption(null),e&&p.isOpen&&p.close())},addOption:function(e){var t,i,n,r=this;if(Array.isArray(e)){for(t=0,i=e.length;t<i;t++)r.addOption(e[t]);return}(n=r.registerOption(e))&&(r.userOptions[n]=!0,r.lastQuery=null,r.trigger("option_add",n,e))},registerOption:function(e){var t=F(e[this.settings.valueField]);return typeof t=="undefined"||t===null||this.options.hasOwnProperty(t)?!1:(e.$order=e.$order||++this.order,this.options[t]=e,t)},registerOptionGroup:function(e){var t=F(e[this.settings.optgroupValueField]);return t?(e.$order=e.$order||++this.order,this.optgroups[t]=e,t):!1},addOptionGroup:function(e,t){t[this.settings.optgroupValueField]=e,(e=this.registerOptionGroup(t))&&this.trigger("optgroup_add",e,t)},removeOptionGroup:function(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.renderCache={},this.trigger("optgroup_remove",e))},clearOptionGroups:function(){this.optgroups={},this.renderCache={},this.trigger("optgroup_clear")},updateOption:function(e,t){var i=this,n,r,s,o,a,l,c;if(e=F(e),s=F(t[i.settings.valueField]),e!==null&&!!i.options.hasOwnProperty(e)){if(typeof s!="string")throw new Error("Value must be set in option data");c=i.options[e].$order,s!==e&&(delete i.options[e],o=i.items.indexOf(e),o!==-1&&i.items.splice(o,1,s)),t.$order=t.$order||c,i.options[s]=t,a=i.renderCache.item,l=i.renderCache.option,a&&(delete a[e],delete a[s]),l&&(delete l[e],delete l[s]),i.items.indexOf(s)!==-1&&(n=i.getItem(e),r=d(i.render("item",t)),n.hasClass("active")&&r.addClass("active"),n.replaceWith(r)),i.lastQuery=null,i.isOpen&&i.refreshOptions(!1)}},removeOption:function(e,t){var i=this;e=F(e);var n=i.renderCache.item,r=i.renderCache.option;n&&delete n[e],r&&delete r[e],delete i.userOptions[e],delete i.options[e],i.lastQuery=null,i.trigger("option_remove",e),i.removeItem(e,t)},clearOptions:function(e){var t=this;t.loadedSearches={},t.userOptions={},t.renderCache={};var i=t.options;d.each(t.options,function(n,r){t.items.indexOf(n)==-1&&delete i[n]}),t.options=t.sifter.items=i,t.lastQuery=null,t.trigger("option_clear"),t.clear(e)},getOption:function(e){return this.getElementWithValue(e,this.$dropdown_content.find("[data-selectable]"))},getFirstOption:function(){var e=this.$dropdown.find("[data-selectable]");return e.length>0?e.eq(0):d()},getAdjacentOption:function(e,t){var i=this.$dropdown.find("[data-selectable]"),n=i.index(e)+t;return n>=0&&n<i.length?i.eq(n):d()},getElementWithValue:function(e,t){if(e=F(e),typeof e!="undefined"&&e!==null){for(var i=0,n=t.length;i<n;i++)if(t[i].getAttribute("data-value")===e)return d(t[i])}return d()},getElementWithTextContent:function(e,t,i){if(e=F(e),typeof e!="undefined"&&e!==null)for(var n=0,r=i.length;n<r;n++){var s=i[n].textContent;if(t==!0&&(s=s!==null?s.toLowerCase():null,e=e.toLowerCase()),s===e)return d(i[n])}return d()},getItem:function(e){return this.getElementWithValue(e,this.$control.children())},getFirstItemMatchedByTextContent:function(e,t){return t=t!==null&&t===!0,this.getElementWithTextContent(e,t,this.$dropdown_content.find("[data-selectable]"))},addItems:function(e,t){this.buffer=document.createDocumentFragment();for(var i=this.$control[0].childNodes,n=0;n<i.length;n++)this.buffer.appendChild(i[n]);for(var r=Array.isArray(e)?e:[e],n=0,s=r.length;n<s;n++)this.isPending=n<s-1,this.addItem(r[n],t);var o=this.$control[0];o.insertBefore(this.buffer,o.firstChild),this.buffer=null},addItem:function(e,t){var i=t?[]:["change"];te(this,i,function(){var n,r,s,o=this,a=o.settings.mode,l,c,u,f;if(e=F(e),o.items.indexOf(e)!==-1){a==="single"&&o.close();return}!o.options.hasOwnProperty(e)||(a==="single"&&o.clear(t),!(a==="multi"&&o.isFull())&&(n=d(o.render("item",o.options[e])),f=o.isFull(),o.items.splice(o.caretPos,0,e),o.insertAtCaret(n),(!o.isPending||!f&&o.isFull())&&o.refreshState(),o.isSetup&&(s=o.$dropdown_content.find("[data-selectable]"),o.isPending||(r=o.getOption(e),u=o.getAdjacentOption(r,1).attr("data-value"),o.refreshOptions(o.isFocused&&a!=="single"),u&&o.setActiveOption(o.getOption(u))),!s.length||o.isFull()?o.close():o.isPending||o.positionDropdown(),o.updatePlaceholder(),o.trigger("item_add",e,n),o.isPending||o.updateOriginalInput({silent:t}))))})},removeItem:function(e,t){var i=this,n,r,s;n=e instanceof d?e:i.getItem(e),e=F(n.attr("data-value")),r=i.items.indexOf(e),r!==-1&&(i.trigger("item_before_remove",e,n),n.remove(),n.hasClass("active")&&(n.removeClass("active"),s=i.$activeItems.indexOf(n[0]),i.$activeItems.splice(s,1),n.removeClass("active")),i.items.splice(r,1),i.lastQuery=null,!i.settings.persist&&i.userOptions.hasOwnProperty(e)&&i.removeOption(e,t),r<i.caretPos&&i.setCaret(i.caretPos-1),i.refreshState(),i.updatePlaceholder(),i.updateOriginalInput({silent:t}),i.positionDropdown(),i.trigger("item_remove",e,n))},createItem:function(e,t){var i=this,n=i.caretPos;e=e||(i.$control_input.val()||"").trim();var r=arguments[arguments.length-1];if(typeof r!="function"&&(r=function(){}),typeof t!="boolean"&&(t=!0),!i.canCreate(e))return r(),!1;i.lock();var s=typeof i.settings.create=="function"?this.settings.create:function(l){var c={};c[i.settings.labelField]=l;var u=l;if(i.settings.formatValueToKey&&typeof i.settings.formatValueToKey=="function"&&(u=i.settings.formatValueToKey.apply(this,[u]),u===null||typeof u=="undefined"||typeof u=="object"||typeof u=="function"))throw new Error('Selectize "formatValueToKey" setting must be a function that returns a value other than object or function.');return c[i.settings.valueField]=u,c},o=ye(function(l){if(i.unlock(),!l||typeof l!="object")return r();var c=F(l[i.settings.valueField]);if(typeof c!="string")return r();i.setTextboxValue(""),i.addOption(l),i.setCaret(n),i.addItem(c),i.refreshOptions(t&&i.settings.mode!=="single"),r(l)}),a=s.apply(this,[e,o]);return typeof a!="undefined"&&o(a),!0},refreshItems:function(e){this.lastQuery=null,this.isSetup&&this.addItem(this.items,e),this.refreshState(),this.updateOriginalInput({silent:e})},refreshState:function(){this.refreshValidityState(),this.refreshClasses()},refreshValidityState:function(){if(!this.isRequired)return!1;var e=!this.items.length;this.isInvalid=e,this.$control_input.prop("required",e),this.$input.prop("required",!e)},refreshClasses:function(){var e=this,t=e.isFull(),i=e.isLocked;e.$wrapper.toggleClass("rtl",e.rtl),e.$control.toggleClass("focus",e.isFocused).toggleClass("disabled",e.isDisabled).toggleClass("required",e.isRequired).toggleClass("invalid",e.isInvalid).toggleClass("locked",i).toggleClass("full",t).toggleClass("not-full",!t).toggleClass("input-active",e.isFocused&&!e.isInputHidden).toggleClass("dropdown-active",e.isOpen).toggleClass("has-options",!d.isEmptyObject(e.options)).toggleClass("has-items",e.items.length>0),e.$control_input.data("grow",!t&&!i)},isFull:function(){return this.settings.maxItems!==null&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(e){var t,i,n,r,s,o,a,l,c,u=this;e=e||{},u.tagType===K?(o=u.$input.find("option"),n=[],r=[],s=[],c=[],o.get().forEach(function(f){n.push(f.value)}),u.items.forEach(function(f){a=u.options[f][u.settings.labelField]||"",c.push(f),n.indexOf(f)==-1&&r.push('<option value="'+T(f)+'" selected="selected">'+T(a)+"</option>")}),s=n.filter(function(f){return c.indexOf(f)<0}).map(function(f){return'option[value="'+T(f)+'"]'}),n.length-s.length+r.length===0&&!u.$input.attr("multiple")&&r.push('<option value="" selected="selected"></option>'),u.$input.find(s.join(", ")).remove(),u.$input.append(r.join(""))):(u.$input.val(u.getValue()),u.$input.attr("value",u.$input.val())),u.isSetup&&(e.silent||u.trigger("change",u.$input.val()))},updatePlaceholder:function(){if(!!this.settings.placeholder){var e=this.$control_input;this.items.length?e.removeAttr("placeholder"):e.attr("placeholder",this.settings.placeholder),e.triggerHandler("update",{force:!0})}},open:function(){var e=this;e.isLocked||e.isOpen||e.settings.mode==="multi"&&e.isFull()||(e.focus(),e.isOpen=!0,e.refreshState(),e.$dropdown.css({visibility:"hidden",display:"block"}),e.setupDropdownHeight(),e.positionDropdown(),e.$dropdown.css({visibility:"visible"}),e.trigger("dropdown_open",e.$dropdown))},close:function(){var e=this,t=e.isOpen;e.settings.mode==="single"&&e.items.length&&(e.hideInput(),e.isBlurring&&e.$control_input[0].blur()),e.isOpen=!1,e.$dropdown.hide(),e.setActiveOption(null),e.refreshState(),t&&e.trigger("dropdown_close",e.$dropdown)},positionDropdown:function(){var e=this.$control,t=this.settings.dropdownParent==="body"?e.offset():e.position();t.top+=e.outerHeight(!0);var i=this.$wrapper[0].style.width!=="fit-content"?this.settings.dropdownParent==="body"?"max-content":"100%":"max-content";this.settings.minWidth&&this.settings.minWidth>i&&(i=this.settings.minWidth),this.settings.dropdownParent!=="body"&&i==="max-content"&&e.outerWidth(!0)>=this.$dropdown.outerWidth(!0)&&(i="100%"),this.$dropdown.css({width:i,minWidth:e.outerWidth(!0),top:t.top,left:t.left})},setupDropdownHeight:function(){if(typeof this.settings.dropdownSize=="object"&&this.settings.dropdownSize.sizeType!=="auto"){var e=this.settings.dropdownSize.sizeValue;if(this.settings.dropdownSize.sizeType==="numberItems"){for(var t=this.$dropdown_content.find("*").not(".optgroup, .highlight").not(this.settings.ignoreOnDropwdownHeight),i=0,n=0,r=0,s=0,o=0;o<e;o++){var a=d(t[o]);if(a.length===0)break;if(i+=a.outerHeight(!0),typeof a.data("selectable")=="undefined"){if(a.hasClass("optgroup-header")){var l=window.getComputedStyle(a.parent()[0],":before");l&&(n=l.marginTop?Number(l.marginTop.replace(/\W*(\w)\w*/g,"$1")):0,r=l.marginBottom?Number(l.marginBottom.replace(/\W*(\w)\w*/g,"$1")):0,s=l.borderTopWidth?Number(l.borderTopWidth.replace(/\W*(\w)\w*/g,"$1")):0)}e++}}var c=this.$dropdown_content.css("padding-top")?Number(this.$dropdown_content.css("padding-top").replace(/\W*(\w)\w*/g,"$1")):0,u=this.$dropdown_content.css("padding-bottom")?Number(this.$dropdown_content.css("padding-bottom").replace(/\W*(\w)\w*/g,"$1")):0;e=i+c+u+n+r+s+"px"}else if(this.settings.dropdownSize.sizeType!=="fixedHeight"){console.warn('Selectize.js - Value of "sizeType" must be "fixedHeight" or "numberItems');return}this.$dropdown_content.css({height:e,maxHeight:"none"})}},clear:function(e){var t=this;!t.items.length||(t.$control.children(":not(input)").remove(),t.items=[],t.lastQuery=null,t.setCaret(0),t.setActiveItem(null),t.updatePlaceholder(),t.updateOriginalInput({silent:e}),t.refreshState(),t.showInput(),t.trigger("clear"))},insertAtCaret:function(e){var t=Math.min(this.caretPos,this.items.length),i=e[0],n=this.buffer||this.$control[0];t===0?n.insertBefore(i,n.firstChild):n.insertBefore(i,n.childNodes[t]),this.setCaret(t+1)},deleteSelection:function(e){var t,i,n,r,s,o,a,l,c,u=this;if(n=e&&e.keyCode===z?-1:1,r=R(u.$control_input[0]),u.$activeOption&&!u.settings.hideSelected&&(typeof u.settings.deselectBehavior=="string"&&u.settings.deselectBehavior==="top"?a=u.getFirstOption().attr("data-value"):a=u.getAdjacentOption(u.$activeOption,-1).attr("data-value")),s=[],u.$activeItems.length){for(c=u.$control.children(".active:"+(n>0?"last":"first")),o=u.$control.children(":not(input)").index(c),n>0&&o++,t=0,i=u.$activeItems.length;t<i;t++)s.push(d(u.$activeItems[t]).attr("data-value"));e&&(e.preventDefault(),e.stopPropagation())}else(u.isFocused||u.settings.mode==="single")&&u.items.length&&(n<0&&r.start===0&&r.length===0?s.push(u.items[u.caretPos-1]):n>0&&r.start===u.$control_input.val().length&&s.push(u.items[u.caretPos]));if(!s.length||typeof u.settings.onDelete=="function"&&u.settings.onDelete.apply(u,[s])===!1)return!1;for(typeof o!="undefined"&&u.setCaret(o);s.length;)u.removeItem(s.pop());return u.showInput(),u.positionDropdown(),u.refreshOptions(!0),a&&(l=u.getOption(a),l.length&&u.setActiveOption(l)),!0},advanceSelection:function(e,t){var i,n,r,s,o,a,l=this;e!==0&&(l.rtl&&(e*=-1),i=e>0?"last":"first",n=R(l.$control_input[0]),l.isFocused&&!l.isInputHidden?(s=l.$control_input.val().length,o=e<0?n.start===0&&n.length===0:n.start===s,o&&!s&&l.advanceCaret(e,t)):(a=l.$control.children(".active:"+i),a.length&&(r=l.$control.children(":not(input)").index(a),l.setActiveItem(null),l.setCaret(e>0?r+1:r))))},advanceCaret:function(e,t){var i=this,n,r;e!==0&&(n=e>0?"next":"prev",i.isShiftDown?(r=i.$control_input[n](),r.length&&(i.hideInput(),i.setActiveItem(r),t&&t.preventDefault())):i.setCaret(i.caretPos+e))},setCaret:function(e){var t=this;if(t.settings.mode==="single"?e=t.items.length:e=Math.max(0,Math.min(t.items.length,e)),!t.isPending){var i,n,r,s,o;for(s=t.$control.children(":not(input)"),i=0,n=s.length;i<n;i++)o=d(s[i]).detach(),i<e?t.$control_input.before(o):t.$control.append(o)}t.caretPos=e},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var e=this;e.$input.prop("disabled",!0),e.$control_input.prop("disabled",!0).prop("tabindex",-1),e.isDisabled=!0,e.lock()},enable:function(){var e=this;e.$input.prop("disabled",!1),e.$control_input.prop("disabled",!1).prop("tabindex",e.tabIndex),e.isDisabled=!1,e.unlock()},destroy:function(){var e=this,t=e.eventNS,i=e.revertSettings;e.trigger("destroy"),e.off(),e.$wrapper.remove(),e.$dropdown.remove(),e.$input.html("").append(i.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:i.tabindex}).show(),e.$control_input.removeData("grow"),e.$input.removeData("selectize"),--w.count==0&&w.$testInput&&(w.$testInput.remove(),w.$testInput=void 0),d(window).off(t),d(document).off(t),d(document.body).off(t),delete e.$input[0].selectize},render:function(e,t){var i,n,r,s="",o=!1,a=this,l=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return(e==="option"||e==="item")&&(i=F(t[a.settings.valueField]),o=!!i),o&&(ee(a.renderCache[e])||(a.renderCache[e]={}),a.renderCache[e].hasOwnProperty(i))?a.renderCache[e][i]:(s=d(a.settings.render[e].apply(this,[t,T])),e==="option"||e==="option_create"?t[a.settings.disabledField]||s.attr("data-selectable",""):e==="optgroup"&&(n=t[a.settings.optgroupValueField]||"",s.attr("data-group",n),t[a.settings.disabledField]&&s.attr("data-disabled","")),(e==="option"||e==="item")&&s.attr("data-value",i||""),o&&(a.renderCache[e][i]=s[0]),s[0])},clearCache:function(e){var t=this;typeof e=="undefined"?t.renderCache={}:delete t.renderCache[e]},canCreate:function(e){var t=this;if(!t.settings.create)return!1;var i=t.settings.createFilter;return e.length&&(typeof i!="function"||i.apply(t,[e]))&&(typeof i!="string"||new RegExp(i).test(e))&&(!(i instanceof RegExp)||i.test(e))}}),w.count=0,w.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,showAddOptionOnCreate:!0,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,showEmptyOptionInDropdown:!1,emptyOptionLabel:"--",setFirstOptionActive:!1,closeAfterSelect:!1,closeDropdownThreshold:250,scrollDuration:60,deselectBehavior:"previous",loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",respect_word_boundaries:!1,normalize:!0,mode:null,wrapperClass:"",inputClass:"",dropdownClass:"",dropdownContentClass:"",dropdownParent:null,copyClassesToDropdown:!0,dropdownSize:{sizeType:"auto",sizeValue:"auto"},ignoreOnDropwdownHeight:"img, i",search:!0,showArrow:!0,render:{}},d.fn.selectize=function(e){var t=d.fn.selectize.defaults,i=d.extend({},t,e),n=i.dataAttr,r=i.labelField,s=i.valueField,o=i.disabledField,a=i.optgroupField,l=i.optgroupLabelField,c=i.optgroupValueField,u=function(h,g){var v,y,O,p,x=h.attr(n);if(x)for(g.options=JSON.parse(x),v=0,y=g.options.length;v<y;v++)g.items.push(g.options[v][s]);else{var _=(h.val()||"").trim();if(!i.allowEmptyOption&&!_.length)return;for(O=_.split(i.delimiter),v=0,y=O.length;v<y;v++)p={},p[r]=O[v],p[s]=O[v],g.options.push(p);g.items=O}},f=function(h,g){var v,y,O,p,x=0,_=g.options,m={},E=function(b){var C=n&&b.attr(n),S=b.data(),I={};return typeof C=="string"&&C.length&&(xe(C)?Object.assign(I,JSON.parse(C)):I[C]=C),Object.assign(I,S),I||null},V=function(b,C){b=d(b);var S=F(b.val());if(!(!S&&!i.allowEmptyOption)){if(m.hasOwnProperty(S)){if(C){var I=m[S][a];I?Array.isArray(I)?I.push(C):m[S][a]=[I,C]:m[S][a]=C}return}var $=E(b)||{};$[r]=$[r]||b.text(),$[s]=$[s]||S,$[o]=$[o]||b.prop("disabled"),$[a]=$[a]||C,$.styles=b.attr("style")||"",$.classes=b.attr("class")||"",m[S]=$,_.push($),b.is(":selected")&&g.items.push(S)}},j=function(b){var C,S,I,$,M;for(b=d(b),I=b.attr("label"),I&&($=E(b)||{},$[l]=I,$[c]=I,$[o]=b.prop("disabled"),g.optgroups.push($)),M=d("option",b),C=0,S=M.length;C<S;C++)V(M[C],I)};for(g.maxItems=h.attr("multiple")?null:1,p=h.children(),v=0,y=p.length;v<y;v++)O=p[v].tagName.toLowerCase(),O==="optgroup"?j(p[v]):O==="option"&&V(p[v])};return this.each(function(){if(!this.selectize){var h,g=d(this),v=this.tagName.toLowerCase(),y=g.attr("placeholder")||g.attr("data-placeholder");if(!y&&!i.allowEmptyOption&&(y=g.children('option[value=""]').text()),i.allowEmptyOption&&i.showEmptyOptionInDropdown&&!g.children('option[value=""]').length){var O=g.html(),p=T(i.emptyOptionLabel||"--");g.html('<option value="">'+p+"</option>"+O)}var x={placeholder:y,options:[],optgroups:[],items:[]};v==="select"?f(g,x):u(g,x),h=new w(g,d.extend(!0,{},t,x,e)),h.settings_user=e}})},d.fn.selectize.defaults=w.defaults,d.fn.selectize.support={validity:Z},w.define("auto_position",function(){var e=this;const t={top:"top",bottom:"bottom"};e.positionDropdown=function(){return function(){const i=this.$control,n=this.settings.dropdownParent==="body"?i.offset():i.position();n.top+=i.outerHeight(!0);const r=this.$dropdown.prop("scrollHeight")+5,s=this.$control.get(0).getBoundingClientRect().top,o=this.$wrapper.height(),a=e.$control.get(0).getBoundingClientRect().bottom,l=s+r+o>window.innerHeight&&a-r-o>=0?t.top:t.bottom;let c=this.$wrapper[0].style.width!=="fit-content"?this.settings.dropdownParent==="body"?"max-content":"100%":"max-content";const u={width:c,minWidth:i.outerWidth(!0),left:n.left};if(l===t.top){const f={bottom:n.top,top:"unset"};this.settings.dropdownParent==="body"&&(f.top=n.top-this.$dropdown.outerHeight(!0)-i.outerHeight(!0),f.bottom="unset"),Object.assign(u,f),this.$dropdown.addClass("selectize-position-top"),this.$control.addClass("selectize-position-top")}else Object.assign(u,{top:n.top,bottom:"unset"}),this.$dropdown.removeClass("selectize-position-top"),this.$control.removeClass("selectize-position-top");this.settings.dropdownParent!=="body"&&c==="max-content"&&i.outerWidth(!0)>=this.$dropdown.outerWidth(!0)&&(c="100%"),this.$dropdown.css(u)}}()}),w.define("auto_select_on_type",function(e){var t=this;t.onBlur=function(){var i=t.onBlur;return function(n){var r=t.getFirstItemMatchedByTextContent(t.lastValue,!0);return typeof r.attr("data-value")!="undefined"&&t.getValue()!==r.attr("data-value")&&t.setValue(r.attr("data-value")),i.apply(this,arguments)}}()}),w.define("autofill_disable",function(e){var t=this;t.setup=function(){var i=t.setup;return function(){i.apply(t,arguments),t.$control_input.attr({name:G(21),autocomplete:G(21)})}}()}),w.define("clear_button",function(e){var t=this;e=d.extend({title:"Clear",className:"clear",label:"\xD7",html:function(i){return'<a class="'+i.className+'" title="'+i.title+'"> '+i.label+"</a>"}},e),t.setup=function(){var i=t.setup;return function(){i.apply(t,arguments),t.$button_clear=d(e.html(e)),t.settings.mode==="single"&&t.$wrapper.addClass("single"),t.$wrapper.append(t.$button_clear),(t.getValue()===""||t.getValue().length===0)&&t.$wrapper.find("."+e.className).css("display","none"),t.on("change",function(){t.getValue()===""||t.getValue().length===0?t.$wrapper.find("."+e.className).css("display","none"):t.$wrapper.find("."+e.className).css("display","")}),t.$wrapper.on("click","."+e.className,function(n){n.preventDefault(),n.stopImmediatePropagation(),n.stopPropagation(),!t.isLocked&&(t.clear(),t.$wrapper.find("."+e.className).css("display","none"))})}}()}),w.define("drag_drop",function(e){if(!d.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if(this.settings.mode==="multi"){var t=this;t.lock=function(){var i=t.lock;return function(){var n=t.$control.data("sortable");return n&&n.disable(),i.apply(t,arguments)}}(),t.unlock=function(){var i=t.unlock;return function(){var n=t.$control.data("sortable");return n&&n.enable(),i.apply(t,arguments)}}(),t.setup=function(){var i=t.setup;return function(){i.apply(this,arguments);var n=t.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:t.isLocked,start:function(r,s){s.placeholder.css("width",s.helper.css("width")),n.addClass("dragging")},stop:function(){n.removeClass("dragging");var r=t.$activeItems?t.$activeItems.slice():null,s=[];n.children("[data-value]").each(function(){s.push(d(this).attr("data-value"))}),t.isFocused=!1,t.setValue(s),t.isFocused=!0,t.setActiveItem(r),t.positionDropdown()}})}}()}}),w.define("dropdown_header",function(e){var t=this;e=d.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(i){return'<div class="'+i.headerClass+'"><div class="'+i.titleRowClass+'"><span class="'+i.labelClass+'">'+i.title+'</span><a href="javascript:void(0)" class="'+i.closeClass+'">&#xd7;</a></div></div>'}},e),t.setup=function(){var i=t.setup;return function(){i.apply(t,arguments),t.$dropdown_header=d(e.html(e)),t.$dropdown.prepend(t.$dropdown_header),t.$dropdown_header.find("."+e.closeClass).on("click",function(){t.close()})}}()}),w.define("optgroup_columns",function(e){var t=this;e=d.extend({equalizeWidth:!0,equalizeHeight:!0},e),this.getAdjacentOption=function(r,s){var o=r.closest("[data-group]").find("[data-selectable]"),a=o.index(r)+s;return a>=0&&a<o.length?o.eq(a):d()},this.onKeyDown=function(){var r=t.onKeyDown;return function(s){var o,a,l,c;if(this.isOpen&&(s.keyCode===B||s.keyCode===J)){t.ignoreHover=!0,c=this.$activeOption.closest("[data-group]"),o=c.find("[data-selectable]").index(this.$activeOption),s.keyCode===B?c=c.prev("[data-group]"):c=c.next("[data-group]"),l=c.find("[data-selectable]"),a=l.eq(Math.min(l.length-1,o)),a.length&&this.setActiveOption(a);return}return r.apply(this,arguments)}}();var i=function(){var r,s=i.width,o=document;return typeof s=="undefined"&&(r=o.createElement("div"),r.innerHTML='<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>',r=r.firstChild,o.body.appendChild(r),s=i.width=r.offsetWidth-r.clientWidth,o.body.removeChild(r)),s},n=function(){var r,s,o,a,l,c,u;if(u=d("[data-group]",t.$dropdown_content),s=u.length,!(!s||!t.$dropdown_content.width())){if(e.equalizeHeight){for(o=0,r=0;r<s;r++)o=Math.max(o,u.eq(r).height());u.css({height:o})}e.equalizeWidth&&(c=t.$dropdown_content.innerWidth()-i(),a=Math.round(c/s),u.css({width:a}),s>1&&(l=c-a*(s-1),u.eq(s-1).css({width:l})))}};(e.equalizeHeight||e.equalizeWidth)&&(L.after(this,"positionDropdown",n),L.after(this,"refreshOptions",n))}),w.define("read-only",function(e){var t=this;this.setup=function(){var i=t.setup;return function(){i.apply(this,arguments),this.$dropdown.hasClass("read-only")&&this.$control_input.attr("readonly","readonly")}}(),this.readonly=function(){return function(i){i?(this.$control_input.attr("readonly","readonly"),this.$dropdown.addClass("read-only")):(this.$control_input.removeAttr("readonly"),this.$dropdown.removeClass("read-only"))}}()}),w.define("remove_button",function(e){if(this.settings.mode!=="single"){e=d.extend({label:"&#xd7;",title:"Remove",className:"remove",append:!0},e);var t=function(i,n){var r=i,s='<a href="javascript:void(0)" class="'+n.className+'" tabindex="-1" title="'+T(n.title)+'">'+n.label+"</a>",o=function(a,l){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+l+a.substring(c)};i.setup=function(){var a=r.setup;return function(){if(n.append){var l=r.settings.render.item;r.settings.render.item=function(c){return o(l.apply(i,arguments),s)}}a.apply(i,arguments),i.$control.on("click","."+n.className,function(c){if(c.preventDefault(),!r.isLocked){var u=d(c.currentTarget).parent();return r.setActiveItem(u),r.deleteSelection()&&r.setCaret(r.items.length),!1}})}}()};t(this,e)}}),w.define("restore_on_backspace",function(e){var t=this;e.text=e.text||function(i){return i[this.settings.labelField]},this.onKeyDown=function(){var i=t.onKeyDown;return function(n){var r,s;if(n.keyCode===z&&this.$control_input.val()===""&&!this.$activeItems.length&&(r=this.caretPos-1,r>=0&&r<this.items.length)){s=this.options[this.items[r]],this.deleteSelection(n)&&(this.setTextboxValue(e.text.apply(this,[s])),this.refreshOptions(!0)),n.preventDefault();return}return i.apply(this,arguments)}}()}),w.define("select_on_focus",function(e){var t=this;t.on("focus",function(){var i=t.onFocus;return function(n){var r=t.getItem(t.getValue()).text();return t.clear(),t.setTextboxValue(r),t.$control_input.select(),setTimeout(function(){t.settings.selectOnTab&&t.setActiveOption(t.getFirstItemMatchedByTextContent(r)),t.settings.score=null},0),i.apply(this,arguments)}}()),t.onBlur=function(){var i=t.onBlur;return function(n){return t.getValue()===""&&t.lastValidValue!==t.getValue()&&t.setValue(t.lastValidValue),setTimeout(function(){t.settings.score=function(){return function(){return 1}}},0),i.apply(this,arguments)}}(),t.settings.score=function(){return function(){return 1}}}),w.define("tag_limit",function(e){const t=this;e.tagLimit=e.tagLimit,this.onBlur=function(i){const n=t.onBlur;return function(r){if(n.apply(this,r),!r)return;const s=this.$control,o=s.find(".item"),a=e.tagLimit;a===void 0||o.length<=a||(o.toArray().forEach(function(l,c){c<a||d(l).hide()}),s.append("<span><b>"+(o.length-a)+"</b></span>"))}}(),this.onFocus=function(i){const n=t.onFocus;return function(r){if(n.apply(this,r),!r)return;const s=this.$control;s.find(".item").show(),s.find("span").remove()}}()}),w});