/*! selectize.js - v0.6.14 | https://github.com/brianreavis/selectize.js | Apache License (v2) */
(function(f){"object"===typeof exports?f(require("jquery")):"function"===typeof define&&define.amd?define(["jquery"],f):f(jQuery)})(function(f){var A=function(a,b){if("string"!==typeof b||b.length){var c="string"===typeof b?RegExp(b,"i"):b,d=function(a){var b=0;if(3===a.nodeType){var h=a.data.search(c);if(0<=h&&0<a.data.length){var f=a.data.match(c),b=document.createElement("span");b.className="highlight";a=a.splitText(h);a.splitText(f[0].length);h=a.cloneNode(!0);b.appendChild(h);a.parentNode.replaceChild(b,
a);b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(h=0;h<a.childNodes.length;++h)h+=d(a.childNodes[h]);return b};return a.each(function(){d(this)})}},r=function(){};r.prototype={on:function(a,b){this._events=this._events||{};this._events[a]=this._events[a]||[];this._events[a].push(b)},off:function(a,b){this._events=this._events||{};!1!==a in this._events&&this._events[a].splice(this._events[a].indexOf(b),1)},trigger:function(a){this._events=this._events||{};if(!1!==
a in this._events)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}};r.mixin=function(a){for(var b=["on","off","trigger"],c=0;c<b.length;c++)a.prototype[b[c]]=r.prototype[b[c]]};var s=/Mac/.test(navigator.userAgent),B=s?91:17,C=s?18:17,u={a:"[a\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]",c:"[c\u00c7\u00e7]",e:"[e\u00c8\u00c9\u00ca\u00cb\u00e8\u00e9\u00ea\u00eb]",i:"[i\u00cc\u00cd\u00ce\u00cf\u00ec\u00ed\u00ee\u00ef]",
n:"[n\u00d1\u00f1]",o:"[o\u00d2\u00d3\u00d4\u00d5\u00d5\u00d6\u00d8\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8]",s:"[s\u0160\u0161]",u:"[u\u00d9\u00da\u00db\u00dc\u00f9\u00fa\u00fb\u00fc]",y:"[y\u0178\u00ff\u00fd]",z:"[z\u017d\u017e]"},t=function(a){return"undefined"!==typeof a},k=function(a){return"undefined"===typeof a||null===a?"":"boolean"===typeof a?a?"1":"0":a+""},n=function(a){return(a+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},w=function(a){return a.replace(/(['"])/g,
"\\$1")},x={before:function(a,b,c){var d=a[b];a[b]=function(){c.apply(a,arguments);return d.apply(a,arguments)}},after:function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);c.apply(a,arguments);return b}}},y=function(a,b){if(!f.isArray(b))return b;var c,d,e={};c=0;for(d=b.length;c<d;c++)b[c].hasOwnProperty(a)&&(e[b[c][a]]=b[c]);return e},D=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},E=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c);
c=window.setTimeout(function(){a.apply(d,e)},b)}},z=function(a,b,c){var d,e=a.trigger,g={};a.trigger=function(){var c=arguments[0];if(-1!==b.indexOf(c))g[c]=arguments;else return e.apply(a,arguments)};c.apply(a,[]);a.trigger=e;for(d in g)g.hasOwnProperty(d)&&e.apply(a,g[d])},F=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;b.currentTarget=c;return d.apply(this,[b])})},v=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=
a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length);b.start=c.text.length-d;b.length=d}return b},G=function(a){var b=function(b){var d,e,g;b=b||window.event||{};if(!b.metaKey&&!b.altKey&&!1!==a.data("grow")){d=a.val();b.type&&"keydown"===b.type.toLowerCase()&&(e=b.keyCode,g=97<=e&&122>=e||65<=e&&90>=e||48<=e&&57>=e||32==e,46===e||8===e?(b=v(a[0]),b.length?d=d.substring(0,
b.start)+d.substring(b.start+b.length):8===e&&b.start?d=d.substring(0,b.start-1)+d.substring(b.start+1):46===e&&"undefined"!==typeof b.start&&(d=d.substring(0,b.start)+d.substring(b.start+1))):g&&(e=b.shiftKey,b=String.fromCharCode(b.keyCode),b=e?b.toUpperCase():b.toLowerCase(),d+=b));b=a.attr("placeholder")||"";!d.length&&b.length&&(d=b);d=f("<test>").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"nowrap"}).text(d).appendTo("body");b=["letterSpacing","fontSize",
"fontFamily","fontWeight","textTransform"];var h={};if(b)for(e=0,g=b.length;e<g;e++)h[b[e]]=a.css(b[e]);else h=a.css();d.css(h);b=d.width();d.remove();d=b+4;d!==a.width()&&(a.width(d),a.triggerHandler("resize"))}};a.on("keydown keyup update blur",b);b()},l=function(a,b){a[0].selectize=this;f.extend(this,{settings:b,$input:a,tagType:"select"===a[0].tagName.toLowerCase()?1:2,highlightedValue:null,isOpen:!1,isDisabled:!1,isLocked:!1,isFocused:!1,isInputFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,
isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:E(this.onSearchChange,b.loadThrottle)});f.extend(this.options,y(b.valueField,b.options));delete this.settings.options;f.extend(this.optgroups,y(b.optgroupValueField,b.optgroups));delete this.settings.optgroups;this.settings.mode=this.settings.mode||
(1===this.settings.maxItems?"single":"multi");"boolean"!==typeof this.settings.hideSelected&&(this.settings.hideSelected="multi"===this.settings.mode);this.loadPlugins(this.settings.plugins);this.setupCallbacks();this.setup()};r.mixin(l);(function(a,b){a.plugins={};a.prototype.loadPlugins=function(a){var b,e;this.plugins=[];this.pluginSettings={};if(f.isArray(a))for(b=0,e=a.length;b<e;b++)this.loadPlugin(a[b]);else if(a)for(b in this.pluginSettings=f.extend({},a),a)a.hasOwnProperty(b)&&this.loadPlugin(b)};
a.prototype.loadPlugin=function(c){var d,e,g;if(-1===this.plugins.indexOf(c)){if(!a.plugins.hasOwnProperty(c))throw Error(b+' unable to find "'+c+'" plugin');d=a.plugins[c];this.plugins.push(c);e=0;for(g=d.dependencies.length;e<g;e++)this.loadPlugin(d.dependencies[e]);d.fn.apply(this,[this.pluginSettings[c]||{}])}};a.registerPlugin=function(b){var d=arguments;a.plugins[b]={name:b,fn:d[d.length-1],dependencies:3===d.length?d[1]:[]}}})(l,"Selectize");f.extend(l.prototype,{setup:function(){var a=this,
b=a.settings,c,d,e,g,h,q;e=a.$input.attr("tabindex")||"";c=a.$input.attr("class")||"";c=f("<div>").addClass(b.theme).addClass(b.wrapperClass).addClass(c);d=f("<div>").addClass(b.inputClass).addClass("items").toggleClass("has-options",!f.isEmptyObject(a.options)).appendTo(c);e=f('<input type="text">').appendTo(d).attr("tabindex",e);g=f(b.dropdownParent||c);g=f("<div>").addClass(b.dropdownClass).hide().appendTo(g);h=f("<div>").addClass(b.dropdownContentClass).appendTo(g);c.css({width:a.$input[0].style.width,
display:a.$input.css("display")});a.plugins.length&&c.addClass("plugin-"+a.plugins.join(" plugin-"));q=a.settings.mode;c.toggleClass("single","single"===q);c.toggleClass("multi","multi"===q);(null===b.maxItems||1<b.maxItems)&&1===a.tagType&&a.$input.attr("multiple","multiple");a.settings.placeholder&&e.attr("placeholder",b.placeholder);a.$wrapper=c;a.$control=d;a.$control_input=e;a.$dropdown=g;a.$dropdown_content=h;d.on("mousedown",function(b){b.isDefaultPrevented()||window.setTimeout(function(){a.focus(!0)},
0)});d.on("click",function(b){a.isInputFocused||a.focus(!0)});g.on("mouseenter","[data-selectable]",function(){return a.onOptionHover.apply(a,arguments)});g.on("mousedown","[data-selectable]",function(){return a.onOptionSelect.apply(a,arguments)});F(d,"mousedown","*:not(input)",function(){return a.onItemSelect.apply(a,arguments)});G(e);e.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return a.onKeyDown.apply(a,arguments)},keyup:function(){return a.onKeyUp.apply(a,arguments)},keypress:function(){return a.onKeyPress.apply(a,
arguments)},resize:function(){a.positionDropdown.apply(a,[])},blur:function(){return a.onBlur.apply(a,arguments)},focus:function(){return a.onFocus.apply(a,arguments)}});f(document).on({keydown:function(b){a.isCmdDown=b[s?"metaKey":"ctrlKey"];a.isCtrlDown=b[s?"altKey":"ctrlKey"];a.isShiftDown=b.shiftKey},keyup:function(b){b.keyCode===C&&(a.isCtrlDown=!1);16===b.keyCode&&(a.isShiftDown=!1);b.keyCode===B&&(a.isCmdDown=!1)},mousedown:function(b){if(a.isFocused)if(b.target===a.$dropdown[0]||b.target.parentNode===
a.$dropdown[0]){var c=a.ignoreFocus;a.ignoreFocus=!0;window.setTimeout(function(){a.ignoreFocus=c;a.focus(!1)},0)}else a.$control.has(b.target).length||b.target===a.$control[0]||a.blur()}});f(window).on({"scroll resize":function(){a.isOpen&&a.positionDropdown.apply(a,arguments)},mousemove:function(){a.ignoreHover=!1}});a.$input.attr("tabindex",-1).hide().after(a.$wrapper);f.isArray(b.items)&&(a.setValue(b.items),delete b.items);a.updateOriginalInput();a.refreshItems();a.updatePlaceholder();a.isSetup=
!0;a.$input.is(":disabled")&&a.disable();a.trigger("initialize");if(b.preload)a.onSearchChange("")},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType"};for(a in c)if(c.hasOwnProperty(a)&&(b=this.settings[c[a]]))this.on(a,b)},triggerCallback:function(a){var b;
"function"===typeof this.settings[a]&&(b=Array.prototype.slice.apply(arguments,[1]),this.settings[a].apply(this,b))},onKeyPress:function(a){if(this.isLocked)return a&&a.preventDefault();var b=String.fromCharCode(a.keyCode||a.which);if(this.settings.create&&b===this.settings.delimiter)return this.createItem(),a.preventDefault(),!1},onKeyDown:function(a){if(this.isLocked)9!==a.keyCode&&a.preventDefault();else{switch(a.keyCode){case 65:if(this.isCmdDown){this.selectAll();return}break;case 27:this.blur();
return;case 40:if(!this.isOpen&&this.hasOptions)this.open();else if(this.$activeOption){this.ignoreHover=!0;var b=this.getAdjacentOption(this.$activeOption,1);b.length&&this.setActiveOption(b,!0,!0)}a.preventDefault();return;case 38:this.$activeOption&&(this.ignoreHover=!0,b=this.getAdjacentOption(this.$activeOption,-1),b.length&&this.setActiveOption(b,!0,!0));a.preventDefault();return;case 13:if(this.$activeOption)this.onOptionSelect({currentTarget:this.$activeOption});a.preventDefault();return;
case 37:this.advanceSelection(-1,a);return;case 39:this.advanceSelection(1,a);return;case 9:this.settings.create&&f.trim(this.$control_input.val()).length&&(this.createItem(),a.preventDefault());return;case 8:case 46:this.deleteSelection(a);return}(this.isFull()||this.isInputHidden)&&a.preventDefault()}},onKeyUp:function(a){if(this.isLocked)return a&&a.preventDefault();a=this.$control_input.val()||"";this.lastValue!==a&&(this.lastValue=a,this.onSearchChange(a),this.refreshOptions(),this.trigger("type",
a))},onSearchChange:function(a){var b=this,c=b.settings.load;c&&!b.loadedSearches.hasOwnProperty(a)&&(b.loadedSearches[a]=!0,b.load(function(d){c.apply(b,[a,d])}))},onFocus:function(a){this.isFocused=this.isInputFocused=!0;if(this.isDisabled)return this.blur(),a.preventDefault(),!1;if(!this.ignoreFocus){if("focus"===this.settings.preload)this.onSearchChange("");this.showInput();this.setActiveItem(null);this.refreshOptions(!!this.settings.openOnFocus);this.refreshClasses()}},onBlur:function(a){this.isInputFocused=
!1;this.ignoreFocus||(this.close(),this.setTextboxValue(""),this.setActiveItem(null),this.setActiveOption(null),this.setCaret(this.items.length),this.isFocused=!1,this.refreshClasses())},onOptionHover:function(a){this.ignoreHover||this.setActiveOption(a.currentTarget,!1)},onOptionSelect:function(a){var b;a.preventDefault&&a.preventDefault();a.stopPropagation&&a.stopPropagation();this.focus(!1);b=f(a.currentTarget);if(b.hasClass("create"))this.createItem();else if(b=b.attr("data-value"))this.setTextboxValue(""),
this.addItem(b),!this.settings.hideSelected&&(a.type&&/mouse/.test(a.type))&&this.setActiveOption(this.getOption(b))},onItemSelect:function(a){"multi"===this.settings.mode&&(a.preventDefault(),this.setActiveItem(a.currentTarget,a),this.focus(!1),this.hideInput())},load:function(a){var b=this,c=b.$wrapper.addClass("loading");b.loading++;a.apply(b,[function(a){b.loading=Math.max(b.loading-1,0);a&&a.length&&(b.addOption(a),b.refreshOptions(!1),b.isInputFocused&&b.open());b.loading||c.removeClass("loading");
b.trigger("load",a)}])},setTextboxValue:function(a){this.$control_input.val(a).triggerHandler("update");this.lastValue=a},getValue:function(){return 1===this.tagType&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(a){z(this,["change"],function(){this.clear();for(var b=f.isArray(a)?a:[a],c=0,d=b.length;c<d;c++)this.addItem(b[c])})},setActiveItem:function(a,b){var c,d,e;a=f(a);if(a.length){c=b&&b.type.toLowerCase();if("mousedown"===c&&this.isShiftDown&&
this.$activeItems.length){c=this.$control.children(".active:last");d=Array.prototype.indexOf.apply(this.$control[0].childNodes,[c[0]]);c=Array.prototype.indexOf.apply(this.$control[0].childNodes,[a[0]]);d>c&&(e=d,d=c,c=e);for(;d<=c;d++)e=this.$control[0].childNodes[d],-1===this.$activeItems.indexOf(e)&&(f(e).addClass("active"),this.$activeItems.push(e));b.preventDefault()}else"mousedown"===c&&this.isCtrlDown||"keydown"===c&&this.isShiftDown?a.hasClass("active")?(c=this.$activeItems.indexOf(a[0]),
this.$activeItems.splice(c,1),a.removeClass("active")):this.$activeItems.push(a.addClass("active")[0]):(f(this.$activeItems).removeClass("active"),this.$activeItems=[a.addClass("active")[0]]);this.isFocused=!!this.$activeItems.length||this.isInputFocused}else f(this.$activeItems).removeClass("active"),this.$activeItems=[],this.isFocused=this.isInputFocused},setActiveOption:function(a,b,c){var d,e,g;this.$activeOption&&this.$activeOption.removeClass("active");this.$activeOption=null;a=f(a);a.length&&
(this.$activeOption=a.addClass("active"),b||!t(b))&&(a=this.$dropdown_content.height(),d=this.$activeOption.outerHeight(!0),b=this.$dropdown_content.scrollTop()||0,e=this.$activeOption.offset().top-this.$dropdown_content.offset().top+b,g=e-a+d,e+d>a-b?this.$dropdown_content.stop().animate({scrollTop:g},c?this.settings.scrollDuration:0):e<b&&this.$dropdown_content.stop().animate({scrollTop:e},c?this.settings.scrollDuration:0))},selectAll:function(){this.$activeItems=Array.prototype.slice.apply(this.$control.children(":not(input)").addClass("active"));
this.isFocused=!0;this.$activeItems.length&&this.hideInput()},hideInput:function(){this.close();this.setTextboxValue("");this.$control_input.css({opacity:0,position:"absolute",left:-1E4});this.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0});this.isInputHidden=!1},focus:function(a){var b=this;b.isDisabled||(b.ignoreFocus=!0,b.$control_input[0].focus(),b.isInputFocused=!0,window.setTimeout(function(){b.ignoreFocus=!1;if(a)b.onFocus()},0))},blur:function(){this.$control_input.trigger("blur")},
parseSearchTokens:function(a){a=f.trim(String(a||"").toLowerCase());if(!a||!a.length)return[];var b,c,d,e=[],g=a.split(/ +/);a=0;for(b=g.length;a<b;a++){c=(g[a]+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");if(this.settings.diacritics)for(d in u)u.hasOwnProperty(d)&&(c=c.replace(RegExp(d,"g"),u[d]));e.push({string:g[a],regex:RegExp(c,"i")})}return e},getScoreFunction:function(a){var b=this,c=a.tokens,d=function(){return c.length?1===c.length?function(a){var b;a=String(a||"").toLowerCase();b=a.search(c[0].regex);
if(-1===b)return 0;a=c[0].string.length/a.length;0===b&&(a+=0.5);return a}:function(a){var b,d,f,m;a=String(a||"").toLowerCase();f=b=0;for(m=c.length;f<m;f++){d=a.search(c[f].regex);if(-1===d)return 0;0===d&&(b+=0.5);b+=c[f].string.length/a.length}return b/c.length}:function(){return 0}}();return function(){var a=b.settings.searchField;"string"===typeof a&&(a=[a]);if(a&&a.length){if(1===a.length){var c=a[0];return function(a){return a.hasOwnProperty(c)?d(a[c]):0}}return function(b){for(var c=0,g=
0,f=0,H=a.length;f<H;f++)b.hasOwnProperty(a[f])&&(g+=d(b[a[f]]),c++);return g/c}}return function(){return 0}}()},search:function(a,b){var c=this,d,e,g,h;b=b||{};a=f.trim(String(a||"").toLowerCase());if(a!==c.lastQuery){c.lastQuery=a;g={query:a,tokens:c.parseSearchTokens(a),total:0,items:[]};if(c.settings.score){if(h=c.settings.score.apply(this,[g]),"function"!==typeof h)throw Error('Selectize "score" setting must be a function that returns a function');}else h=c.getScoreFunction(g);if(a.length){for(d in c.options)c.options.hasOwnProperty(d)&&
(e=h(c.options[d]),0<e&&g.items.push({score:e,value:d}));g.items.sort(function(a,b){return b.score-a.score})}else{for(d in c.options)c.options.hasOwnProperty(d)&&g.items.push({score:1,value:d});c.settings.sortField&&g.items.sort(function(){var a=c.settings.sortField,b="desc"===c.settings.sortDirection?-1:1;return function(d,e){d=d&&String(c.options[d.value][a]||"").toLowerCase();e=e&&String(c.options[e.value][a]||"").toLowerCase();return d>e?1*b:e>d?-1*b:0}}())}c.currentResults=g}else g=f.extend(!0,
{},c.currentResults);return c.prepareResults(g,b)},prepareResults:function(a,b){if(this.settings.hideSelected)for(var c=a.items.length-1;0<=c;c--)-1!==this.items.indexOf(String(a.items[c].value))&&a.items.splice(c,1);a.total=a.items.length;"number"===typeof b.limit&&(a.items=a.items.slice(0,b.limit));return a},refreshOptions:function(a){"undefined"===typeof a&&(a=!0);var b,c,d,e,g,h,q,m=this.$control_input.val(),p=this.search(m,{}),l,k=this.$dropdown_content;c=p.items.length;"number"===typeof this.settings.maxOptions&&
(c=Math.min(c,this.settings.maxOptions));d={};if(this.settings.optgroupOrder)for(e=this.settings.optgroupOrder,b=0;b<e.length;b++)d[e[b]]=[];else e=[];for(b=0;b<c;b++)g=this.options[p.items[b].value],h=g[this.settings.optgroupField]||"",this.optgroups.hasOwnProperty(h)||(h=""),d.hasOwnProperty(h)||(d[h]=[],e.push(h)),d[h].push(this.render("option",g));g=[];b=0;for(c=e.length;b<c;b++)h=e[b],this.optgroups.hasOwnProperty(h)&&d[h].length?(q=this.render("optgroup_header",this.optgroups[h])||"",q+=d[h].join(""),
g.push(this.render("optgroup",f.extend({},this.optgroups[h],{html:q})))):g.push(d[h].join(""));k.html(g.join(""));if(this.settings.highlight&&p.query.length&&p.tokens.length)for(b=0,c=p.tokens.length;b<c;b++)A(k,p.tokens[b].regex);if(!this.settings.hideSelected)for(b=0,c=this.items.length;b<c;b++)this.getOption(this.items[b]).addClass("selected");if(b=this.settings.create&&p.query.length)k.prepend(this.render("option_create",{input:m})),l=f(k[0].childNodes[0]);(this.hasOptions=0<p.items.length||b)?
(m=0<p.items.length?l?this.getAdjacentOption(l,1):k.find("[data-selectable]").first():l,this.setActiveOption(m),a&&!this.isOpen&&this.open()):(this.setActiveOption(null),a&&this.isOpen&&this.close())},addOption:function(a,b){var c,d;if(f.isArray(a))for(c=0,d=a.length;c<d;c++)this.addOption(a[c][this.settings.valueField],a[c]);else a=k(a),this.options.hasOwnProperty(a)||(this.userOptions[a]=!0,this.options[a]=b,this.lastQuery=null,this.trigger("option_add",a,b))},addOptionGroup:function(a,b){this.optgroups[a]=
b;this.trigger("optgroup_add",value,b)},updateOption:function(a,b){var c,d,e;a=k(a);c=k(b[this.settings.valueField]);if(this.options.hasOwnProperty(a)){if(!c)throw Error("Value must be set in option data");c!==a&&(delete this.options[a],d=this.items.indexOf(a),-1!==d&&this.items.splice(d,1,c));this.options[c]=b;d=this.renderCache.item;e=this.renderCache.option;t(d)&&(delete d[a],delete d[c]);t(e)&&(delete e[a],delete e[c]);-1!==this.items.indexOf(c)&&(c=this.getItem(a),d=f(this.render("item",b)),
c.hasClass("active")&&d.addClass("active"),c.replaceWith(d));this.isOpen&&this.refreshOptions(!1)}},removeOption:function(a){a=k(a);delete this.userOptions[a];delete this.options[a];this.lastQuery=null;this.trigger("option_remove",a);this.removeItem(a)},clearOptions:function(){this.loadedSearches={};this.userOptions={};this.options={};this.lastQuery=null;this.trigger("option_clear");this.clear()},getOption:function(a){return(a=k(a))?this.$dropdown_content.find("[data-selectable]").filter('[data-value="'+
w(a)+'"]:first'):f()},getAdjacentOption:function(a,b){var c=this.$dropdown.find("[data-selectable]"),d=c.index(a)+b;return 0<=d&&d<c.length?c.eq(d):f()},getItem:function(a){return this.$control.children('[data-value="'+w(k(a))+'"]')},addItem:function(a){z(this,["change"],function(){var b,c,d=this,e=d.settings.mode,g;a=k(a);"single"===e&&d.clear();"multi"===e&&d.isFull()||(-1!==d.items.indexOf(a)||!d.options.hasOwnProperty(a))||(b=f(d.render("item",d.options[a])),d.items.splice(d.caretPos,0,a),d.insertAtCaret(b),
d.refreshClasses(),d.isSetup&&(g=d.$dropdown_content.find("[data-selectable]"),c=d.getOption(a),c=d.getAdjacentOption(c,1).attr("data-value"),d.refreshOptions(d.isFocused&&"single"!==e),c&&d.setActiveOption(d.getOption(c)),!g.length||null!==d.settings.maxItems&&d.items.length>=d.settings.maxItems?d.close():d.positionDropdown(),d.isFocused&&window.setTimeout(function(){"single"===e?(d.blur(),d.focus(!1),d.hideInput()):d.focus(!1)},0),d.updatePlaceholder(),d.trigger("item_add",a,b),d.updateOriginalInput()))})},
removeItem:function(a){var b,c;b="object"===typeof a?a:this.getItem(a);a=k(b.attr("data-value"));c=this.items.indexOf(a);-1!==c&&(b.remove(),b.hasClass("active")&&(b=this.$activeItems.indexOf(b[0]),this.$activeItems.splice(b,1)),this.items.splice(c,1),this.lastQuery=null,!this.settings.persist&&this.userOptions.hasOwnProperty(a)&&this.removeOption(a),c<this.caretPos&&this.setCaret(this.caretPos-1),this.refreshClasses(),this.updatePlaceholder(),this.updateOriginalInput(),this.positionDropdown(),this.trigger("item_remove",
a))},createItem:function(){var a=this,b=f.trim(a.$control_input.val()||""),c=a.caretPos;if(b.length){a.lock();var d="function"===typeof a.settings.create?this.settings.create:function(b){var c={};c[a.settings.labelField]=b;c[a.settings.valueField]=b;return c},e=D(function(b){a.unlock();a.focus(!1);if(b&&"object"===typeof b){var d=k(b[a.settings.valueField]);d&&(a.setTextboxValue(""),a.addOption(d,b),a.setCaret(c),a.addItem(d),a.refreshOptions("single"!==a.settings.mode),a.focus(!1))}}),b=d.apply(this,
[b,e]);"undefined"!==typeof b&&e(b)}},refreshItems:function(){this.lastQuery=null;if(this.isSetup)for(var a=0;a<this.items.length;a++)this.addItem(this.items);this.refreshClasses();this.updateOriginalInput()},refreshClasses:function(){var a=this.isFull(),b=this.isLocked;this.$control.toggleClass("focus",this.isFocused).toggleClass("disabled",this.isDisabled).toggleClass("locked",b).toggleClass("full",a).toggleClass("not-full",!a).toggleClass("dropdown-active",this.isOpen).toggleClass("has-items",
0<this.items.length);this.$control_input.data("grow",!a&&!b)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(){var a,b,c;if("select"===this.$input[0].tagName.toLowerCase()){c=[];a=0;for(b=this.items.length;a<b;a++)c.push('<option value="'+n(this.items[a])+'" selected="selected"></option>');c.length||this.$input.attr("multiple")||c.push('<option value="" selected="selected"></option>');this.$input.html(c.join(""))}else this.$input.val(this.getValue());
this.$input.trigger("change");this.isSetup&&this.trigger("change",this.$input.val())},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder);a.triggerHandler("update")}},open:function(){this.isLocked||(this.isOpen||"multi"===this.settings.mode&&this.isFull())||(this.focus(!0),this.isOpen=!0,this.refreshClasses(),this.$dropdown.css({visibility:"hidden",display:"block"}),this.positionDropdown(),
this.$dropdown.css({visibility:"visible"}),this.trigger("dropdown_open",this.$dropdown))},close:function(){this.isOpen&&(this.$dropdown.hide(),this.setActiveOption(null),this.isOpen=!1,this.refreshClasses(),this.trigger("dropdown_close",this.$dropdown))},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0);this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(){this.items.length&&(this.$control.children(":not(input)").remove(),
this.items=[],this.setCaret(0),this.updatePlaceholder(),this.updateOriginalInput(),this.refreshClasses(),this.showInput(),this.trigger("clear"))},insertAtCaret:function(a){var b=Math.min(this.caretPos,this.items.length);0===b?this.$control.prepend(a):f(this.$control[0].childNodes[b]).before(a);this.setCaret(b+1)},deleteSelection:function(a){var b,c,d,e,g;b=a&&8===a.keyCode?-1:1;c=v(this.$control_input[0]);this.$activeOption&&!this.settings.hideSelected&&(g=this.getAdjacentOption(this.$activeOption,
-1).attr("data-value"));d=[];if(this.$activeItems.length){e=this.$control.children(".active:"+(0<b?"last":"first"));e=this.$control.children(":not(input)").index(e);0<b&&e++;b=0;for(c=this.$activeItems.length;b<c;b++)d.push(f(this.$activeItems[b]).attr("data-value"));a&&(a.preventDefault(),a.stopPropagation())}else(this.isFocused||"single"===this.settings.mode)&&this.items.length&&(0>b&&0===c.start&&0===c.length?d.push(this.items[this.caretPos-1]):0<b&&c.start===this.$control_input.val().length&&
d.push(this.items[this.caretPos]));if(!d.length||"function"===typeof this.settings.onDelete&&!1===this.settings.onDelete(d))return!1;for("undefined"!==typeof e&&this.setCaret(e);d.length;)this.removeItem(d.pop());this.showInput();this.refreshOptions(!0);g&&(a=this.getOption(g),a.length&&this.setActiveOption(a));return!0},advanceSelection:function(a,b){var c,d;0!==a&&(c=0<a?"last":"first",d=v(this.$control_input[0]),this.isInputFocused&&!this.isInputHidden?(c=this.$control_input.val().length,(d=0>
a?0===d.start&&0===d.length:d.start===c)&&!c&&this.advanceCaret(a,b)):(d=this.$control.children(".active:"+c),d.length&&(d=this.$control.children(":not(input)").index(d),this.setActiveItem(null),this.setCaret(0<a?d+1:d),this.showInput())))},advanceCaret:function(a,b){if(0!==a){var c=0<a?"next":"prev";this.isShiftDown?(c=this.$control_input[c](),c.length&&(this.hideInput(),this.setActiveItem(c),b&&b.preventDefault())):this.setCaret(this.caretPos+a)}},setCaret:function(a){a="single"===this.settings.mode?
this.items.length:Math.max(0,Math.min(this.items.length,a));var b,c,d,e;d=this.$control.children(":not(input)");b=0;for(c=d.length;b<c;b++)e=f(d[b]).detach(),b<a?this.$control_input.before(e):this.$control.append(e);this.caretPos=a},lock:function(){this.close();this.isLocked=!0;this.refreshClasses()},unlock:function(){this.isLocked=!1;this.refreshClasses()},disable:function(){this.isDisabled=!0;this.lock()},enable:function(){this.isDisabled=!1;this.unlock()},render:function(a,b){var c,d,e="",g=!1,
h=/^[\\t ]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;if("option"===a||"item"===a)c=k(b[this.settings.valueField]),g=!!c;if(g&&(t(this.renderCache[a])||(this.renderCache[a]={}),this.renderCache[a].hasOwnProperty(c)))return this.renderCache[a][c];if(this.settings.render&&"function"===typeof this.settings.render[a])e=this.settings.render[a].apply(this,[b,n]);else switch(d=b[this.settings.labelField],a){case "optgroup":e='<div class="optgroup">'+b.html+"</div>";break;case "optgroup_header":d=b[this.settings.optgroupLabelField];
e='<div class="optgroup-header">'+n(d)+"</div>";break;case "option":e='<div class="option">'+n(d)+"</div>";break;case "item":e='<div class="item">'+n(d)+"</div>";break;case "option_create":e='<div class="create">Add <strong>'+n(b.input)+"</strong>&hellip;</div>"}if("option"===a||"option_create"===a)e=e.replace(h,"<$1 data-selectable");"optgroup"===a&&(d=b[this.settings.optgroupValueField]||"",e=e.replace(h,'<$1 data-group="'+n(d)+'"'));if("option"===a||"item"===a)e=e.replace(h,'<$1 data-value="'+
n(c||"")+'"');g&&(this.renderCache[a][c]=e);return e}});l.defaults={plugins:[],delimiter:",",persist:!0,diacritics:!0,create:!1,highlight:!0,openOnFocus:!0,maxOptions:1E3,maxItems:null,hideSelected:null,preload:!1,scrollDuration:60,loadThrottle:300,dataAttr:"data-data",optgroupField:"optgroup",sortField:null,sortDirection:"asc",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",optgroupOrder:null,searchField:["text"],mode:null,theme:"default",wrapperClass:"selectize-control",
inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,render:{}};f.fn.selectize=function(a){a=a||{};var b=f.fn.selectize.defaults,c=a.dataAttr||b.dataAttr,d=function(a,b){var d,l,m,k;b.maxItems=a.attr("multiple")?null:1;var n=function(a){a=c&&a.attr(c);return"string"===typeof a&&a.length?JSON.parse(a):null},r=function(a,c){a=f(a);var d=a.attr("value")||"";d.length&&(b.options[d]=n(a)||{text:a.text(),value:d,optgroup:c},
a.is(":selected")&&b.items.push(d))},s=function(a){var c,d=f("option",a);a=f(a);var e=a.attr("label");e&&e.length&&(b.optgroups[e]=n(a)||{label:e});a=0;for(c=d.length;a<c;a++)r(d[a],e)};k=a.children();d=0;for(l=k.length;d<l;d++)m=k[d].tagName.toLowerCase(),"optgroup"===m?s(k[d]):"option"===m&&r(k[d])};return this.each(function(){var c,g=f(this),h=g[0].tagName.toLowerCase();c={placeholder:g.children('option[value=""]').text()||g.attr("placeholder"),options:{},optgroups:{},items:[]};if("select"===h)d(g,
c);else{var k,m,h=f.trim(g.val()||"");if(h.length){m=h.split(a.delimiter||b.delimiter);h=0;for(k=m.length;h<k;h++)c.options[m[h]]={text:m[h],value:m[h]};c.items=m}}c=new l(g,f.extend(!0,{},b,c,a));g.data("selectize",c);g.addClass("selectized")})};f.fn.selectize.defaults=l.defaults;l.registerPlugin("drag_drop",function(a){if(!f.fn.sortable)throw Error('The "drag_drop" Selectize plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var b=this;this.setup=function(){var a=b.setup;return function(){a.apply(this,
arguments);var d=this.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,start:function(a,b){b.placeholder.css("width",b.helper.css("width"));d.css({overflow:"visible"})},stop:function(){d.css({overflow:"hidden"});var a=this.$activeItems?this.$activeItems.slice():null,c=[];d.children("[data-value]").each(function(){c.push(f(this).attr("data-value"))});b.setValue(c);b.setActiveItem(a)}})}}()}});l.registerPlugin("dropdown_header",function(a){var b=this;a=f.extend({title:"Untitled",headerClass:"selectize-dropdown-header",
titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(a){return'<div class="'+a.headerClass+'"><div class="'+a.titleRowClass+'"><span class="'+a.labelClass+'">'+a.title+'</span><a href="javascript:void(0)" class="'+a.closeClass+'">&times;</a></div></div>'}},a);b.setup=function(){var c=b.setup;return function(){c.apply(b,arguments);b.$dropdown_header=f(a.html(a));b.$dropdown.prepend(b.$dropdown_header)}}()});
l.registerPlugin("optgroup_columns",function(a){var b=this;a=f.extend({equalizeWidth:!0,equalizeHeight:!0},a);this.getAdjacentOption=function(a,b){var c=a.closest("[data-group]").find("[data-selectable]"),h=c.index(a)+b;return 0<=h&&h<c.length?c.eq(h):f()};this.onKeyDown=function(){var a=b.onKeyDown;return function(c){var g,f;if(!this.isOpen||37!==c.keyCode&&39!==c.keyCode)return a.apply(this,arguments);b.ignoreHover=!0;f=this.$activeOption.closest("[data-group]");g=f.find("[data-selectable]").index(this.$activeOption);
f=37===c.keyCode?f.prev("[data-group]"):f.next("[data-group]");f=f.find("[data-selectable]");g=f.eq(Math.min(f.length-1,g));g.length&&this.setActiveOption(g)}}();var c=function(){var c,e,g,h;h=f("[data-group]",b.$dropdown_content);if((e=h.length)&&b.$dropdown_content.width()){if(a.equalizeHeight){for(c=g=0;c<e;c++)g=Math.max(g,h.eq(c).height());h.css({height:g})}a.equalizeWidth&&(g=b.$dropdown_content.innerWidth(),c=Math.round(g/e),h.css({width:c}),1<e&&(c=g-c*(e-1),h.eq(e-1).css({width:c})))}};if(a.equalizeHeight||
a.equalizeWidth)x.after(this,"positionDropdown",c),x.after(this,"refreshOptions",c)});l.registerPlugin("remove_button",function(a){var b=this;this.settings.render.item=function(a){return'<div class="item">'+a[b.settings.labelField]+' <a href="javascript:void(0)" class="remove" tabindex="-1" title="Remove">&times;</a></div>'};this.setup=function(){var a=b.setup;return function(){a.apply(this,arguments);this.$control.on("click",".remove",function(a){a.preventDefault();a=f(a.target).parent();b.setActiveItem(a);
b.deleteSelection()&&b.setCaret(b.items.length)})}}()});l.registerPlugin("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]};this.onKeyDown=function(c){var d=b.onKeyDown;return function(b){var c;if(8===b.keyCode&&(""===this.$control_input.val()&&!this.$activeItems.length)&&(c=this.caretPos-1,0<=c&&c<this.items.length)){c=this.options[this.items[c]];this.deleteSelection(b)&&(this.setTextboxValue(a.text.apply(this,[c])),this.refreshOptions(!0));
b.preventDefault();return}return d.apply(this,arguments)}}()});return l});
