-
Notifications
You must be signed in to change notification settings - Fork 44
/
selectize.min.js
2 lines (2 loc) · 41.2 KB
/
selectize.min.js
1
2
!function(e,t){"function"==typeof define&&define.amd?define("sifter",t):"object"==typeof exports?module.exports=t():e.Sifter=t()}(this,function(){var e=function(e,t){this.items=e,this.settings=t||{diacritics:!0}};e.prototype.tokenize=function(e){if(e=i(((e||"")+"").toLowerCase()),!e||!e.length)return[];var t,n,o,a,l=[],u=e.split(/ +/);for(t=0,n=u.length;n>t;t++){if(o=r(u[t]),this.settings.diacritics)for(a in s)s.hasOwnProperty(a)&&(o=o.replace(RegExp(a,"g"),s[a]));l.push({string:u[t],regex:RegExp(o,"i")})}return l},e.prototype.iterator=function(e,t){var n;n=o(e)?Array.prototype.forEach||function(e){for(var t=0,n=this.length;n>t;t++)e(this[t],t,this)}:function(e){for(var t in this)this.hasOwnProperty(t)&&e(this[t],t,this)},n.apply(e,[t])},e.prototype.getScoreFunction=function(e,t){var n,i,r,o;n=this,e=n.prepareSearch(e,t),r=e.tokens,i=e.options.fields,o=r.length;var s=function(e,t){var n,i;return e?(e=(e||"")+"",i=e.search(t.regex),-1===i?0:(n=t.string.length/e.length,0===i&&(n+=.5),n)):0},a=function(){var e=i.length;return e?1===e?function(e,t){return s(t[i[0]],e)}:function(t,n){for(var r=0,o=0;e>r;r++)o+=s(n[i[r]],t);return o/e}:function(){return 0}}();return o?1===o?function(e){return a(r[0],e)}:"and"===e.options.conjunction?function(e){for(var t,n=0,i=0;o>n;n++){if(t=a(r[n],e),0>=t)return 0;i+=t}return i/o}:function(e){for(var t=0,n=0;o>t;t++)n+=a(r[t],e);return n/o}:function(){return 0}},e.prototype.getSortFunction=function(e,n){var i,r,o,s,a,l,u,c,p,d,h;if(o=this,e=o.prepareSearch(e,n),h=!e.query&&n.sort_empty||n.sort,p=function(e,t){return"$score"===e?t.score:o.items[t.id][e]},a=[],h)for(i=0,r=h.length;r>i;i++)(e.query||"$score"!==h[i].field)&&a.push(h[i]);if(e.query){for(d=!0,i=0,r=a.length;r>i;i++)if("$score"===a[i].field){d=!1;break}d&&a.unshift({field:"$score",direction:"desc"})}else for(i=0,r=a.length;r>i;i++)if("$score"===a[i].field){a.splice(i,1);break}for(c=[],i=0,r=a.length;r>i;i++)c.push("desc"===a[i].direction?-1:1);return l=a.length,l?1===l?(s=a[0].field,u=c[0],function(e,n){return u*t(p(s,e),p(s,n))}):function(e,n){var i,r,o;for(i=0;l>i;i++)if(o=a[i].field,r=c[i]*t(p(o,e),p(o,n)))return r;return 0}:null},e.prototype.prepareSearch=function(e,t){if("object"==typeof e)return e;t=n({},t);var i=t.fields,r=t.sort,s=t.sort_empty;return i&&!o(i)&&(t.fields=[i]),r&&!o(r)&&(t.sort=[r]),s&&!o(s)&&(t.sort_empty=[s]),{options:t,query:((e||"")+"").toLowerCase(),tokens:this.tokenize(e),total:0,items:[]}},e.prototype.search=function(e,t){var n,i,r,o,s=this;return i=this.prepareSearch(e,t),t=i.options,e=i.query,o=t.score||s.getScoreFunction(i),e.length?s.iterator(s.items,function(e,r){n=o(e),(t.filter===!1||n>0)&&i.items.push({score:n,id:r})}):s.iterator(s.items,function(e,t){i.items.push({score:1,id:t})}),r=s.getSortFunction(i,t),r&&i.items.sort(r),i.total=i.items.length,"number"==typeof t.limit&&(i.items=i.items.slice(0,t.limit)),i};var t=function(e,t){return"number"==typeof e&&"number"==typeof t?e>t?1:t>e?-1:0:(e=a((e||"")+""),t=a((t||"")+""),e>t?1:t>e?-1:0)},n=function(e){var t,n,i,r;for(t=1,n=arguments.length;n>t;t++)if(r=arguments[t])for(i in r)r.hasOwnProperty(i)&&(e[i]=r[i]);return e},i=function(e){return(e+"").replace(/^\s+|\s+$|/g,"")},r=function(e){return(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},o=Array.isArray||$&&$.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},s={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎ]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},a=function(){var e,t,n,i,r="",o={};for(n in s)if(s.hasOwnProperty(n))for(i=s[n].substring(2,s[n].length-1),r+=i,e=0,t=i.length;t>e;e++)o[i.charAt(e)]=n;var a=RegExp("["+r+"]","g");return function(e){return e.replace(a,function(e){return o[e]}).toLowerCase()}}();return e}),function(e,t){"function"==typeof define&&define.amd?define("microplugin",t):"object"==typeof exports?module.exports=t():e.MicroPlugin=t()}(this,function(){var e={};e.mixin=function(e){e.plugins={},e.prototype.initializePlugins=function(e){var n,i,r,o=this,s=[];if(o.plugins={names:[],settings:{},requested:{},loaded:{}},t.isArray(e))for(n=0,i=e.length;i>n;n++)"string"==typeof e[n]?s.push(e[n]):(o.plugins.settings[e[n].name]=e[n].options,s.push(e[n].name));else if(e)for(r in e)e.hasOwnProperty(r)&&(o.plugins.settings[r]=e[r],s.push(r));for(;s.length;)o.require(s.shift())},e.prototype.loadPlugin=function(t){var n=this,i=n.plugins,r=e.plugins[t];if(!e.plugins.hasOwnProperty(t))throw Error('Unable to find "'+t+'" plugin');i.requested[t]=!0,i.loaded[t]=r.fn.apply(n,[n.plugins.settings[t]||{}]),i.names.push(t)},e.prototype.require=function(e){var t=this,n=t.plugins;if(!t.plugins.loaded.hasOwnProperty(e)){if(n.requested[e])throw Error('Plugin has circular dependency ("'+e+'")');t.loadPlugin(e)}return n.loaded[e]},e.define=function(t,n){e.plugins[t]={name:t,fn:n}}};var t={isArray:Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}};return e}),function(e,t){"function"==typeof define&&define.amd?define("selectize",["jquery","sifter","microplugin"],t):"object"==typeof exports?module.exports=t(require("jquery"),require("sifter"),require("microplugin")):e.Selectize=t(e.jQuery,e.Sifter,e.MicroPlugin)}(this,function(e,t,n){"use strict";var i=function(e,t){if("string"!=typeof t||t.length){var n="string"==typeof t?RegExp(t,"i"):t,i=function(e){var t=0;if(3===e.nodeType){var r=e.data.search(n);if(r>=0&&e.data.length>0){var o=e.data.match(n),s=document.createElement("span");s.className="highlight";var a=e.splitText(r),l=(a.splitText(o[0].length),a.cloneNode(!0));s.appendChild(l),a.parentNode.replaceChild(s,a),t=1}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName))for(var u=0;u<e.childNodes.length;++u)u+=i(e.childNodes[u]);return t};return e.each(function(){i(this)})}},r=function(){};r.prototype={on:function(e,t){this._events=this._events||{},this._events[e]=this._events[e]||[],this._events[e].push(t)},off:function(e,t){var n=arguments.length;return 0===n?delete this._events:1===n?delete this._events[e]:(this._events=this._events||{},void(e in this._events!=!1&&this._events[e].splice(this._events[e].indexOf(t),1)))},trigger:function(e){if(this._events=this._events||{},e in this._events!=!1)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}},r.mixin=function(e){for(var t=["on","off","trigger"],n=0;n<t.length;n++)e.prototype[t[n]]=r.prototype[t[n]]};var o=/Mac/.test(navigator.userAgent),s=65,a=13,l=27,u=37,c=38,p=80,d=39,h=40,f=78,g=8,v=46,m=16,y=o?91:17,w=o?18:17,O=9,$=1,C=2,b=!/android/i.test(window.navigator.userAgent)&&!!document.createElement("form").validity,x=function(e){return void 0!==e},S=function(e){return void 0===e||null===e?null:"boolean"==typeof e?e?"1":"0":e+""},I=function(e){return(e+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},_=function(e){return(e+"").replace(/\$/g,"$$$$")},A={};A.before=function(e,t,n){var i=e[t];e[t]=function(){return n.apply(e,arguments),i.apply(e,arguments)}},A.after=function(e,t,n){var i=e[t];e[t]=function(){var t=i.apply(e,arguments);return n.apply(e,arguments),t}};var F=function(e){var t=!1;return function(){t||(t=!0,e.apply(this,arguments))}},D=function(e,t){var n;return function(){var i=this,r=arguments;window.clearTimeout(n),n=window.setTimeout(function(){e.apply(i,r)},t)}},k=function(e,t,n){var i,r=e.trigger,o={};e.trigger=function(){var n=arguments[0];return-1===t.indexOf(n)?r.apply(e,arguments):void(o[n]=arguments)},n.apply(e,[]),e.trigger=r;for(i in o)o.hasOwnProperty(i)&&r.apply(e,o[i])},P=function(e,t,n,i){e.on(t,n,function(t){for(var n=t.target;n&&n.parentNode!==e[0];)n=n.parentNode;return t.currentTarget=n,i.apply(this,[t])})},z=function(e){var t={};if("selectionStart"in e)t.start=e.selectionStart,t.length=e.selectionEnd-t.start;else if(document.selection){e.focus();var n=document.selection.createRange(),i=document.selection.createRange().text.length;n.moveStart("character",-e.value.length),t.start=n.text.length-i,t.length=i}return t},T=function(e,t,n){var i,r,o={};if(n)for(i=0,r=n.length;r>i;i++)o[n[i]]=e.css(n[i]);else o=e.css();t.css(o)},q=function(t,n){if(!t)return 0;var i=e("<test>").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).text(t).appendTo("body");T(n,i,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var r=i.width();return i.remove(),r},j=function(e){var t=null,n=function(n,i){var r,o,s,a,l,u,c,p;n=n||window.event||{},i=i||{},n.metaKey||n.altKey||(i.force||e.data("grow")!==!1)&&(r=e.val(),n.type&&"keydown"===n.type.toLowerCase()&&(o=n.keyCode,s=o>=97&&122>=o||o>=65&&90>=o||o>=48&&57>=o||32===o,o===v||o===g?(p=z(e[0]),p.length?r=r.substring(0,p.start)+r.substring(p.start+p.length):o===g&&p.start?r=r.substring(0,p.start-1)+r.substring(p.start+1):o===v&&void 0!==p.start&&(r=r.substring(0,p.start)+r.substring(p.start+1))):s&&(u=n.shiftKey,c=String.fromCharCode(n.keyCode),c=u?c.toUpperCase():c.toLowerCase(),r+=c)),a=e.attr("placeholder"),!r&&a&&(r=a),l=q(r,e)+4,l!==t&&(t=l,e.width(l),e.triggerHandler("resize")))};e.on("keydown keyup update blur",n),n()},L=function(n,i){var r,o,s,a,l=this;a=n[0],a.selectize=l;var u=window.getComputedStyle&&window.getComputedStyle(a,null);if(s=u?u.getPropertyValue("direction"):a.currentStyle&&a.currentStyle.direction,s=s||n.parents("[dir]:first").attr("dir")||"",e.extend(l,{order:0,settings:i,$input:n,tabIndex:n.attr("tabindex")||"",tagType:"select"===a.tagName.toLowerCase()?$:C,rtl:/rtl/i.test(s),eventNS:".selectize"+ ++L.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isRequired:n.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===i.loadThrottle?l.onSearchChange:D(l.onSearchChange,i.loadThrottle)}),l.sifter=new t(this.options,{diacritics:i.diacritics}),l.settings.options){for(r=0,o=l.settings.options.length;o>r;r++)l.registerOption(l.settings.options[r]);delete l.settings.options}if(l.settings.optgroups){for(r=0,o=l.settings.optgroups.length;o>r;r++)l.registerOptionGroup(l.settings.optgroups[r]);delete l.settings.optgroups}l.settings.mode=l.settings.mode||(1===l.settings.maxItems?"single":"multi"),"boolean"!=typeof l.settings.hideSelected&&(l.settings.hideSelected="multi"===l.settings.mode),l.initializePlugins(l.settings.plugins),l.setupCallbacks(),l.setupTemplates(),l.setup()};return r.mixin(L),n.mixin(L),e.extend(L.prototype,{setup:function(){var t,n,i,r,s,a,l,u,c,p=this,d=p.settings,h=p.eventNS,f=e(window),g=e(document),v=p.$input;if(l=p.settings.mode,u=v.attr("class")||"",t=e("<div>").addClass(d.wrapperClass).addClass(u).addClass(l),n=e("<div>").addClass(d.inputClass).addClass("items").appendTo(t),i=e('<input type="text" autocomplete="off" />').appendTo(n).attr("tabindex",v.is(":disabled")?"-1":p.tabIndex),a=e(d.dropdownParent||t),r=e("<div>").addClass(d.dropdownClass).addClass(l).hide().appendTo(a),s=e("<div>").addClass(d.dropdownContentClass).appendTo(r),p.settings.copyClassesToDropdown&&r.addClass(u),t.css({width:v[0].style.width}),p.plugins.names.length&&(c="plugin-"+p.plugins.names.join(" plugin-"),t.addClass(c),r.addClass(c)),null!==d.maxItems&&d.maxItems<=1||p.tagType!==$||v.attr("multiple","multiple"),p.settings.placeholder&&i.attr("placeholder",d.placeholder),!p.settings.splitOn&&p.settings.delimiter){var O=p.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");p.settings.splitOn=RegExp("\\s*"+O+"+\\s*")}v.attr("autocorrect")&&i.attr("autocorrect",v.attr("autocorrect")),v.attr("autocapitalize")&&i.attr("autocapitalize",v.attr("autocapitalize")),p.$wrapper=t,p.$control=n,p.$control_input=i,p.$dropdown=r,p.$dropdown_content=s,r.on("mouseenter","[data-selectable]",function(){return p.onOptionHover.apply(p,arguments)}),r.on("mousedown click","[data-selectable]",function(){return p.onOptionSelect.apply(p,arguments)}),P(n,"mousedown","*:not(input)",function(){return p.onItemSelect.apply(p,arguments)}),j(i),n.on({mousedown:function(){return p.onMouseDown.apply(p,arguments)},click:function(){return p.onClick.apply(p,arguments)}}),i.on({mousedown:function(e){e.stopPropagation()},keydown:function(){return p.onKeyDown.apply(p,arguments)},keyup:function(){return p.onKeyUp.apply(p,arguments)},keypress:function(){return p.onKeyPress.apply(p,arguments)},resize:function(){p.positionDropdown.apply(p,[])},blur:function(){return p.onBlur.apply(p,arguments)},focus:function(){return p.ignoreBlur=!1,p.onFocus.apply(p,arguments)},paste:function(){return p.onPaste.apply(p,arguments)}}),g.on("keydown"+h,function(e){p.isCmdDown=e[o?"metaKey":"ctrlKey"],p.isCtrlDown=e[o?"altKey":"ctrlKey"],p.isShiftDown=e.shiftKey}),g.on("keyup"+h,function(e){e.keyCode===w&&(p.isCtrlDown=!1),e.keyCode===m&&(p.isShiftDown=!1),e.keyCode===y&&(p.isCmdDown=!1)}),g.on("mousedown"+h,function(e){if(p.isFocused){if(e.target===p.$dropdown[0]||e.target.parentNode===p.$dropdown[0])return!1;p.$control.has(e.target).length||e.target===p.$control[0]||p.blur(e.target)}}),f.on(["scroll"+h,"resize"+h].join(" "),function(){p.isOpen&&p.positionDropdown.apply(p,arguments)}),f.on("mousemove"+h,function(){p.ignoreHover=!1}),this.revertSettings={$children:v.children().detach(),tabindex:v.attr("tabindex")},v.attr("tabindex",-1).hide().after(p.$wrapper),e.isArray(d.items)&&(p.setValue(d.items),delete d.items),b&&v.on("invalid"+h,function(e){e.preventDefault(),p.isInvalid=!0,p.refreshState()}),p.updateOriginalInput(),p.refreshItems(),p.refreshState(),p.updatePlaceholder(),p.isSetup=!0,v.is(":disabled")&&p.disable(),p.on("change",this.onChange),v.data("selectize",p),v.addClass("selectized"),p.trigger("initialize"),d.preload===!0&&p.onSearchChange("")},setupTemplates:function(){var t=this,n=t.settings.labelField,i=t.settings.optgroupLabelField,r={optgroup:function(e){return'<div class="optgroup">'+e.html+"</div>"},optgroup_header:function(e,t){return'<div class="optgroup-header">'+t(e[i])+"</div>"},option:function(e,t){return'<div class="option">'+t(e[n])+"</div>"},item:function(e,t){return'<div class="item">'+t(e[n])+"</div>"},option_create:function(e,t){return'<div class="create">Add <strong>'+t(e.input)+"</strong>…</div>"}};t.settings.render=e.extend({},r,t.settings.render)},setupCallbacks:function(){var e,t,n={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(e in n)n.hasOwnProperty(e)&&(t=this.settings[n[e]],t&&this.on(e,t))},onClick:function(e){var t=this;t.isFocused||(t.focus(),e.preventDefault())},onMouseDown:function(t){{var n=this,i=t.isDefaultPrevented();e(t.target)}if(n.isFocused){if(t.target!==n.$control_input[0])return"single"===n.settings.mode?n.isOpen?n.close():n.open():i||n.setActiveItem(null),!1}else i||window.setTimeout(function(){n.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(t){var n=this;n.isFull()||n.isInputHidden||n.isLocked?t.preventDefault():n.settings.splitOn&&setTimeout(function(){for(var t=e.trim(n.$control_input.val()||"").split(n.settings.splitOn),i=0,r=t.length;r>i;i++)n.createItem(t[i])},0)},onKeyPress:function(e){if(this.isLocked)return e&&e.preventDefault();var t=String.fromCharCode(e.keyCode||e.which);return this.settings.create&&"multi"===this.settings.mode&&t===this.settings.delimiter?(this.createItem(),e.preventDefault(),!1):void 0},onKeyDown:function(e){var t=(e.target===this.$control_input[0],this);if(t.isLocked)return void(e.keyCode!==O&&e.preventDefault());switch(e.keyCode){case s:if(t.isCmdDown)return void t.selectAll();break;case l:return void(t.isOpen&&(e.preventDefault(),e.stopPropagation(),t.close()));case f:if(!e.ctrlKey||e.altKey)break;case h:if(!t.isOpen&&t.hasOptions)t.open();else if(t.$activeOption){t.ignoreHover=!0;var n=t.getAdjacentOption(t.$activeOption,1);n.length&&t.setActiveOption(n,!0,!0)}return void e.preventDefault();case p:if(!e.ctrlKey||e.altKey)break;case c:if(t.$activeOption){t.ignoreHover=!0;var i=t.getAdjacentOption(t.$activeOption,-1);i.length&&t.setActiveOption(i,!0,!0)}return void e.preventDefault();case a:return void(t.isOpen&&t.$activeOption&&(t.onOptionSelect({currentTarget:t.$activeOption}),e.preventDefault()));case u:return void t.advanceSelection(-1,e);case d:return void t.advanceSelection(1,e);case O:return t.settings.selectOnTab&&t.isOpen&&t.$activeOption&&(t.onOptionSelect({currentTarget:t.$activeOption}),t.isFull()||e.preventDefault()),void(t.settings.create&&t.createItem()&&e.preventDefault());case g:case v:return void t.deleteSelection(e)}return!t.isFull()&&!t.isInputHidden||(o?e.metaKey:e.ctrlKey)?void 0:void e.preventDefault()},onKeyUp:function(e){var t=this;if(t.isLocked)return e&&e.preventDefault();var n=t.$control_input.val()||"";t.lastValue!==n&&(t.lastValue=n,t.onSearchChange(n),t.refreshOptions(),t.trigger("type",n))},onSearchChange:function(e){var t=this,n=t.settings.load;n&&(t.loadedSearches.hasOwnProperty(e)||(t.loadedSearches[e]=!0,t.load(function(i){n.apply(t,[e,i])})))},onFocus:function(e){var t=this,n=t.isFocused;return t.isDisabled?(t.blur(),e&&e.preventDefault(),!1):void(t.ignoreFocus||(t.isFocused=!0,"focus"===t.settings.preload&&t.onSearchChange(""),n||t.trigger("focus"),t.$activeItems.length||(t.showInput(),t.setActiveItem(null),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState()))},onBlur:function(e,t){var n=this;if(n.isFocused&&(n.isFocused=!1,!n.ignoreFocus)){if(!n.ignoreBlur&&document.activeElement===n.$dropdown_content[0])return n.ignoreBlur=!0,void n.onFocus(e);var i=function(){n.close(),n.setTextboxValue(""),n.setActiveItem(null),n.setActiveOption(null),n.setCaret(n.items.length),n.refreshState(),(t||document.body).focus(),n.ignoreFocus=!1,n.trigger("blur")};n.ignoreFocus=!0,n.settings.create&&n.settings.createOnBlur?n.createItem(null,!1,i):i()}},onOptionHover:function(e){this.ignoreHover||this.setActiveOption(e.currentTarget,!1)},onOptionSelect:function(t){var n,i,r=this;t.preventDefault&&(t.preventDefault(),t.stopPropagation()),i=e(t.currentTarget),i.hasClass("create")?r.createItem(null,function(){r.settings.closeAfterSelect&&r.close()}):(n=i.attr("data-value"),void 0!==n&&(r.lastQuery=null,r.setTextboxValue(""),r.addItem(n),r.settings.closeAfterSelect?r.close():!r.settings.hideSelected&&t.type&&/mouse/.test(t.type)&&r.setActiveOption(r.getOption(n))))},onItemSelect:function(e){var t=this;t.isLocked||"multi"===t.settings.mode&&(e.preventDefault(),t.setActiveItem(e.currentTarget,e))},load:function(e){var t=this,n=t.$wrapper.addClass(t.settings.loadingClass);t.loading++,e.apply(t,[function(e){t.loading=Math.max(t.loading-1,0),e&&e.length&&(t.addOption(e),t.refreshOptions(t.isFocused&&!t.isInputHidden)),t.loading||n.removeClass(t.settings.loadingClass),t.trigger("load",e)}])},setTextboxValue:function(e){var t=this.$control_input,n=t.val()!==e;n&&(t.val(e).triggerHandler("update"),this.lastValue=e)},getValue:function(){return this.tagType===$&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(e,t){var n=t?[]:["change"];k(this,n,function(){this.clear(t),this.addItems(e,t)})},setActiveItem:function(t,n){var i,r,o,s,a,l,u,c,p=this;if("single"!==p.settings.mode){if(t=e(t),!t.length)return e(p.$activeItems).removeClass("active"),p.$activeItems=[],void(p.isFocused&&p.showInput());if(i=n&&n.type.toLowerCase(),"mousedown"===i&&p.isShiftDown&&p.$activeItems.length){for(c=p.$control.children(".active:last"),s=Array.prototype.indexOf.apply(p.$control[0].childNodes,[c[0]]),a=Array.prototype.indexOf.apply(p.$control[0].childNodes,[t[0]]),s>a&&(u=s,s=a,a=u),r=s;a>=r;r++)l=p.$control[0].childNodes[r],-1===p.$activeItems.indexOf(l)&&(e(l).addClass("active"),p.$activeItems.push(l));n.preventDefault()}else"mousedown"===i&&p.isCtrlDown||"keydown"===i&&this.isShiftDown?t.hasClass("active")?(o=p.$activeItems.indexOf(t[0]),p.$activeItems.splice(o,1),t.removeClass("active")):p.$activeItems.push(t.addClass("active")[0]):(e(p.$activeItems).removeClass("active"),p.$activeItems=[t.addClass("active")[0]]);p.hideInput(),this.isFocused||p.focus()}},setActiveOption:function(t,n,i){var r,o,s,a,l,u=this;u.$activeOption&&u.$activeOption.removeClass("active"),u.$activeOption=null,t=e(t),t.length&&(u.$activeOption=t.addClass("active"),(n||!x(n))&&(r=u.$dropdown_content.height(),o=u.$activeOption.outerHeight(!0),n=u.$dropdown_content.scrollTop()||0,s=u.$activeOption.offset().top-u.$dropdown_content.offset().top+n,a=s,l=s-r+o,s+o>r+n?u.$dropdown_content.stop().animate({scrollTop:l},i?u.settings.scrollDuration:0):n>s&&u.$dropdown_content.stop().animate({scrollTop:a},i?u.settings.scrollDuration:0)))},selectAll:function(){var e=this;"single"!==e.settings.mode&&(e.$activeItems=Array.prototype.slice.apply(e.$control.children(":not(input)").addClass("active")),e.$activeItems.length&&(e.hideInput(),e.close()),e.focus())},hideInput:function(){var e=this;e.setTextboxValue(""),e.$control_input.css({opacity:0,position:"absolute",left:e.rtl?1e4:-1e4}),e.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(){var e=this;e.isDisabled||(e.ignoreFocus=!0,e.$control_input[0].focus(),window.setTimeout(function(){e.ignoreFocus=!1,e.onFocus()},0))},blur:function(e){this.$control_input[0].blur(),this.onBlur(null,e)},getScoreFunction:function(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())},getSearchOptions:function(){var e=this.settings,t=e.sortField;return"string"==typeof t&&(t=[{field:t}]),{fields:e.searchField,conjunction:e.searchConjunction,sort:t}},search:function(t){var n,i,r,o=this,s=o.settings,a=this.getSearchOptions();if(s.score&&(r=o.settings.score.apply(this,[t]),"function"!=typeof r))throw Error('Selectize "score" setting must be a function that returns a function');if(t!==o.lastQuery?(o.lastQuery=t,i=o.sifter.search(t,e.extend(a,{score:r})),o.currentResults=i):i=e.extend(!0,{},o.currentResults),s.hideSelected)for(n=i.items.length-1;n>=0;n--)-1!==o.items.indexOf(S(i.items[n].id))&&i.items.splice(n,1);return i},refreshOptions:function(t){var n,r,o,s,a,l,u,c,p,d,h,f,g,v,m,y;void 0===t&&(t=!0);var w=this,O=e.trim(w.$control_input.val()),$=w.search(O),C=w.$dropdown_content,b=w.$activeOption&&S(w.$activeOption.attr("data-value"));for(s=$.items.length,"number"==typeof w.settings.maxOptions&&(s=Math.min(s,w.settings.maxOptions)),a={},l=[],n=0;s>n;n++)for(u=w.options[$.items[n].id],c=w.render("option",u),p=u[w.settings.optgroupField]||"",d=e.isArray(p)?p:[p],r=0,o=d&&d.length;o>r;r++)p=d[r],w.optgroups.hasOwnProperty(p)||(p=""),a.hasOwnProperty(p)||(a[p]=[],l.push(p)),a[p].push(c);for(this.settings.lockOptgroupOrder&&l.sort(function(e,t){var n=w.optgroups[e].$order||0,i=w.optgroups[t].$order||0;return n-i}),h=[],n=0,s=l.length;s>n;n++)p=l[n],w.optgroups.hasOwnProperty(p)&&a[p].length?(f=w.render("optgroup_header",w.optgroups[p])||"",f+=a[p].join(""),h.push(w.render("optgroup",e.extend({},w.optgroups[p],{html:f})))):h.push(a[p].join(""));if(C.html(h.join("")),w.settings.highlight&&$.query.length&&$.tokens.length)for(n=0,s=$.tokens.length;s>n;n++)i(C,$.tokens[n].regex);if(!w.settings.hideSelected)for(n=0,s=w.items.length;s>n;n++)w.getOption(w.items[n]).addClass("selected");g=w.canCreate(O),g&&(C.prepend(w.render("option_create",{input:O})),y=e(C[0].childNodes[0])),w.hasOptions=$.items.length>0||g,w.hasOptions?($.items.length>0?(m=b&&w.getOption(b),m&&m.length?v=m:"single"===w.settings.mode&&w.items.length&&(v=w.getOption(w.items[0])),v&&v.length||(v=y&&!w.settings.addPrecedence?w.getAdjacentOption(y,1):C.find("[data-selectable]:first"))):v=y,w.setActiveOption(v),t&&!w.isOpen&&w.open()):(w.setActiveOption(null),t&&w.isOpen&&w.close())},addOption:function(t){var n,i,r,o=this;if(e.isArray(t))for(n=0,i=t.length;i>n;n++)o.addOption(t[n]);else(r=o.registerOption(t))&&(o.userOptions[r]=!0,o.lastQuery=null,o.trigger("option_add",r,t))},registerOption:function(e){var t=S(e[this.settings.valueField]);return!t||this.options.hasOwnProperty(t)?!1:(e.$order=e.$order||++this.order,this.options[t]=e,t)},registerOptionGroup:function(e){var t=S(e[this.settings.optgroupValueField]);return t?(e.$order=e.$order||++this.order,this.optgroups[t]=e,t):!1},addOptionGroup:function(e,t){t[this.settings.optgroupValueField]=e,(e=this.registerOptionGroup(t))&&this.trigger("optgroup_add",e,t)},removeOptionGroup:function(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.renderCache={},this.trigger("optgroup_remove",e))},clearOptionGroups:function(){this.optgroups={},this.renderCache={},this.trigger("optgroup_clear")},updateOption:function(t,n){var i,r,o,s,a,l,u,c=this;if(t=S(t),o=S(n[c.settings.valueField]),null!==t&&c.options.hasOwnProperty(t)){if("string"!=typeof o)throw Error("Value must be set in option data");u=c.options[t].$order,o!==t&&(delete c.options[t],s=c.items.indexOf(t),-1!==s&&c.items.splice(s,1,o)),n.$order=n.$order||u,c.options[o]=n,a=c.renderCache.item,l=c.renderCache.option,a&&(delete a[t],delete a[o]),l&&(delete l[t],delete l[o]),-1!==c.items.indexOf(o)&&(i=c.getItem(t),r=e(c.render("item",n)),i.hasClass("active")&&r.addClass("active"),i.replaceWith(r)),c.lastQuery=null,c.isOpen&&c.refreshOptions(!1)}},removeOption:function(e,t){var n=this;e=S(e);var i=n.renderCache.item,r=n.renderCache.option;i&&delete i[e],r&&delete r[e],delete n.userOptions[e],delete n.options[e],n.lastQuery=null,n.trigger("option_remove",e),n.removeItem(e,t)},clearOptions:function(){var e=this;e.loadedSearches={},e.userOptions={},e.renderCache={},e.options=e.sifter.items={},e.lastQuery=null,e.trigger("option_clear"),e.clear()},getOption:function(e){return this.getElementWithValue(e,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(t,n){var i=this.$dropdown.find("[data-selectable]"),r=i.index(t)+n;return r>=0&&r<i.length?i.eq(r):e()},getElementWithValue:function(t,n){if(t=S(t),void 0!==t&&null!==t)for(var i=0,r=n.length;r>i;i++)if(n[i].getAttribute("data-value")===t)return e(n[i]);return e()},getItem:function(e){return this.getElementWithValue(e,this.$control.children())},addItems:function(t,n){for(var i=e.isArray(t)?t:[t],r=0,o=i.length;o>r;r++)this.isPending=o-1>r,this.addItem(i[r],n)},addItem:function(t,n){var i=n?[]:["change"];k(this,i,function(){var i,r,o,s,a,l=this,u=l.settings.mode;return t=S(t),-1!==l.items.indexOf(t)?void("single"===u&&l.close()):void(l.options.hasOwnProperty(t)&&("single"===u&&l.clear(n),"multi"===u&&l.isFull()||(i=e(l.render("item",l.options[t])),a=l.isFull(),l.items.splice(l.caretPos,0,t),l.insertAtCaret(i),(!l.isPending||!a&&l.isFull())&&l.refreshState(),l.isSetup&&(o=l.$dropdown_content.find("[data-selectable]"),l.isPending||(r=l.getOption(t),s=l.getAdjacentOption(r,1).attr("data-value"),l.refreshOptions(l.isFocused&&"single"!==u),s&&l.setActiveOption(l.getOption(s))),!o.length||l.isFull()?l.close():l.positionDropdown(),l.updatePlaceholder(),l.trigger("item_add",t,i),l.updateOriginalInput({silent:n})))))})},removeItem:function(e,t){var n,i,r,o=this;n="object"==typeof e?e:o.getItem(e),e=S(n.attr("data-value")),i=o.items.indexOf(e),-1!==i&&(n.remove(),n.hasClass("active")&&(r=o.$activeItems.indexOf(n[0]),o.$activeItems.splice(r,1)),o.items.splice(i,1),o.lastQuery=null,!o.settings.persist&&o.userOptions.hasOwnProperty(e)&&o.removeOption(e,t),i<o.caretPos&&o.setCaret(o.caretPos-1),o.refreshState(),o.updatePlaceholder(),o.updateOriginalInput({silent:t}),o.positionDropdown(),o.trigger("item_remove",e,n))},createItem:function(t,n){var i=this,r=i.caretPos;t=t||e.trim(i.$control_input.val()||"");var o=arguments[arguments.length-1];if("function"!=typeof o&&(o=function(){}),"boolean"!=typeof n&&(n=!0),!i.canCreate(t))return o(),!1;i.lock();var s="function"==typeof i.settings.create?this.settings.create:function(e){var t={};return t[i.settings.labelField]=e,t[i.settings.valueField]=e,t},a=F(function(e){if(i.unlock(),!e||"object"!=typeof e)return o();var t=S(e[i.settings.valueField]);return"string"!=typeof t?o():(i.setTextboxValue(""),i.addOption(e),i.setCaret(r),i.addItem(t),i.refreshOptions(n&&"single"!==i.settings.mode),void o(e))}),l=s.apply(this,[t,a]);return void 0!==l&&a(l),!0},refreshItems:function(){this.lastQuery=null,this.isSetup&&this.addItem(this.items),this.refreshState(),this.updateOriginalInput()},refreshState:function(){var e,t=this;t.isRequired&&(t.items.length&&(t.isInvalid=!1),t.$control_input.prop("required",e)),t.refreshClasses()},refreshClasses:function(){var t=this,n=t.isFull(),i=t.isLocked;t.$wrapper.toggleClass("rtl",t.rtl),t.$control.toggleClass("focus",t.isFocused).toggleClass("disabled",t.isDisabled).toggleClass("required",t.isRequired).toggleClass("invalid",t.isInvalid).toggleClass("locked",i).toggleClass("full",n).toggleClass("not-full",!n).toggleClass("input-active",t.isFocused&&!t.isInputHidden).toggleClass("dropdown-active",t.isOpen).toggleClass("has-options",!e.isEmptyObject(t.options)).toggleClass("has-items",t.items.length>0),t.$control_input.data("grow",!n&&!i)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(e){var t,n,i,r,o=this;if(e=e||{},o.tagType===$){for(i=[],t=0,n=o.items.length;n>t;t++)r=o.options[o.items[t]][o.settings.labelField]||"",i.push('<option value="'+I(o.items[t])+'" selected="selected">'+I(r)+"</option>");i.length||this.$input.attr("multiple")||i.push('<option value="" selected="selected"></option>'),o.$input.html(i.join(""))}else o.$input.val(o.getValue()),o.$input.attr("value",o.$input.val());o.isSetup&&(e.silent||o.trigger("change",o.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var e=this.$control_input;this.items.length?e.removeAttr("placeholder"):e.attr("placeholder",this.settings.placeholder),e.triggerHandler("update",{force:!0})}},open:function(){var e=this;e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull()||(e.focus(),e.isOpen=!0,e.refreshState(),e.$dropdown.css({visibility:"hidden",display:"block"}),e.positionDropdown(),e.$dropdown.css({visibility:"visible"}),e.trigger("dropdown_open",e.$dropdown))},close:function(){var e=this,t=e.isOpen;"single"===e.settings.mode&&e.items.length&&e.hideInput(),e.isOpen=!1,e.$dropdown.hide(),e.setActiveOption(null),e.refreshState(),t&&e.trigger("dropdown_close",e.$dropdown)},positionDropdown:function(){var e=this.$control,t="body"===this.settings.dropdownParent?e.offset():e.position();t.top+=e.outerHeight(!0),this.$dropdown.css({width:e.outerWidth(),top:t.top,left:t.left})},clear:function(e){var t=this;t.items.length&&(t.$control.children(":not(input)").remove(),t.items=[],t.lastQuery=null,t.setCaret(0),t.setActiveItem(null),t.updatePlaceholder(),t.updateOriginalInput({silent:e}),t.refreshState(),t.showInput(),t.trigger("clear"))},insertAtCaret:function(t){var n=Math.min(this.caretPos,this.items.length);0===n?this.$control.prepend(t):e(this.$control[0].childNodes[n]).before(t),this.setCaret(n+1)},deleteSelection:function(t){var n,i,r,o,s,a,l,u,c,p=this;if(r=t&&t.keyCode===g?-1:1,o=z(p.$control_input[0]),p.$activeOption&&!p.settings.hideSelected&&(l=p.getAdjacentOption(p.$activeOption,-1).attr("data-value")),s=[],p.$activeItems.length){for(c=p.$control.children(".active:"+(r>0?"last":"first")),a=p.$control.children(":not(input)").index(c),r>0&&a++,n=0,i=p.$activeItems.length;i>n;n++)s.push(e(p.$activeItems[n]).attr("data-value"));
t&&(t.preventDefault(),t.stopPropagation())}else(p.isFocused||"single"===p.settings.mode)&&p.items.length&&(0>r&&0===o.start&&0===o.length?s.push(p.items[p.caretPos-1]):r>0&&o.start===p.$control_input.val().length&&s.push(p.items[p.caretPos]));if(!s.length||"function"==typeof p.settings.onDelete&&p.settings.onDelete.apply(p,[s])===!1)return!1;for(void 0!==a&&p.setCaret(a);s.length;)p.removeItem(s.pop());return p.showInput(),p.positionDropdown(),p.refreshOptions(!0),l&&(u=p.getOption(l),u.length&&p.setActiveOption(u)),!0},advanceSelection:function(e,t){var n,i,r,o,s,a,l=this;0!==e&&(l.rtl&&(e*=-1),n=e>0?"last":"first",i=z(l.$control_input[0]),l.isFocused&&!l.isInputHidden?(o=l.$control_input.val().length,s=0>e?0===i.start&&0===i.length:i.start===o,s&&!o&&l.advanceCaret(e,t)):(a=l.$control.children(".active:"+n),a.length&&(r=l.$control.children(":not(input)").index(a),l.setActiveItem(null),l.setCaret(e>0?r+1:r))))},advanceCaret:function(e,t){var n,i,r=this;0!==e&&(n=e>0?"next":"prev",r.isShiftDown?(i=r.$control_input[n](),i.length&&(r.hideInput(),r.setActiveItem(i),t&&t.preventDefault())):r.setCaret(r.caretPos+e))},setCaret:function(t){var n=this;if(t="single"===n.settings.mode?n.items.length:Math.max(0,Math.min(n.items.length,t)),!n.isPending){var i,r,o,s;for(o=n.$control.children(":not(input)"),i=0,r=o.length;r>i;i++)s=e(o[i]).detach(),t>i?n.$control_input.before(s):n.$control.append(s)}n.caretPos=t},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var e=this;e.$input.prop("disabled",!0),e.$control_input.prop("disabled",!0).prop("tabindex",-1),e.isDisabled=!0,e.lock()},enable:function(){var e=this;e.$input.prop("disabled",!1),e.$control_input.prop("disabled",!1).prop("tabindex",e.tabIndex),e.isDisabled=!1,e.unlock()},destroy:function(){var t=this,n=t.eventNS,i=t.revertSettings;t.trigger("destroy"),t.off(),t.$wrapper.remove(),t.$dropdown.remove(),t.$input.html("").append(i.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:i.tabindex}).show(),t.$control_input.removeData("grow"),t.$input.removeData("selectize"),e(window).off(n),e(document).off(n),e(document.body).off(n),delete t.$input[0].selectize},render:function(e,t){var n,i,r="",o=!1,s=this,a=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return("option"===e||"item"===e)&&(n=S(t[s.settings.valueField]),o=!!n),o&&(x(s.renderCache[e])||(s.renderCache[e]={}),s.renderCache[e].hasOwnProperty(n))?s.renderCache[e][n]:(r=s.settings.render[e].apply(this,[t,I]),("option"===e||"option_create"===e)&&(r=r.replace(a,"<$1 data-selectable")),"optgroup"===e&&(i=t[s.settings.optgroupValueField]||"",r=r.replace(a,'<$1 data-group="'+_(I(i))+'"')),("option"===e||"item"===e)&&(r=r.replace(a,'<$1 data-value="'+_(I(n||""))+'"')),o&&(s.renderCache[e][n]=r),r)},clearCache:function(e){var t=this;void 0===e?t.renderCache={}:delete t.renderCache[e]},canCreate:function(e){var t=this;if(!t.settings.create)return!1;var n=t.settings.createFilter;return!(!e.length||"function"==typeof n&&!n.apply(t,[e])||"string"==typeof n&&!RegExp(n).test(e)||n instanceof RegExp&&!n.test(e))}}),L.count=0,L.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,copyClassesToDropdown:!0,render:{}},e.fn.selectize=function(t){var n=e.fn.selectize.defaults,i=e.extend({},n,t),r=i.dataAttr,o=i.labelField,s=i.valueField,a=i.optgroupField,l=i.optgroupLabelField,u=i.optgroupValueField,c=function(t,n){var a,l,u,c,p=t.attr(r);if(p)for(n.options=JSON.parse(p),a=0,l=n.options.length;l>a;a++)n.items.push(n.options[a][s]);else{var d=e.trim(t.val()||"");if(!i.allowEmptyOption&&!d.length)return;for(u=d.split(i.delimiter),a=0,l=u.length;l>a;a++)c={},c[o]=u[a],c[s]=u[a],n.options.push(c);n.items=u}},p=function(t,n){var c,p,d,h,f=n.options,g={},v=function(e){var t=r&&e.attr(r);return"string"==typeof t&&t.length?JSON.parse(t):null},m=function(t,r){t=e(t);var l=S(t.attr("value"));if(l||i.allowEmptyOption)if(g.hasOwnProperty(l)){if(r){var u=g[l][a];u?e.isArray(u)?u.push(r):g[l][a]=[u,r]:g[l][a]=r}}else{var c=v(t)||{};c[o]=c[o]||t.text(),c[s]=c[s]||l,c[a]=c[a]||r,g[l]=c,f.push(c),t.is(":selected")&&n.items.push(l)}},y=function(t){var i,r,o,s,a;for(t=e(t),o=t.attr("label"),o&&(s=v(t)||{},s[l]=o,s[u]=o,n.optgroups.push(s)),a=e("option",t),i=0,r=a.length;r>i;i++)m(a[i],o)};for(n.maxItems=t.attr("multiple")?null:1,h=t.children(),c=0,p=h.length;p>c;c++)d=h[c].tagName.toLowerCase(),"optgroup"===d?y(h[c]):"option"===d&&m(h[c])};return this.each(function(){if(!this.selectize){var r,o=e(this),s=this.tagName.toLowerCase(),a=o.attr("placeholder")||o.attr("data-placeholder");a||i.allowEmptyOption||(a=o.children('option[value=""]').text());var l={placeholder:a,options:[],optgroups:[],items:[]};"select"===s?p(o,l):c(o,l),r=new L(o,e.extend(!0,{},n,l,t))}})},e.fn.selectize.defaults=L.defaults,e.fn.selectize.support={validity:b},L.define("drag_drop",function(){if(!e.fn.sortable)throw Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var t=this;t.lock=function(){var e=t.lock;return function(){var n=t.$control.data("sortable");return n&&n.disable(),e.apply(t,arguments)}}(),t.unlock=function(){var e=t.unlock;return function(){var n=t.$control.data("sortable");return n&&n.enable(),e.apply(t,arguments)}}(),t.setup=function(){var n=t.setup;return function(){n.apply(this,arguments);var i=t.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:t.isLocked,start:function(e,t){t.placeholder.css("width",t.helper.css("width")),i.css({overflow:"visible"})},stop:function(){i.css({overflow:"hidden"});var n=t.$activeItems?t.$activeItems.slice():null,r=[];i.children("[data-value]").each(function(){r.push(e(this).attr("data-value"))}),t.setValue(r),t.setActiveItem(n)}})}}()}}),L.define("dropdown_header",function(t){var n=this;t=e.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(e){return'<div class="'+e.headerClass+'"><div class="'+e.titleRowClass+'"><span class="'+e.labelClass+'">'+e.title+'</span><a href="javascript:void(0)" class="'+e.closeClass+'">×</a></div></div>'}},t),n.setup=function(){var i=n.setup;return function(){i.apply(n,arguments),n.$dropdown_header=e(t.html(t)),n.$dropdown.prepend(n.$dropdown_header)}}()}),L.define("optgroup_columns",function(t){var n=this;t=e.extend({equalizeWidth:!0,equalizeHeight:!0},t),this.getAdjacentOption=function(t,n){var i=t.closest("[data-group]").find("[data-selectable]"),r=i.index(t)+n;return r>=0&&r<i.length?i.eq(r):e()},this.onKeyDown=function(){var e=n.onKeyDown;return function(t){var i,r,o,s;return!this.isOpen||t.keyCode!==u&&t.keyCode!==d?e.apply(this,arguments):(n.ignoreHover=!0,s=this.$activeOption.closest("[data-group]"),i=s.find("[data-selectable]").index(this.$activeOption),s=t.keyCode===u?s.prev("[data-group]"):s.next("[data-group]"),o=s.find("[data-selectable]"),r=o.eq(Math.min(o.length-1,i)),void(r.length&&this.setActiveOption(r)))}}();var i=function(){var e,t=i.width,n=document;return void 0===t&&(e=n.createElement("div"),e.innerHTML='<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>',e=e.firstChild,n.body.appendChild(e),t=i.width=e.offsetWidth-e.clientWidth,n.body.removeChild(e)),t},r=function(){var r,o,s,a,l,u,c;if(c=e("[data-group]",n.$dropdown_content),o=c.length,o&&n.$dropdown_content.width()){if(t.equalizeHeight){for(s=0,r=0;o>r;r++)s=Math.max(s,c.eq(r).height());c.css({height:s})}t.equalizeWidth&&(u=n.$dropdown_content.innerWidth()-i(),a=Math.round(u/o),c.css({width:a}),o>1&&(l=u-a*(o-1),c.eq(o-1).css({width:l})))}};(t.equalizeHeight||t.equalizeWidth)&&(A.after(this,"positionDropdown",r),A.after(this,"refreshOptions",r))}),L.define("remove_button",function(t){if("single"!==this.settings.mode){t=e.extend({label:"×",title:"Remove",className:"remove",append:!0},t);var n=this,i='<a href="javascript:void(0)" class="'+t.className+'" tabindex="-1" title="'+I(t.title)+'">'+t.label+"</a>",r=function(e,t){var n=e.search(/(<\/[^>]+>\s*)$/);return e.substring(0,n)+t+e.substring(n)};this.setup=function(){var o=n.setup;return function(){if(t.append){var s=n.settings.render.item;n.settings.render.item=function(){return r(s.apply(this,arguments),i)}}o.apply(this,arguments),this.$control.on("click","."+t.className,function(t){if(t.preventDefault(),!n.isLocked){var i=e(t.currentTarget).parent();n.setActiveItem(i),n.deleteSelection()&&n.setCaret(n.items.length)}})}}()}}),L.define("restore_on_backspace",function(e){var t=this;e.text=e.text||function(e){return e[this.settings.labelField]},this.onKeyDown=function(){var n=t.onKeyDown;return function(t){var i,r;if(t.keyCode===g&&""===this.$control_input.val()&&!this.$activeItems.length&&(i=this.caretPos-1,i>=0&&i<this.items.length)){if(r=this.options[this.items[i]],this.deleteSelection(t)){var o=e.text.apply(this,[r]);o.length>0&&(o=o.substring(0,o.length-1)),this.setTextboxValue(o),this.refreshOptions(!0),this.onSearchChange(o)}return void t.preventDefault()}return n.apply(this,arguments)}}()}),L});