(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;j0){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:(kj){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=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/g,">").replace(/"/g,""")};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").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").addClass(ad.wrapperClass).addClass(ae).addClass(ai);af=v("
").addClass(ad.inputClass).addClass("items").appendTo(ab);R=v('').appendTo(af).attr("tabindex",S.is(":disabled")?"-1":W.tabIndex);ac=v(ad.dropdownParent||ab);T=v("
").addClass(ad.dropdownClass).addClass(ai).hide().appendTo(ac);X=v("
").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'
'+U.html+"
"},optgroup_header:function(V,U){return'
'+U(V[S])+"
"},option:function(V,U){return'
'+U(V[Q])+"
"},item:function(V,U){return'
'+U(V[Q])+"
"},option_create:function(V,U){return'
Add '+U(V.input)+"
"}};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;US){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=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;ah0||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=0&&R0);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'+D(R)+"")}if(!S.length&&!this.$input.attr("multiple")){S.push('')}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;R0&&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
'+S.title+'×
')}},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
';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;V1){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:"×",title:"Remove",className:"remove",append:true},Q);var R=function(X,V){V.className="remove-single";var U=X;var W=''+V.label+"";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=''+V.label+"";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