praiadeseselle/wire/modules/Jquery/JqueryUI/selectize/js/standalone/selectize.min.js
2022-03-08 15:55:41 +01:00

1 line
No EOL
47 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function(a,b){if(typeof define==="function"&&define.amd){define("sifter",b)}else{if(typeof exports==="object"){module.exports=b()}else{a.Sifter=b()}}}(this,function(){var h=function(j,k){this.items=j;this.settings=k||{diacritics:true}};h.prototype.tokenize=function(m){m=b(String(m||"").toLowerCase());if(!m||!m.length){return[]}var j,q,l,k;var o=[];var p=m.split(/ +/);for(j=0,q=p.length;j<q;j++){l=e(p[j]);if(this.settings.diacritics){for(k in i){if(i.hasOwnProperty(k)){l=l.replace(new RegExp(k,"g"),i[k])}}}o.push({string:p[j],regex:new RegExp(l,"i")})}return o};h.prototype.iterator=function(j,l){var k;if(c(j)){k=Array.prototype.forEach||function(p){for(var m=0,o=this.length;m<o;m++){p(this[m],m,this)}}}else{k=function(n){for(var m in this){if(this.hasOwnProperty(m)){n(this[m],m,this)}}}}k.apply(j,[l])};h.prototype.getScoreFunction=function(q,r){var p,l,n,o,k;p=this;q=p.prepareSearch(q,r);n=q.tokens;l=q.options.fields;o=n.length;k=q.options.nesting;var m=function(t,s){var u,v;if(!t){return 0}t=String(t||"");v=t.search(s.regex);if(v===-1){return 0}u=s.string.length/t.length;if(v===0){u+=0.5}return u};var j=(function(){var s=l.length;if(!s){return function(){return 0}}if(s===1){return function(t,u){return m(a(u,l[0],k),t)}}return function(u,w){for(var t=0,v=0;t<s;t++){v+=m(a(w,l[t],k),u)}return v/s}})();if(!o){return function(){return 0}}if(o===1){return function(s){return j(n[0],s)}}if(q.options.conjunction==="and"){return function(u){var v;for(var s=0,t=0;s<o;s++){v=j(n[s],u);if(v<=0){return 0}t+=v}return t/o}}else{return function(u){for(var s=0,t=0;s<o;s++){t+=j(n[s],u)}return t/o}}};h.prototype.getSortFunction=function(v,w){var q,j,u,s,r,l,t,o,k,m,p;u=this;v=u.prepareSearch(v,w);p=(!v.query&&w.sort_empty)||w.sort;k=function(x,n){if(x==="$score"){return n.score}return a(u.items[n.id],x,w.nesting)};r=[];if(p){for(q=0,j=p.length;q<j;q++){if(v.query||p[q].field!=="$score"){r.push(p[q])}}}if(v.query){m=true;for(q=0,j=r.length;q<j;q++){if(r[q].field==="$score"){m=false;break}}if(m){r.unshift({field:"$score",direction:"desc"})}}else{for(q=0,j=r.length;q<j;q++){if(r[q].field==="$score"){r.splice(q,1);break}}}o=[];for(q=0,j=r.length;q<j;q++){o.push(r[q].direction==="desc"?-1:1)}l=r.length;if(!l){return null}else{if(l===1){s=r[0].field;t=o[0];return function(x,n){return t*f(k(s,x),k(s,n))}}else{return function(z,x){var B,n,y,A,C;for(B=0;B<l;B++){C=r[B].field;n=o[B]*f(k(C,z),k(C,x));if(n){return n}}return 0}}}};h.prototype.prepareSearch=function(m,j){if(typeof m==="object"){return m}j=d({},j);var l=j.fields;var n=j.sort;var k=j.sort_empty;if(l&&!c(l)){j.fields=[l]}if(n&&!c(n)){j.sort=[n]}if(k&&!c(k)){j.sort_empty=[k]}return{options:j,query:String(m||"").toLowerCase(),tokens:this.tokenize(m),total:0,items:[]}};h.prototype.search=function(m,r){var p=this,o,k,q,l;var j;var n;q=this.prepareSearch(m,r);r=q.options;m=q.query;n=r.score||p.getScoreFunction(q);if(m.length){p.iterator(p.items,function(s,t){k=n(s);if(r.filter===false||k>0){q.items.push({score:k,id:t})}})}else{p.iterator(p.items,function(s,t){q.items.push({score:1,id:t})})}j=p.getSortFunction(q,r);if(j){q.items.sort(j)}q.total=q.items.length;if(typeof r.limit==="number"){q.items=q.items.slice(0,r.limit)}return q};var f=function(k,j){if(typeof k==="number"&&typeof j==="number"){return k>j?1:(k<j?-1:0)}k=g(String(k||""));j=g(String(j||""));if(k>j){return 1}if(j>k){return -1}return 0};var d=function(l,j){var p,q,m,o;for(p=1,q=arguments.length;p<q;p++){o=arguments[p];if(!o){continue}for(m in o){if(o.hasOwnProperty(m)){l[m]=o[m]}}}return l};var a=function(m,j,k){if(!m||!j){return}if(!k){return m[j]}var l=j.split(".");while(l.length&&(m=m[l.shift()])){}return m};var b=function(j){return(j+"").replace(/^\s+|\s+$|/g,"")};var e=function(j){return(j+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")};var c=Array.isArray||(typeof $!=="undefined"&&$.isArray)||function(j){return Object.prototype.toString.call(j)==="[object Array]"};var i={a:"[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]",b:"[b␢βΒB฿𐌁ᛒ]",c:"[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕ]",d:"[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅð]",e:"[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇɘǝƏƐε]",f:"[fƑƒḞḟ]",g:"[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]",h:"[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]",i:"[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪ]",j:"[jȷĴĵɈɉʝɟʲ]",k:"[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]",l:"[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟ]",n:"[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴŊŋ]",o:"[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]",p:"[pṔṕṖṗⱣᵽƤƥᵱ]",q:"[qꝖꝗʠɊɋꝘꝙq̃]",r:"[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]",s:"[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]",t:"[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]",u:"[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ]",v:"[vṼṽṾṿƲʋꝞꝟⱱʋ]",w:"[wẂẃẀẁŴŵẄẅẆẇẈẉ]",x:"[xẌẍẊẋχ]",y:"[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]",z:"[zŹźẐẑŽžŻżẒẓẔẕƵƶ]"};var g=(function(){var o,r,j,m;var l="";var q={};for(j in i){if(i.hasOwnProperty(j)){m=i[j].substring(2,i[j].length-1);l+=m;for(o=0,r=m.length;o<r;o++){q[m.charAt(o)]=j}}}var p=new RegExp("["+l+"]","g");return function(k){return k.replace(p,function(n){return q[n]}).toLowerCase()}})();return h}));(function(a,b){if(typeof define==="function"&&define.amd){define("microplugin",b)}else{if(typeof exports==="object"){module.exports=b()}else{a.MicroPlugin=b()}}}(this,function(){var a={};a.mixin=function(c){c.plugins={};c.prototype.initializePlugins=function(e){var h,j,g;var f=this;var d=[];f.plugins={names:[],settings:{},requested:{},loaded:{}};if(b.isArray(e)){for(h=0,j=e.length;h<j;h++){if(typeof e[h]==="string"){d.push(e[h])}else{f.plugins.settings[e[h].name]=e[h].options;d.push(e[h].name)}}}else{if(e){for(g in e){if(e.hasOwnProperty(g)){f.plugins.settings[g]=e[g];d.push(g)}}}}while(d.length){f.require(d.shift())}};c.prototype.loadPlugin=function(f){var e=this;var d=e.plugins;var g=c.plugins[f];if(!c.plugins.hasOwnProperty(f)){throw new Error('Unable to find "'+f+'" plugin')}d.requested[f]=true;d.loaded[f]=g.fn.apply(e,[e.plugins.settings[f]||{}]);d.names.push(f)};c.prototype.require=function(f){var e=this;var d=e.plugins;if(!e.plugins.loaded.hasOwnProperty(f)){if(d.requested[f]){throw new Error('Plugin has circular dependency ("'+f+'")')}e.loadPlugin(f)}return d.loaded[f]};c.define=function(d,e){c.plugins[d]={name:d,fn:e}}};var b={isArray:Array.isArray||function(c){return Object.prototype.toString.call(c)==="[object Array]"}};return a}));(function(a,b){if(typeof define==="function"&&define.amd){define("selectize",["jquery","sifter","microplugin"],b)}else{if(typeof exports==="object"){module.exports=b(require("jquery"),require("sifter"),require("microplugin"))}else{a.Selectize=b(a.jQuery,a.Sifter,a.MicroPlugin)}}}(this,function(v,m,i){var M=function(Q,T){if(typeof T==="string"&&!T.length){return}var S=(typeof T==="string")?new RegExp(T,"i"):T;var R=function(W){var ac=0;if(W.nodeType===3){var ab=W.data.search(S);if(ab>=0&&W.data.length>0){var aa=W.data.match(S);var Z=document.createElement("span");Z.className="highlight";var X=W.splitText(ab);var U=X.splitText(aa[0].length);var V=X.cloneNode(true);Z.appendChild(V);X.parentNode.replaceChild(Z,X);ac=1}}else{if(W.nodeType===1&&W.childNodes&&!/(script|style)/i.test(W.tagName)){for(var Y=0;Y<W.childNodes.length;++Y){Y+=R(W.childNodes[Y])}}}return ac};return Q.each(function(){R(this)})};v.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;var Q=this.parentNode;Q.replaceChild(this.firstChild,this);Q.normalize()}).end()};var G=function(){};G.prototype={on:function(R,Q){this._events=this._events||{};this._events[R]=this._events[R]||[];this._events[R].push(Q)},off:function(R,Q){var S=arguments.length;if(S===0){return delete this._events}if(S===1){return delete this._events[R]}this._events=this._events||{};if(R in this._events===false){return}this._events[R].splice(this._events[R].indexOf(Q),1)},trigger:function(R){this._events=this._events||{};if(R in this._events===false){return}for(var Q=0;Q<this._events[R].length;Q++){this._events[R][Q].apply(this,Array.prototype.slice.call(arguments,1))}}};G.mixin=function(Q){var S=["on","off","trigger"];for(var R=0;R<S.length;R++){Q.prototype[S[R]]=G.prototype[S[R]]}};var b=/Mac/.test(navigator.userAgent);var I=65;var N=188;var z=13;var w=27;var p=37;var H=38;var x=80;var t=39;var u=40;var B=78;var o=8;var q=46;var j=16;var J=b?91:17;var e=b?18:17;var F=9;var k=1;var h=2;var C=!/android/i.test(window.navigator.userAgent)&&!!document.createElement("input").validity;var P=function(Q){return typeof Q!=="undefined"};var y=function(Q){if(typeof Q==="undefined"||Q===null){return null}if(typeof Q==="boolean"){return Q?"1":"0"}return Q+""};var D=function(Q){return(Q+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};var f=function(Q){return(Q+"").replace(/\$/g,"$$$$")};var s={};s.before=function(Q,T,S){var R=Q[T];Q[T]=function(){S.apply(Q,arguments);return R.apply(Q,arguments)}};s.after=function(Q,T,S){var R=Q[T];Q[T]=function(){var U=R.apply(Q,arguments);S.apply(Q,arguments);return U}};var r=function(Q){var R=false;return function(){if(R){return}R=true;Q.apply(this,arguments)}};var g=function(R,Q){var S;return function(){var T=this;var U=arguments;window.clearTimeout(S);S=window.setTimeout(function(){R.apply(T,U)},Q)}};var a=function(Q,S,U){var T;var R=Q.trigger;var V={};Q.trigger=function(){var W=arguments[0];if(S.indexOf(W)!==-1){V[W]=arguments}else{return R.apply(Q,arguments)}};U.apply(Q,[]);Q.trigger=R;for(T in V){if(V.hasOwnProperty(T)){R.apply(Q,V[T])}}};var A=function(T,S,Q,R){T.on(S,Q,function(U){var V=U.target;while(V&&V.parentNode!==T[0]){V=V.parentNode}U.currentTarget=V;return R.apply(this,[U])})};var l=function(S){var R={};if("selectionStart" in S){R.start=S.selectionStart;R.length=S.selectionEnd-R.start}else{if(document.selection){S.focus();var T=document.selection.createRange();var Q=document.selection.createRange().text.length;T.moveStart("character",-S.value.length);R.start=T.text.length-Q;R.length=Q}}return R};var n=function(T,U,R){var Q,V,S={};if(R){for(Q=0,V=R.length;Q<V;Q++){S[R[Q]]=T.css(R[Q])}}else{S=T.css()}U.css(S)};var O={str:"",width:0};var K=function(T,S){if(!T){return 0}var R=v("#selectize-measureString");if(!R.length){R=v("<test>").attr("id","selectize-measureString").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).appendTo("body");n(S,R,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"])}if(T===O.str){var Q=O.width}else{R.text(T);var Q=R.width()}return Q};var L=function(S){var Q=null;var R=function(W,ac){var aa,ab,X,Z,T;var U,V,Y;W=W||window.event||{};ac=ac||{};if(W.metaKey||W.altKey){return}if(!ac.force&&S.data("grow")===false){return}aa=S.val();if(W.type&&W.type.toLowerCase()==="keydown"){ab=W.keyCode;X=((ab>=97&&ab<=122)||(ab>=65&&ab<=90)||(ab>=48&&ab<=57)||ab===32);if(ab===q||ab===o){Y=l(S[0]);if(Y.length){aa=aa.substring(0,Y.start)+aa.substring(Y.start+Y.length)}else{if(ab===o&&Y.start){aa=aa.substring(0,Y.start-1)+aa.substring(Y.start+1)}else{if(ab===q&&typeof Y.start!=="undefined"){aa=aa.substring(0,Y.start)+aa.substring(Y.start+1)}}}}else{if(X){U=W.shiftKey;V=String.fromCharCode(W.keyCode);if(U){V=V.toUpperCase()}else{V=V.toLowerCase()}aa+=V}}}Z=S.attr("placeholder");if(!aa&&Z){aa=Z}T=K(aa,S)+4;if(T!==Q){Q=T;S.width(T);S.triggerHandler("resize")}};S.on("keydown keyup update blur",R);R()};var E=function(R){var Q=document.createElement("div");Q.appendChild(R.cloneNode(true));return Q.innerHTML};var d=function(S,R){if(!R){R={}}var Q="Selectize";console.error(Q+": "+S);if(R.explanation){if(console.group){console.group()}console.error(R.explanation);if(console.group){console.groupEnd()}}};var c=function(V,S){var X,T,Q,R,W,Y=this;W=V[0];W.selectize=Y;var U=window.getComputedStyle&&window.getComputedStyle(W,null);R=U?U.getPropertyValue("direction"):W.currentStyle&&W.currentStyle.direction;R=R||V.parents("[dir]:first").attr("dir")||"";v.extend(Y,{order:0,settings:S,$input:V,tabIndex:V.attr("tabindex")||"",tagType:W.tagName.toLowerCase()==="select"?k:h,rtl:/rtl/i.test(R),eventNS:".selectize"+(++c.count),highlightedValue:null,isOpen:false,isDisabled:false,isRequired:V.is("[required]"),isInvalid:false,isLocked:false,isFocused:false,isInputHidden:false,isSetup:false,isShiftDown:false,isCmdDown:false,isCtrlDown:false,ignoreFocus:false,ignoreBlur:false,ignoreHover:false,hasOptions:false,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:S.loadThrottle===null?Y.onSearchChange:g(Y.onSearchChange,S.loadThrottle)});Y.sifter=new m(this.options,{diacritics:S.diacritics});if(Y.settings.options){for(T=0,Q=Y.settings.options.length;T<Q;T++){Y.registerOption(Y.settings.options[T])}delete Y.settings.options}if(Y.settings.optgroups){for(T=0,Q=Y.settings.optgroups.length;T<Q;T++){Y.registerOptionGroup(Y.settings.optgroups[T])}delete Y.settings.optgroups}Y.settings.mode=Y.settings.mode||(Y.settings.maxItems===1?"single":"multi");if(typeof Y.settings.hideSelected!=="boolean"){Y.settings.hideSelected=Y.settings.mode==="multi"}Y.initializePlugins(Y.settings.plugins);Y.setupCallbacks();Y.setupTemplates();Y.setup()};G.mixin(c);if(typeof i!=="undefined"){i.mixin(c)}else{d("Dependency MicroPlugin is missing",{explanation:'Make sure you either: (1) are using the "standalone" version of Selectize, or (2) require MicroPlugin before you load Selectize.'})}v.extend(c.prototype,{setup:function(){var W=this;var ad=W.settings;var Z=W.eventNS;var V=v(window);var ah=v(document);var S=W.$input;var ab;var af;var R;var T;var X;var ac;var ai;var U;var ag;var ae;var Y;var aa;ai=W.settings.mode;ae=S.attr("class")||"";ab=v("<div>").addClass(ad.wrapperClass).addClass(ae).addClass(ai);af=v("<div>").addClass(ad.inputClass).addClass("items").appendTo(ab);R=v('<input type="text" autocomplete="off" />').appendTo(af).attr("tabindex",S.is(":disabled")?"-1":W.tabIndex);ac=v(ad.dropdownParent||ab);T=v("<div>").addClass(ad.dropdownClass).addClass(ai).hide().appendTo(ac);X=v("<div>").addClass(ad.dropdownContentClass).appendTo(T);if(aa=S.attr("id")){R.attr("id",aa+"-selectized");v("label[for='"+aa+"']").attr("for",aa+"-selectized")}if(W.settings.copyClassesToDropdown){T.addClass(ae)}ab.css({width:S[0].style.width});if(W.plugins.names.length){Y="plugin-"+W.plugins.names.join(" plugin-");ab.addClass(Y);T.addClass(Y)}if((ad.maxItems===null||ad.maxItems>1)&&W.tagType===k){S.attr("multiple","multiple")}if(W.settings.placeholder){R.attr("placeholder",ad.placeholder)}if(!W.settings.splitOn&&W.settings.delimiter){var Q=W.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");W.settings.splitOn=new RegExp("\\s*"+Q+"+\\s*")}if(S.attr("autocorrect")){R.attr("autocorrect",S.attr("autocorrect"))}if(S.attr("autocapitalize")){R.attr("autocapitalize",S.attr("autocapitalize"))}W.$wrapper=ab;W.$control=af;W.$control_input=R;W.$dropdown=T;W.$dropdown_content=X;T.on("mouseenter","[data-selectable]",function(){return W.onOptionHover.apply(W,arguments)});T.on("mousedown click","[data-selectable]",function(){return W.onOptionSelect.apply(W,arguments)});A(af,"mousedown","*:not(input)",function(){return W.onItemSelect.apply(W,arguments)});L(R);af.on({mousedown:function(){return W.onMouseDown.apply(W,arguments)},click:function(){return W.onClick.apply(W,arguments)}});R.on({mousedown:function(aj){aj.stopPropagation()},keydown:function(){return W.onKeyDown.apply(W,arguments)},keyup:function(){return W.onKeyUp.apply(W,arguments)},keypress:function(){return W.onKeyPress.apply(W,arguments)},resize:function(){W.positionDropdown.apply(W,[])},blur:function(){return W.onBlur.apply(W,arguments)},focus:function(){W.ignoreBlur=false;return W.onFocus.apply(W,arguments)},paste:function(){return W.onPaste.apply(W,arguments)}});ah.on("keydown"+Z,function(aj){W.isCmdDown=aj[b?"metaKey":"ctrlKey"];W.isCtrlDown=aj[b?"altKey":"ctrlKey"];W.isShiftDown=aj.shiftKey});ah.on("keyup"+Z,function(aj){if(aj.keyCode===e){W.isCtrlDown=false}if(aj.keyCode===j){W.isShiftDown=false}if(aj.keyCode===J){W.isCmdDown=false}});ah.on("mousedown"+Z,function(aj){if(W.isFocused){if(aj.target===W.$dropdown[0]||aj.target.parentNode===W.$dropdown[0]){return false}if(!W.$control.has(aj.target).length&&aj.target!==W.$control[0]){W.blur(aj.target)}}});V.on(["scroll"+Z,"resize"+Z].join(" "),function(){if(W.isOpen){W.positionDropdown.apply(W,arguments)}});V.on("mousemove"+Z,function(){W.ignoreHover=false});this.revertSettings={$children:S.children().detach(),tabindex:S.attr("tabindex")};S.attr("tabindex",-1).hide().after(W.$wrapper);if(v.isArray(ad.items)){W.setValue(ad.items);delete ad.items}if(C){S.on("invalid"+Z,function(aj){aj.preventDefault();W.isInvalid=true;W.refreshState()})}W.updateOriginalInput();W.refreshItems();W.refreshState();W.updatePlaceholder();W.isSetup=true;if(S.is(":disabled")){W.disable()}W.on("change",this.onChange);S.data("selectize",W);S.addClass("selectized");W.trigger("initialize");if(ad.preload===true){W.onSearchChange("")}},setupTemplates:function(){var R=this;var Q=R.settings.labelField;var S=R.settings.optgroupLabelField;var T={optgroup:function(U){return'<div class="optgroup">'+U.html+"</div>"},optgroup_header:function(V,U){return'<div class="optgroup-header">'+U(V[S])+"</div>"},option:function(V,U){return'<div class="option">'+U(V[Q])+"</div>"},item:function(V,U){return'<div class="item">'+U(V[Q])+"</div>"},option_create:function(V,U){return'<div class="create">Add <strong>'+U(V.input)+"</strong>&hellip;</div>"}};R.settings.render=v.extend({},T,R.settings.render)},setupCallbacks:function(){var Q,R,S={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"};for(Q in S){if(S.hasOwnProperty(Q)){R=this.settings[S[Q]];if(R){this.on(Q,R)}}}},onClick:function(R){var Q=this;if(!Q.isFocused){Q.focus();R.preventDefault()}},onMouseDown:function(T){var R=this;var S=T.isDefaultPrevented();var Q=v(T.target);if(R.isFocused){if(T.target!==R.$control_input[0]){if(R.settings.mode==="single"){R.isOpen?R.close():R.open()}else{if(!S){R.setActiveItem(null)}}return false}}else{if(!S){window.setTimeout(function(){R.focus()},0)}}},onChange:function(){this.$input.trigger("change")},onPaste:function(R){var Q=this;if(Q.isFull()||Q.isInputHidden||Q.isLocked){R.preventDefault();return}if(Q.settings.splitOn){setTimeout(function(){var T=Q.$control_input.val();if(!T.match(Q.settings.splitOn)){return}var S=v.trim(T).split(Q.settings.splitOn);for(var U=0,V=S.length;U<V;U++){Q.createItem(S[U])}},0)}},onKeyPress:function(R){if(this.isLocked){return R&&R.preventDefault()}var Q=String.fromCharCode(R.keyCode||R.which);if(this.settings.create&&this.settings.mode==="multi"&&Q===this.settings.delimiter){this.createItem();R.preventDefault();return false}},lastKeyDown:null,onKeyDown:function(U){var T=U.target===this.$control_input[0];var S=this;if(S.isLocked){if(U.keyCode!==F){U.preventDefault()}return}switch(U.keyCode){case I:if(S.isCmdDown){S.selectAll();return}break;case w:if(S.isOpen){U.preventDefault();U.stopPropagation();S.close()}return;case B:if(!U.ctrlKey||U.altKey){break}case u:if(!S.isOpen&&S.hasOptions){S.open()}else{if(S.$activeOption){S.ignoreHover=true;var Q=S.getAdjacentOption(S.$activeOption,1);if(Q.length){S.setActiveOption(Q,true,true)}}}U.preventDefault();return;case x:if(!U.ctrlKey||U.altKey){break}case H:if(S.$activeOption){S.ignoreHover=true;var R=S.getAdjacentOption(S.$activeOption,-1);if(R.length){S.setActiveOption(R,true,true)}}U.preventDefault();return;case z:if(S.isOpen&&S.$activeOption){S.onOptionSelect({currentTarget:S.$activeOption});U.preventDefault()}if(!S.settings.submitOnReturn){return false}return;case p:S.advanceSelection(-1,U);return;case t:S.advanceSelection(1,U);return;case F:if(S.settings.selectOnTab&&S.isOpen&&S.$activeOption){S.onOptionSelect({currentTarget:S.$activeOption});if(!S.isFull()){U.preventDefault()}}if(S.settings.create&&S.createItem()){U.preventDefault()}return;case o:case q:S.deleteSelection(U);return}if((S.isFull()||S.isInputHidden)&&!(b?U.metaKey:U.ctrlKey)){U.preventDefault();return}},onKeyUp:function(S){var Q=this;if(Q.isLocked){return S&&S.preventDefault()}var R=Q.$control_input.val()||"";if(Q.lastValue!==R){Q.lastValue=R;Q.onSearchChange(R);Q.refreshOptions();Q.trigger("type",R)}},onSearchChange:function(S){var Q=this;var R=Q.settings.load;if(!R){return}if(Q.loadedSearches.hasOwnProperty(S)){return}Q.loadedSearches[S]=true;Q.load(function(T){R.apply(Q,[S,T])})},onFocus:function(S){var Q=this;var R=Q.isFocused;if(Q.isDisabled){Q.blur();S&&S.preventDefault();return false}if(Q.ignoreFocus){return}Q.isFocused=true;if(Q.settings.preload==="focus"){Q.onSearchChange("")}if(!R){Q.trigger("focus")}if(!Q.$activeItems.length){Q.showInput();Q.setActiveItem(null);Q.refreshOptions(!!Q.settings.openOnFocus)}Q.refreshState()},onBlur:function(T,R){var Q=this;if(!Q.isFocused){return}Q.isFocused=false;if(Q.ignoreFocus){return}else{if(!Q.ignoreBlur&&document.activeElement===Q.$dropdown_content[0]){Q.ignoreBlur=true;Q.onFocus(T);return}}var S=function(){Q.close();Q.setTextboxValue("");Q.setActiveItem(null);Q.setActiveOption(null);Q.setCaret(Q.items.length);Q.refreshState();R&&R.focus&&R.focus();Q.ignoreFocus=false;Q.trigger("blur")};Q.ignoreFocus=true;if(Q.settings.create&&Q.settings.createOnBlur){Q.createItem(null,false,S)}else{S()}},onOptionHover:function(Q){if(this.ignoreHover){return}this.setActiveOption(Q.currentTarget,false)},onOptionSelect:function(U){var S,Q,T,R=this;if(U.preventDefault){U.preventDefault();U.stopPropagation()}Q=v(U.currentTarget);if(Q.hasClass("create")){R.createItem(null,function(){if(R.settings.closeAfterSelect){R.close();console.log("1")}})}else{S=Q.attr("data-value");if(typeof S!=="undefined"){R.lastQuery=null;R.setTextboxValue("");R.addItem(S);if(R.settings.closeAfterSelect){R.close();R.blur()}else{if(!R.settings.hideSelected&&U.type&&/mouse/.test(U.type)){R.setActiveOption(R.getOption(S))}}}}},onItemSelect:function(R){var Q=this;if(Q.isLocked){return}if(Q.settings.mode==="multi"){R.preventDefault();Q.setActiveItem(R.currentTarget,R)}},load:function(R){var Q=this;var S=Q.$wrapper.addClass(Q.settings.loadingClass);Q.loading++;R.apply(Q,[function(T){Q.loading=Math.max(Q.loading-1,0);if(T&&T.length){Q.addOption(T);Q.refreshOptions(Q.isFocused&&!Q.isInputHidden)}if(!Q.loading){S.removeClass(Q.settings.loadingClass)}Q.trigger("load",T)}])},setTextboxValue:function(Q){var S=this.$control_input;var R=S.val()!==Q;if(R){S.val(Q).triggerHandler("update");this.lastValue=Q}},getValue:function(){if(this.tagType===k&&this.$input.attr("multiple")){return this.items}else{return this.items.join(this.settings.delimiter)}},setValue:function(S,Q){var R=Q?[]:["change"];a(this,R,function(){this.clear(Q);this.addItems(S,Q)})},setActiveItem:function(X,V){var aa=this;var U;var T,Y,Q,S,Z,R;var W;if(aa.settings.mode==="single"){return}X=v(X);if(!X.length){v(aa.$activeItems).removeClass("active");aa.$activeItems=[];if(aa.isFocused){aa.showInput()}return}U=V&&V.type.toLowerCase();if(U==="mousedown"&&aa.isShiftDown&&aa.$activeItems.length){W=aa.$control.children(".active:last");Q=Array.prototype.indexOf.apply(aa.$control[0].childNodes,[W[0]]);S=Array.prototype.indexOf.apply(aa.$control[0].childNodes,[X[0]]);if(Q>S){R=Q;Q=S;S=R}for(T=Q;T<=S;T++){Z=aa.$control[0].childNodes[T];if(aa.$activeItems.indexOf(Z)===-1){v(Z).addClass("active");aa.$activeItems.push(Z)}}V.preventDefault()}else{if((U==="mousedown"&&aa.isCtrlDown)||(U==="keydown"&&this.isShiftDown)){if(X.hasClass("active")){Y=aa.$activeItems.indexOf(X[0]);aa.$activeItems.splice(Y,1);X.removeClass("active")}else{aa.$activeItems.push(X.addClass("active")[0])}}else{v(aa.$activeItems).removeClass("active");aa.$activeItems=[X.addClass("active")[0]]}}aa.hideInput();if(!this.isFocused){aa.focus()}},setActiveOption:function(Q,W,S){var R,X,V;var U,T;var Y=this;if(Y.$activeOption){Y.$activeOption.removeClass("active")}Y.$activeOption=null;Q=v(Q);if(!Q.length){return}Y.$activeOption=Q.addClass("active");if(W||!P(W)){R=Y.$dropdown_content.height();X=Y.$activeOption.outerHeight(true);W=Y.$dropdown_content.scrollTop()||0;V=Y.$activeOption.offset().top-Y.$dropdown_content.offset().top+W;U=V;T=V-R+X;if(V+X>R+W){Y.$dropdown_content.stop().animate({scrollTop:T},S?Y.settings.scrollDuration:0)}else{if(V<W){Y.$dropdown_content.stop().animate({scrollTop:U},S?Y.settings.scrollDuration:0)}}}},selectAll:function(){var Q=this;if(Q.settings.mode==="single"){return}Q.$activeItems=Array.prototype.slice.apply(Q.$control.children(":not(input)").addClass("active"));if(Q.$activeItems.length){Q.hideInput();Q.close()}Q.focus()},hideInput:function(){var Q=this;Q.setTextboxValue("");Q.$control_input.css({opacity:0,position:"absolute",left:Q.rtl?10000:-10000});Q.isInputHidden=true},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0});this.isInputHidden=false},focus:function(){var Q=this;if(Q.isDisabled){return}Q.ignoreFocus=true;Q.$control_input[0].focus();window.setTimeout(function(){Q.ignoreFocus=false;Q.onFocus()},0)},blur:function(Q){this.$control_input[0].blur();this.onBlur(null,Q)},getScoreFunction:function(Q){return this.sifter.getScoreFunction(Q,this.getSearchOptions())},getSearchOptions:function(){var R=this.settings;var Q=R.sortField;if(typeof Q==="string"){Q=[{field:Q}]}return{fields:R.searchField,conjunction:R.searchConjunction,sort:Q}},search:function(U){var T,V,Q,Y,S;var W=this;var R=W.settings;var X=this.getSearchOptions();if(R.score){S=W.settings.score.apply(this,[U]);if(typeof S!=="function"){throw new Error('Selectize "score" setting must be a function that returns a function')}}if(U!==W.lastQuery){W.lastQuery=U;Y=W.sifter.search(U,v.extend(X,{score:S}));W.currentResults=Y}else{Y=v.extend(true,{},W.currentResults)}if(R.hideSelected){for(T=Y.items.length-1;T>=0;T--){if(W.items.indexOf(y(Y.items[T].id))!==-1){Y.items.splice(T,1)}}}return Y},refreshOptions:function(aa){var ah,ag,af,ad,ak,Q,W,ai,S,ae,U,aj,V;var T,Z,ab;if(typeof aa==="undefined"){aa=true}var Y=this;var R=v.trim(Y.$control_input.val());var ac=Y.search(R);var X=Y.$dropdown_content;var al=Y.$activeOption&&y(Y.$activeOption.attr("data-value"));ad=ac.items.length;if(typeof Y.settings.maxOptions==="number"){ad=Math.min(ad,Y.settings.maxOptions)}ak={};Q=[];for(ah=0;ah<ad;ah++){W=Y.options[ac.items[ah].id];ai=Y.render("option",W);S=W[Y.settings.optgroupField]||"";ae=v.isArray(S)?S:[S];for(ag=0,af=ae&&ae.length;ag<af;ag++){S=ae[ag];if(!Y.optgroups.hasOwnProperty(S)){S=""}if(!ak.hasOwnProperty(S)){ak[S]=document.createDocumentFragment();Q.push(S)}ak[S].appendChild(ai)}}if(this.settings.lockOptgroupOrder){Q.sort(function(an,am){var ao=Y.optgroups[an].$order||0;var ap=Y.optgroups[am].$order||0;return ao-ap})}U=document.createDocumentFragment();for(ah=0,ad=Q.length;ah<ad;ah++){S=Q[ah];if(Y.optgroups.hasOwnProperty(S)&&ak[S].childNodes.length){aj=document.createDocumentFragment();aj.appendChild(Y.render("optgroup_header",Y.optgroups[S]));aj.appendChild(ak[S]);U.appendChild(Y.render("optgroup",v.extend({},Y.optgroups[S],{html:E(aj),dom:aj})))}else{U.appendChild(ak[S])}}X.html(U);if(Y.settings.highlight&&ac.query.length&&ac.tokens.length){X.removeHighlight();for(ah=0,ad=ac.tokens.length;ah<ad;ah++){M(X,ac.tokens[ah].regex)}}if(!Y.settings.hideSelected){for(ah=0,ad=Y.items.length;ah<ad;ah++){Y.getOption(Y.items[ah]).addClass("selected")}}V=Y.canCreate(R);if(V){X.prepend(Y.render("option_create",{input:R}));ab=v(X[0].childNodes[0])}Y.hasOptions=ac.items.length>0||V;if(Y.hasOptions){if(ac.items.length>0){Z=al&&Y.getOption(al);if(Z&&Z.length){T=Z}else{if(Y.settings.mode==="single"&&Y.items.length){T=Y.getOption(Y.items[0])}}if(!T||!T.length){if(ab&&!Y.settings.addPrecedence){T=Y.getAdjacentOption(ab,1)}else{T=X.find("[data-selectable]:first")}}}else{T=ab}Y.setActiveOption(T);if(aa&&!Y.isOpen){Y.open()}}else{Y.setActiveOption(null);if(aa&&Y.isOpen){Y.close()}}},addOption:function(T){var R,U,S,Q=this;if(v.isArray(T)){for(R=0,U=T.length;R<U;R++){Q.addOption(T[R])}return}if(S=Q.registerOption(T)){Q.userOptions[S]=true;Q.lastQuery=null;Q.trigger("option_add",S,T)}},registerOption:function(R){var Q=y(R[this.settings.valueField]);if(typeof Q==="undefined"||Q===null||this.options.hasOwnProperty(Q)){return false}R.$order=R.$order||++this.order;this.options[Q]=R;return Q},registerOptionGroup:function(R){var Q=y(R[this.settings.optgroupValueField]);if(!Q){return false}R.$order=R.$order||++this.order;this.optgroups[Q]=R;return Q},addOptionGroup:function(R,Q){Q[this.settings.optgroupValueField]=R;if(R=this.registerOptionGroup(Q)){this.trigger("optgroup_add",R,Q)}},removeOptionGroup:function(Q){if(this.optgroups.hasOwnProperty(Q)){delete this.optgroups[Q];this.renderCache={};this.trigger("optgroup_remove",Q)}},clearOptionGroups:function(){this.optgroups={};this.renderCache={};this.trigger("optgroup_clear")},updateOption:function(X,V){var Z=this;var Y,Q;var S,T,W,R,U;X=y(X);S=y(V[Z.settings.valueField]);if(X===null){return}if(!Z.options.hasOwnProperty(X)){return}if(typeof S!=="string"){throw new Error("Value must be set in option data")}U=Z.options[X].$order;if(S!==X){delete Z.options[X];T=Z.items.indexOf(X);if(T!==-1){Z.items.splice(T,1,S)}}V.$order=V.$order||U;Z.options[S]=V;W=Z.renderCache.item;R=Z.renderCache.option;if(W){delete W[X];delete W[S]}if(R){delete R[X];delete R[S]}if(Z.items.indexOf(S)!==-1){Y=Z.getItem(X);Q=v(Z.render("item",V));if(Y.hasClass("active")){Q.addClass("active")}Y.replaceWith(Q)}Z.lastQuery=null;if(Z.isOpen){Z.refreshOptions(false)}},removeOption:function(U,S){var R=this;U=y(U);var Q=R.renderCache.item;var T=R.renderCache.option;if(Q){delete Q[U]}if(T){delete T[U]}delete R.userOptions[U];delete R.options[U];R.lastQuery=null;R.trigger("option_remove",U);R.removeItem(U,S)},clearOptions:function(){var Q=this;Q.loadedSearches={};Q.userOptions={};Q.renderCache={};Q.options=Q.sifter.items={};Q.lastQuery=null;Q.trigger("option_clear");Q.clear()},getOption:function(Q){return this.getElementWithValue(Q,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(T,S){var Q=this.$dropdown.find("[data-selectable]");var R=Q.index(T)+S;return R>=0&&R<Q.length?Q.eq(R):v()},getElementWithValue:function(S,R){S=y(S);if(typeof S!=="undefined"&&S!==null){for(var Q=0,T=R.length;Q<T;Q++){if(R[Q].getAttribute("data-value")===S){return v(R[Q])}}}return v()},getItem:function(Q){return this.getElementWithValue(Q,this.$control.children())},addItems:function(S,R){var Q=v.isArray(S)?S:[S];for(var T=0,U=Q.length;T<U;T++){this.isPending=(T<U-1);this.addItem(Q[T],R)}},addItem:function(S,Q){var R=Q?[]:["change"];a(this,R,function(){var aa,U,Y;var ab=this;var T=ab.settings.mode;var X,W,Z,V;S=y(S);if(ab.items.indexOf(S)!==-1){if(T==="single"){ab.close()}return}if(!ab.options.hasOwnProperty(S)){return}if(T==="single"){ab.clear(Q)}if(T==="multi"&&ab.isFull()){return}aa=v(ab.render("item",ab.options[S]));V=ab.isFull();ab.items.splice(ab.caretPos,0,S);ab.insertAtCaret(aa);if(!ab.isPending||(!V&&ab.isFull())){ab.refreshState()}if(ab.isSetup){Y=ab.$dropdown_content.find("[data-selectable]");if(!ab.isPending){U=ab.getOption(S);Z=ab.getAdjacentOption(U,1).attr("data-value");ab.refreshOptions(ab.isFocused&&T!=="single");if(Z){ab.setActiveOption(ab.getOption(Z))}}if(!Y.length||ab.isFull()){ab.close()}else{ab.positionDropdown()}ab.updatePlaceholder();ab.trigger("item_add",S,aa);ab.updateOriginalInput({silent:Q})}})},removeItem:function(V,T){var S=this;var R,U,Q;R=(V instanceof v)?V:S.getItem(V);V=y(R.attr("data-value"));U=S.items.indexOf(V);if(U!==-1){R.remove();if(R.hasClass("active")){Q=S.$activeItems.indexOf(R[0]);S.$activeItems.splice(Q,1)}S.items.splice(U,1);S.lastQuery=null;if(!S.settings.persist&&S.userOptions.hasOwnProperty(V)){S.removeOption(V,T)}if(U<S.caretPos){S.setCaret(S.caretPos-1)}S.refreshState();S.updatePlaceholder();S.updateOriginalInput({silent:T});S.positionDropdown();S.trigger("item_remove",V,R)}},createItem:function(T,V){var S=this;var W=S.caretPos;T=T||v.trim(S.$control_input.val()||"");var X=arguments[arguments.length-1];if(typeof X!=="function"){X=function(){}}if(typeof V!=="boolean"){V=true}if(!S.canCreate(T)){X();return false}S.lock();var Q=(typeof S.settings.create==="function")?this.settings.create:function(Y){var Z={};Z[S.settings.labelField]=Y;Z[S.settings.valueField]=Y;return Z};var U=r(function(Z){S.unlock();if(!Z||typeof Z!=="object"){return X()}var Y=y(Z[S.settings.valueField]);if(typeof Y!=="string"){return X()}S.setTextboxValue("");S.addOption(Z);S.setCaret(W);S.addItem(Y);S.refreshOptions(V&&S.settings.mode!=="single");X(Z)});var R=Q.apply(this,[T,U]);if(typeof R!=="undefined"){U(R)}return true},refreshItems:function(){this.lastQuery=null;if(this.isSetup){this.addItem(this.items)}this.refreshState();this.updateOriginalInput()},refreshState:function(){this.refreshValidityState();this.refreshClasses()},refreshValidityState:function(){if(!this.isRequired){return false}var Q=!this.items.length;this.isInvalid=Q;this.$control_input.prop("required",Q);this.$input.prop("required",!Q)},refreshClasses:function(){var Q=this;var R=Q.isFull();var S=Q.isLocked;Q.$wrapper.toggleClass("rtl",Q.rtl);Q.$control.toggleClass("focus",Q.isFocused).toggleClass("disabled",Q.isDisabled).toggleClass("required",Q.isRequired).toggleClass("invalid",Q.isInvalid).toggleClass("locked",S).toggleClass("full",R).toggleClass("not-full",!R).toggleClass("input-active",Q.isFocused&&!Q.isInputHidden).toggleClass("dropdown-active",Q.isOpen).toggleClass("has-options",!v.isEmptyObject(Q.options)).toggleClass("has-items",Q.items.length>0);Q.$control_input.data("grow",!R&&!S)},isFull:function(){return this.settings.maxItems!==null&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(U){var T,V,S,R,Q=this;U=U||{};if(Q.tagType===k){S=[];for(T=0,V=Q.items.length;T<V;T++){R=Q.options[Q.items[T]][Q.settings.labelField]||"";S.push('<option value="'+D(Q.items[T])+'" selected="selected">'+D(R)+"</option>")}if(!S.length&&!this.$input.attr("multiple")){S.push('<option value="" selected="selected"></option>')}Q.$input.html(S.join(""))}else{Q.$input.val(Q.getValue());Q.$input.attr("value",Q.$input.val())}if(Q.isSetup){if(!U.silent){Q.trigger("change",Q.$input.val())}}},updatePlaceholder:function(){if(!this.settings.placeholder){return}var Q=this.$control_input;if(this.items.length){Q.removeAttr("placeholder")}else{Q.attr("placeholder",this.settings.placeholder)}Q.triggerHandler("update",{force:true})},open:function(){var Q=this;if(Q.isLocked||Q.isOpen||(Q.settings.mode==="multi"&&Q.isFull())){return}Q.focus();Q.isOpen=true;Q.refreshState();Q.$dropdown.css({visibility:"hidden",display:"block"});Q.positionDropdown();Q.$dropdown.css({visibility:"visible"});Q.trigger("dropdown_open",Q.$dropdown)},close:function(){var Q=this;var R=Q.isOpen;if(Q.settings.mode==="single"&&Q.items.length){Q.hideInput();Q.$control_input.blur()}Q.isOpen=false;Q.$dropdown.hide();Q.setActiveOption(null);Q.refreshState();if(R){Q.trigger("dropdown_close",Q.$dropdown)}},positionDropdown:function(){var Q=this.$control;var R=this.settings.dropdownParent==="body"?Q.offset():Q.position();R.top+=Q.outerHeight(true);this.$dropdown.css({width:Q.outerWidth(),top:R.top,left:R.left})},clear:function(R){var Q=this;if(!Q.items.length){return}Q.$control.children(":not(input)").remove();Q.items=[];Q.lastQuery=null;Q.setCaret(0);Q.setActiveItem(null);Q.updatePlaceholder();Q.updateOriginalInput({silent:R});Q.refreshState();Q.showInput();Q.trigger("clear")},insertAtCaret:function(Q){var R=Math.min(this.caretPos,this.items.length);if(R===0){this.$control.prepend(Q)}else{v(this.$control[0].childNodes[R]).before(Q)}this.setCaret(R+1)},deleteSelection:function(T){var R,Q,X,Y,Z,V,U,W,S;var aa=this;X=(T&&T.keyCode===o)?-1:1;Y=l(aa.$control_input[0]);if(aa.$activeOption&&!aa.settings.hideSelected){U=aa.getAdjacentOption(aa.$activeOption,-1).attr("data-value")}Z=[];if(aa.$activeItems.length){S=aa.$control.children(".active:"+(X>0?"last":"first"));V=aa.$control.children(":not(input)").index(S);if(X>0){V++}for(R=0,Q=aa.$activeItems.length;R<Q;R++){Z.push(v(aa.$activeItems[R]).attr("data-value"))}if(T){T.preventDefault();T.stopPropagation()}}else{if((aa.isFocused||aa.settings.mode==="single")&&aa.items.length){if(X<0&&Y.start===0&&Y.length===0){Z.push(aa.items[aa.caretPos-1])}else{if(X>0&&Y.start===aa.$control_input.val().length){Z.push(aa.items[aa.caretPos])}}}}if(!Z.length||(typeof aa.settings.onDelete==="function"&&aa.settings.onDelete.apply(aa,[Z])===false)){return false}if(typeof V!=="undefined"){aa.setCaret(V)}while(Z.length){aa.removeItem(Z.pop())}aa.showInput();aa.positionDropdown();aa.refreshOptions(true);if(U){W=aa.getOption(U);if(W.length){aa.setActiveOption(W)}}return true},advanceSelection:function(U,R){var S,V,W,X,T,Q;var Y=this;if(U===0){return}if(Y.rtl){U*=-1}S=U>0?"last":"first";V=l(Y.$control_input[0]);if(Y.isFocused&&!Y.isInputHidden){X=Y.$control_input.val().length;T=U<0?V.start===0&&V.length===0:V.start===X;if(T&&!X){Y.advanceCaret(U,R)}}else{Q=Y.$control.children(".active:"+S);if(Q.length){W=Y.$control.children(":not(input)").index(Q);Y.setActiveItem(null);Y.setCaret(U>0?W+1:W)}}},advanceCaret:function(U,T){var Q=this,S,R;if(U===0){return}S=U>0?"next":"prev";if(Q.isShiftDown){R=Q.$control_input[S]();if(R.length){Q.hideInput();Q.setActiveItem(R);T&&T.preventDefault()}}else{Q.setCaret(Q.caretPos+U)}},setCaret:function(T){var R=this;if(R.settings.mode==="single"){T=R.items.length}else{T=Math.max(0,Math.min(R.items.length,T))}if(!R.isPending){var S,W,U,Q,V;Q=R.$control.children(":not(input)");for(S=0,W=Q.length;S<W;S++){V=v(Q[S]).detach();if(S<T){R.$control_input.before(V)}else{R.$control.append(V)}}}R.caretPos=T},lock:function(){this.close();this.isLocked=true;this.refreshState()},unlock:function(){this.isLocked=false;this.refreshState()},disable:function(){var Q=this;Q.$input.prop("disabled",true);Q.$control_input.prop("disabled",true).prop("tabindex",-1);Q.isDisabled=true;Q.lock()},enable:function(){var Q=this;Q.$input.prop("disabled",false);Q.$control_input.prop("disabled",false).prop("tabindex",Q.tabIndex);Q.isDisabled=false;Q.unlock()},destroy:function(){var Q=this;var S=Q.eventNS;var R=Q.revertSettings;Q.trigger("destroy");Q.off();Q.$wrapper.remove();Q.$dropdown.remove();Q.$input.html("").append(R.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:R.tabindex}).show();Q.$control_input.removeData("grow");Q.$input.removeData("selectize");v(window).off(S);v(document).off(S);v(document.body).off(S);delete Q.$input[0].selectize},render:function(Y,S){var W,R,V;var T="";var Q=false;var X=this;var U=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;if(Y==="option"||Y==="item"){W=y(S[X.settings.valueField]);Q=!!W}if(Q){if(!P(X.renderCache[Y])){X.renderCache[Y]={}}if(X.renderCache[Y].hasOwnProperty(W)){return X.renderCache[Y][W]}}T=v(X.settings.render[Y].apply(this,[S,D]));if(Y==="option"||Y==="option_create"){T.attr("data-selectable","")}else{if(Y==="optgroup"){R=S[X.settings.optgroupValueField]||"";T.attr("data-group",R)}}if(Y==="option"||Y==="item"){T.attr("data-value",W||"")}if(Q){X.renderCache[Y][W]=T[0]}return T[0]},clearCache:function(Q){var R=this;if(typeof Q==="undefined"){R.renderCache={}}else{delete R.renderCache[Q]}},canCreate:function(R){var Q=this;if(!Q.settings.create){return false}var S=Q.settings.createFilter;return R.length&&(typeof S!=="function"||S.apply(Q,[R]))&&(typeof S!=="string"||new RegExp(S).test(R))&&(!(S instanceof RegExp)||S.test(R))}});c.count=0;c.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:true,diacritics:true,create:false,createOnBlur:false,createFilter:null,highlight:true,openOnFocus:true,maxOptions:1000,maxItems:null,hideSelected:null,addPrecedence:false,selectOnTab:false,preload:false,allowEmptyOption:false,closeAfterSelect:false,submitOnReturn:true,scrollDuration:60,loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:false,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,copyClassesToDropdown:true,render:{}};v.fn.selectize=function(W){var S=v.fn.selectize.defaults;var R=v.extend({},S,W);var T=R.dataAttr;var Z=R.labelField;var aa=R.valueField;var Y=R.optgroupField;var U=R.optgroupLabelField;var V=R.optgroupValueField;var Q=function(ai,ag){var ad,ah,ab,ae;var ac=ai.attr(T);if(!ac){var af=v.trim(ai.val()||"");if(!R.allowEmptyOption&&!af.length){return}ab=af.split(R.delimiter);for(ad=0,ah=ab.length;ad<ah;ad++){ae={};ae[Z]=ab[ad];ae[aa]=ab[ad];ag.options.push(ae)}ag.items=ab}else{ag.options=JSON.parse(ac);for(ad=0,ah=ag.options.length;ad<ah;ad++){ag.items.push(ag.options[ad][aa])}}};var X=function(ai,ag){var ah,ad,ae,al,af=0;var am=ag.options;var ak={};var ab=function(an){var ao=T&&an.attr(T);if(typeof ao==="string"&&ao.length){return JSON.parse(ao)}return null};var aj=function(ar,aq){ar=v(ar);var ap=y(ar.val());if(!ap&&!R.allowEmptyOption){return}if(ak.hasOwnProperty(ap)){if(aq){var an=ak[ap][Y];if(!an){ak[ap][Y]=aq}else{if(!v.isArray(an)){ak[ap][Y]=[an,aq]}else{an.push(aq)}}}return}var ao=ab(ar)||{};ao[Z]=ao[Z]||ar.text();ao[aa]=ao[aa]||ap;ao[Y]=ao[Y]||aq;ak[ap]=ao;am.push(ao);if(ar.is(":selected")){ag.items.push(ap)}};var ac=function(ao){var aq,at,ar,ap,an;ao=v(ao);ar=ao.attr("label");if(ar){ap=ab(ao)||{};ap[U]=ar;ap[V]=ar;ag.optgroups.push(ap)}an=v("option",ao);for(aq=0,at=an.length;aq<at;aq++){aj(an[aq],ar)}};ag.maxItems=ai.attr("multiple")?null:1;al=ai.children();for(ah=0,ad=al.length;ah<ad;ah++){ae=al[ah].tagName.toLowerCase();if(ae==="optgroup"){ac(al[ah])}else{if(ae==="option"){aj(al[ah])}}}};return this.each(function(){if(this.selectize){return}var ab;var af=v(this);var ae=this.tagName.toLowerCase();var ad=af.attr("placeholder")||af.attr("data-placeholder");if(!ad&&!R.allowEmptyOption){ad=af.children('option[value=""]').text()}var ac={placeholder:ad,options:[],optgroups:[],items:[]};if(ae==="select"){X(af,ac)}else{Q(af,ac)}ab=new c(af,v.extend(true,{},S,ac,W))})};v.fn.selectize.defaults=c.defaults;v.fn.selectize.support={validity:C};c.define("drag_drop",function(R){if(!v.fn.sortable){throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".')}if(this.settings.mode!=="multi"){return}var Q=this;Q.lock=(function(){var S=Q.lock;return function(){var T=Q.$control.data("sortable");if(T){T.disable()}return S.apply(Q,arguments)}})();Q.unlock=(function(){var S=Q.unlock;return function(){var T=Q.$control.data("sortable");if(T){T.enable()}return S.apply(Q,arguments)}})();Q.setup=(function(){var S=Q.setup;return function(){S.apply(this,arguments);var T=Q.$control.sortable({items:"[data-value]",forcePlaceholderSize:true,disabled:Q.isLocked,start:function(V,U){U.placeholder.css("width",U.helper.css("width"));T.css({overflow:"visible"})},stop:function(){T.css({overflow:"hidden"});var V=Q.$activeItems?Q.$activeItems.slice():null;var U=[];T.children("[data-value]").each(function(){U.push(v(this).attr("data-value"))});Q.setValue(U);Q.setActiveItem(V)}})}})()});c.define("dropdown_header",function(R){var Q=this;R=v.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(S){return('<div class="'+S.headerClass+'"><div class="'+S.titleRowClass+'"><span class="'+S.labelClass+'">'+S.title+'</span><a href="javascript:void(0)" class="'+S.closeClass+'">&times;</a></div></div>')}},R);Q.setup=(function(){var S=Q.setup;return function(){S.apply(Q,arguments);Q.$dropdown_header=v(R.html(R));Q.$dropdown.prepend(Q.$dropdown_header)}})()});c.define("optgroup_columns",function(S){var R=this;S=v.extend({equalizeWidth:true,equalizeHeight:true},S);this.getAdjacentOption=function(X,W){var U=X.closest("[data-group]").find("[data-selectable]");var V=U.index(X)+W;return V>=0&&V<U.length?U.eq(V):v()};this.onKeyDown=(function(){var U=R.onKeyDown;return function(Z){var X,Y,V,W;if(this.isOpen&&(Z.keyCode===p||Z.keyCode===t)){R.ignoreHover=true;W=this.$activeOption.closest("[data-group]");X=W.find("[data-selectable]").index(this.$activeOption);if(Z.keyCode===p){W=W.prev("[data-group]")}else{W=W.next("[data-group]")}V=W.find("[data-selectable]");Y=V.eq(Math.min(V.length-1,X));if(Y.length){this.setActiveOption(Y)}return}return U.apply(this,arguments)}})();var Q=function(){var W;var U=Q.width;var V=document;if(typeof U==="undefined"){W=V.createElement("div");W.innerHTML='<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>';W=W.firstChild;V.body.appendChild(W);U=Q.width=W.offsetWidth-W.clientWidth;V.body.removeChild(W)}return U};var T=function(){var V,aa,U,W,Z,Y,X;X=v("[data-group]",R.$dropdown_content);aa=X.length;if(!aa||!R.$dropdown_content.width()){return}if(S.equalizeHeight){U=0;for(V=0;V<aa;V++){U=Math.max(U,X.eq(V).height())}X.css({height:U})}if(S.equalizeWidth){Y=R.$dropdown_content.innerWidth()-Q();W=Math.round(Y/aa);X.css({width:W});if(aa>1){Z=Y-W*(aa-1);X.eq(aa-1).css({width:Z})}}};if(S.equalizeHeight||S.equalizeWidth){s.after(this,"positionDropdown",T);s.after(this,"refreshOptions",T)}});c.define("remove_button",function(Q){Q=v.extend({label:"&times;",title:"Remove",className:"remove",append:true},Q);var R=function(X,V){V.className="remove-single";var U=X;var W='<a href="javascript:void(0)" class="'+V.className+'" tabindex="-1" title="'+D(V.title)+'">'+V.label+"</a>";var T=function(Y,Z){return Y+Z};X.setup=(function(){var Y=U.setup;return function(){if(V.append){var ab=v(U.$input.context).attr("id");var aa=v("#"+ab);var Z=U.settings.render.item;U.settings.render.item=function(ac){return T(Z.apply(X,arguments),W)}}Y.apply(X,arguments);X.$control.on("click","."+V.className,function(ac){ac.preventDefault();if(U.isLocked){return}U.clear()})}})()};var S=function(X,V){var U=X;var W='<a href="javascript:void(0)" class="'+V.className+'" tabindex="-1" title="'+D(V.title)+'">'+V.label+"</a>";var T=function(Y,Z){var aa=Y.search(/(<\/[^>]+>\s*)$/);return Y.substring(0,aa)+Z+Y.substring(aa)};X.setup=(function(){var Y=U.setup;return function(){if(V.append){var Z=U.settings.render.item;U.settings.render.item=function(aa){return T(Z.apply(X,arguments),W)}}Y.apply(X,arguments);X.$control.on("click","."+V.className,function(ab){ab.preventDefault();if(U.isLocked){return}var aa=v(ab.currentTarget).parent();U.setActiveItem(aa);if(U.deleteSelection()){U.setCaret(U.items.length)}})}})()};if(this.settings.mode==="single"){R(this,Q);return}else{S(this,Q)}});c.define("restore_on_backspace",function(R){var Q=this;R.text=R.text||function(S){return S[this.settings.labelField]};this.onKeyDown=(function(){var S=Q.onKeyDown;return function(V){var T,U;if(V.keyCode===o&&this.$control_input.val()===""&&!this.$activeItems.length){T=this.caretPos-1;if(T>=0&&T<this.items.length){U=this.options[this.items[T]];if(this.deleteSelection(V)){this.setTextboxValue(R.text.apply(this,[U]));this.refreshOptions(true)}V.preventDefault();return}}return S.apply(this,arguments)}})()});return c}));