(function(root,factory){if(typeof define==='function'&&define.amd){define('sifter',factory);}else if(typeof exports==='object'){module.exports=factory();}else{root.Sifter=factory();}}(this,function(){var Sifter=function(items,settings){this.items=items;this.settings=settings||{diacritics:true};};Sifter.prototype.tokenize=function(query){query=trim(String(query||'').toLowerCase());if(!query||!query.length)return[];var i,n,regex,letter;var tokens=[];var words=query.split(/ +/);for(i=0,n=words.length;i0){search.items.push({'score':score,'id':id});}});}else{self.iterator(self.items,function(item,id){search.items.push({'score':1,'id':id});});}fn_sort=self.getSortFunction(search,options);if(fn_sort)search.items.sort(fn_sort);search.total=search.items.length;if(typeof options.limit==='number'){search.items=search.items.slice(0,options.limit);}return search;};var cmp=function(a,b){if(typeof a==='number'&&typeof b==='number'){return a>b?1:(ab)return 1;if(b>a)return-1;return 0;};var extend=function(a,b){var i,n,k,object;for(i=1,n=arguments.length;i=0&&node.data.length>0){var match=node.data.match(regex);var spannode=document.createElement('span');spannode.className='highlight';var middlebit=node.splitText(pos);var endbit=middlebit.splitText(match[0].length);var middleclone=middlebit.cloneNode(true);spannode.appendChild(middleclone);middlebit.parentNode.replaceChild(spannode,middlebit);skip=1;}}else if(node.nodeType===1&&node.childNodes&&!/(script|style)/i.test(node.tagName)){for(var i=0;i/g,'>').replace(/"/g,'"');};var escape_replace=function(str){return(str+'').replace(/\$/g,'$$$$');};var hook={};hook.before=function(self,method,fn){var original=self[method];self[method]=function(){fn.apply(self,arguments);return original.apply(self,arguments);};};hook.after=function(self,method,fn){var original=self[method];self[method]=function(){var result=original.apply(self,arguments);fn.apply(self,arguments);return result;};};var build_hash_table=function(key,objects){if(!$.isArray(objects))return objects;var i,n,table={};for(i=0,n=objects.length;i').css({position:'absolute',top:-99999,left:-99999,width:'auto',padding:0,whiteSpace:'pre'}).text(str).appendTo('body');transferStyles($parent,$test,['letterSpacing','fontSize','fontFamily','fontWeight','textTransform']);var width=$test.width();$test.remove();return width;};var autoGrow=function($input){var update=function(e){var value,keyCode,printable,placeholder,width;var shift,character,selection;e=e||window.event||{};if(e.metaKey||e.altKey)return;if($input.data('grow')===false)return;value=$input.val();if(e.type&&e.type.toLowerCase()==='keydown'){keyCode=e.keyCode;printable=((keyCode>=97&&keyCode<=122)||(keyCode>=65&&keyCode<=90)||(keyCode>=48&&keyCode<=57)||keyCode===32);if(keyCode===KEY_DELETE||keyCode===KEY_BACKSPACE){selection=getSelection($input[0]);if(selection.length){value=value.substring(0,selection.start)+value.substring(selection.start+selection.length);}else if(keyCode===KEY_BACKSPACE&&selection.start){value=value.substring(0,selection.start-1)+value.substring(selection.start+1);}else if(keyCode===KEY_DELETE&&typeof selection.start!=='undefined'){value=value.substring(0,selection.start)+value.substring(selection.start+1);}}else if(printable){shift=e.shiftKey;character=String.fromCharCode(e.keyCode);if(shift)character=character.toUpperCase();else character=character.toLowerCase();value+=character;}}placeholder=$input.attr('placeholder')||'';if(!value.length&&placeholder.length){value=placeholder;}width=measureString(value,$input)+4;if(width!==$input.width()){$input.width(width);$input.triggerHandler('resize');}};$input.on('keydown keyup update blur',update);update();};var Selectize=function($input,settings){var key,i,n,dir,input,self=this;input=$input[0];input.selectize=self;dir=window.getComputedStyle?window.getComputedStyle(input,null).getPropertyValue('direction'):input.currentStyle&&input.currentStyle.direction;dir=dir||$input.parents('[dir]:first').attr('dir')||'';$.extend(self,{settings:settings,$input:$input,tagType:input.tagName.toLowerCase()==='select'?TAG_SELECT:TAG_INPUT,rtl:/rtl/i.test(dir),eventNS:'.selectize'+(++Selectize.count),highlightedValue:null,isOpen:false,isDisabled:false,isRequired:$input.is('[required]'),isInvalid:false,isLocked:false,isFocused:false,isInputHidden:false,isSetup:false,isShiftDown:false,isCmdDown:false,isCtrlDown:false,ignoreFocus:false,ignoreHover:false,hasOptions:false,currentResults:null,lastValue:'',caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:debounce(self.onSearchChange,settings.loadThrottle)});self.sifter=new Sifter(this.options,{diacritics:settings.diacritics});$.extend(self.options,build_hash_table(settings.valueField,settings.options));delete self.settings.options;$.extend(self.optgroups,build_hash_table(settings.optgroupValueField,settings.optgroups));delete self.settings.optgroups;self.settings.mode=self.settings.mode||(self.settings.maxItems===1?'single':'multi');if(typeof self.settings.hideSelected!=='boolean'){self.settings.hideSelected=self.settings.mode==='multi';}self.initializePlugins(self.settings.plugins);self.setupCallbacks();self.setupTemplates();self.setup();};MicroEvent.mixin(Selectize);MicroPlugin.mixin(Selectize);$.extend(Selectize.prototype,{setup:function(){var self=this;var settings=self.settings;var eventNS=self.eventNS;var $window=$(window);var $document=$(document);var $wrapper;var $control;var $control_input;var $dropdown;var $dropdown_content;var $dropdown_parent;var inputMode;var timeout_blur;var timeout_focus;var tab_index;var classes;var classes_plugins;inputMode=self.settings.mode;tab_index=self.$input.attr('tabindex')||'';classes=self.$input.attr('class')||'';$wrapper=$('
').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode);$control=$('
').addClass(settings.inputClass).addClass('items').appendTo($wrapper);$control_input=$('').appendTo($control).attr('tabindex',tab_index);$dropdown_parent=$(settings.dropdownParent||$wrapper);$dropdown=$('
').addClass(settings.dropdownClass).addClass(classes).addClass(inputMode).hide().appendTo($dropdown_parent);$dropdown_content=$('
').addClass(settings.dropdownContentClass).appendTo($dropdown);$wrapper.css({width:self.$input[0].style.width});if(self.plugins.names.length){classes_plugins='plugin-'+self.plugins.names.join(' plugin-');$wrapper.addClass(classes_plugins);$dropdown.addClass(classes_plugins);}if((settings.maxItems===null||settings.maxItems>1)&&self.tagType===TAG_SELECT){self.$input.attr('multiple','multiple');}if(self.settings.placeholder){$control_input.attr('placeholder',settings.placeholder);}self.$wrapper=$wrapper;self.$control=$control;self.$control_input=$control_input;self.$dropdown=$dropdown;self.$dropdown_content=$dropdown_content;$dropdown.on('mouseenter','[data-selectable]',function(){return self.onOptionHover.apply(self,arguments);});$dropdown.on('mousedown','[data-selectable]',function(){return self.onOptionSelect.apply(self,arguments);});watchChildEvent($control,'mousedown','*:not(input)',function(){return self.onItemSelect.apply(self,arguments);});autoGrow($control_input);$control.on({mousedown:function(){return self.onMouseDown.apply(self,arguments);},click:function(){return self.onClick.apply(self,arguments);}});$control_input.on({mousedown:function(e){e.stopPropagation();},keydown:function(){return self.onKeyDown.apply(self,arguments);},keyup:function(){return self.onKeyUp.apply(self,arguments);},keypress:function(){return self.onKeyPress.apply(self,arguments);},resize:function(){self.positionDropdown.apply(self,[]);},blur:function(){return self.onBlur.apply(self,arguments);},focus:function(){return self.onFocus.apply(self,arguments);}});$document.on('keydown'+eventNS,function(e){self.isCmdDown=e[IS_MAC?'metaKey':'ctrlKey'];self.isCtrlDown=e[IS_MAC?'altKey':'ctrlKey'];self.isShiftDown=e.shiftKey;});$document.on('keyup'+eventNS,function(e){if(e.keyCode===KEY_CTRL)self.isCtrlDown=false;if(e.keyCode===KEY_SHIFT)self.isShiftDown=false;if(e.keyCode===KEY_CMD)self.isCmdDown=false;});$document.on('mousedown'+eventNS,function(e){if(self.isFocused){if(e.target===self.$dropdown[0]||e.target.parentNode===self.$dropdown[0]){return false;}if(!self.$control.has(e.target).length&&e.target!==self.$control[0]){self.blur();}}});$window.on(['scroll'+eventNS,'resize'+eventNS].join(' '),function(){if(self.isOpen){self.positionDropdown.apply(self,arguments);}});$window.on('mousemove'+eventNS,function(){self.ignoreHover=false;});this.revertSettings={$children:self.$input.children().detach(),tabindex:self.$input.attr('tabindex')};self.$input.attr('tabindex',-1).hide().after(self.$wrapper);if($.isArray(settings.items)){self.setValue(settings.items);delete settings.items;}if(self.$input[0].validity){self.$input.on('invalid'+eventNS,function(e){e.preventDefault();self.isInvalid=true;self.refreshState();});}self.updateOriginalInput();self.refreshItems();self.refreshState();self.updatePlaceholder();self.isSetup=true;if(self.$input.is(':disabled')){self.disable();}self.on('change',this.onChange);self.trigger('initialize');if(settings.preload){self.onSearchChange('');}},setupTemplates:function(){var self=this;var field_label=self.settings.labelField;var field_optgroup=self.settings.optgroupLabelField;var templates={'optgroup':function(data){return'
'+data.html+'
';},'optgroup_header':function(data,escape){return'
'+escape(data[field_optgroup])+'
';},'option':function(data,escape){return'
'+escape(data[field_label])+'
';},'item':function(data,escape){return'
'+escape(data[field_label])+'
';},'option_create':function(data,escape){return'
Add '+escape(data.input)+'
';}};self.settings.render=$.extend({},templates,self.settings.render);},setupCallbacks:function(){var key,fn,callbacks={'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(key in callbacks){if(callbacks.hasOwnProperty(key)){fn=this.settings[callbacks[key]];if(fn)this.on(key,fn);}}},onClick:function(e){var self=this;if(!self.isFocused){self.focus();e.preventDefault();}},onMouseDown:function(e){var self=this;var defaultPrevented=e.isDefaultPrevented();var $target=$(e.target);if(self.isFocused){if(e.target!==self.$control_input[0]){if(self.settings.mode==='single'){self.isOpen?self.close():self.open();}else if(!defaultPrevented){self.setActiveItem(null);}return false;}}else{if(!defaultPrevented){window.setTimeout(function(){self.focus();},0);}}},onChange:function(){this.$input.trigger('change');},onKeyPress:function(e){if(this.isLocked)return e&&e.preventDefault();var character=String.fromCharCode(e.keyCode||e.which);if(this.settings.create&&character===this.settings.delimiter){this.createItem();e.preventDefault();return false;}},onKeyDown:function(e){var isInput=e.target===this.$control_input[0];var self=this;if(self.isLocked){if(e.keyCode!==KEY_TAB){e.preventDefault();}return;}switch(e.keyCode){case KEY_A:if(self.isCmdDown){self.selectAll();return;}break;case KEY_ESC:self.close();return;case KEY_DOWN:if(!self.isOpen&&self.hasOptions){self.open();}else if(self.$activeOption){self.ignoreHover=true;var $next=self.getAdjacentOption(self.$activeOption,1);if($next.length)self.setActiveOption($next,true,true);}e.preventDefault();return;case KEY_UP:if(self.$activeOption){self.ignoreHover=true;var $prev=self.getAdjacentOption(self.$activeOption,-1);if($prev.length)self.setActiveOption($prev,true,true);}e.preventDefault();return;case KEY_RETURN:case KEY_LEFT:self.advanceSelection(-1,e);return;case KEY_RIGHT:self.advanceSelection(1,e);return;case KEY_TAB:if(self.settings.create&&self.createItem()){e.preventDefault();}return;case KEY_BACKSPACE:case KEY_DELETE:self.deleteSelection(e);return;}if(self.isFull()||self.isInputHidden){e.preventDefault();return;}},onKeyUp:function(e){var self=this;if(self.isLocked)return e&&e.preventDefault();var value=self.$control_input.val()||'';if(self.lastValue!==value){self.lastValue=value;self.onSearchChange(value);self.refreshOptions();self.trigger('type',value);}},onSearchChange:function(value){var self=this;var fn=self.settings.load;if(!fn)return;if(self.loadedSearches.hasOwnProperty(value))return;self.loadedSearches[value]=true;self.load(function(callback){fn.apply(self,[value,callback]);});},onFocus:function(e){var self=this;self.isFocused=true;if(self.isDisabled){self.blur();e&&e.preventDefault();return false;}if(self.ignoreFocus)return;if(self.settings.preload==='focus')self.onSearchChange('');if(!self.$activeItems.length){self.showInput();self.setActiveItem(null);self.refreshOptions(!!self.settings.openOnFocus);}self.refreshState();},onBlur:function(e){var self=this;self.isFocused=false;if(self.ignoreFocus)return;if(self.settings.create&&self.settings.createOnBlur){self.createItem();}self.close();self.setTextboxValue('');self.setActiveItem(null);self.setActiveOption(null);self.setCaret(self.items.length);self.refreshState();},onOptionHover:function(e){if(this.ignoreHover)return;this.setActiveOption(e.currentTarget,false);},onOptionSelect:function(e){var value,$target,$option,self=this;if(e.preventDefault){e.preventDefault();e.stopPropagation();}$target=$(e.currentTarget);if($target.hasClass('create')){self.createItem();}else{value=$target.attr('data-value');if(value){self.lastQuery=null;self.setTextboxValue('');self.addItem(value);if(!self.settings.hideSelected&&e.type&&/mouse/.test(e.type)){self.setActiveOption(self.getOption(value));}}}},onItemSelect:function(e){var self=this;if(self.isLocked)return;if(self.settings.mode==='multi'){e.preventDefault();self.setActiveItem(e.currentTarget,e);}},load:function(fn){var self=this;var $wrapper=self.$wrapper.addClass('loading');self.loading++;fn.apply(self,[function(results){self.loading=Math.max(self.loading-1,0);if(results&&results.length){self.addOption(results);self.refreshOptions(self.isFocused&&!self.isInputHidden);}if(!self.loading){$wrapper.removeClass('loading');}self.trigger('load',results);}]);},setTextboxValue:function(value){this.$control_input.val(value).triggerHandler('update');this.lastValue=value;},getValue:function(){if(this.tagType===TAG_SELECT&&this.$input.attr('multiple')){return this.items;}else{return this.items.join(this.settings.delimiter);}},setValue:function(value){debounce_events(this,['change'],function(){this.clear();var items=$.isArray(value)?value:[value];for(var i=0,n=items.length;iend){swap=begin;begin=end;end=swap;}for(i=begin;i<=end;i++){item=self.$control[0].childNodes[i];if(self.$activeItems.indexOf(item)===-1){$(item).addClass('active');self.$activeItems.push(item);}}e.preventDefault();}else if((eventName==='mousedown'&&self.isCtrlDown)||(eventName==='keydown'&&this.isShiftDown)){if($item.hasClass('active')){idx=self.$activeItems.indexOf($item[0]);self.$activeItems.splice(idx,1);$item.removeClass('active');}else{self.$activeItems.push($item.addClass('active')[0]);}}else{$(self.$activeItems).removeClass('active');self.$activeItems=[$item.addClass('active')[0]];}self.hideInput();if(!this.isFocused){self.focus();}},setActiveOption:function($option,scroll,animate){var height_menu,height_item,y;var scroll_top,scroll_bottom;var self=this;if(self.$activeOption)self.$activeOption.removeClass('active');self.$activeOption=null;$option=$($option);if(!$option.length)return;self.$activeOption=$option.addClass('active');if(scroll||!isset(scroll)){height_menu=self.$dropdown_content.height();height_item=self.$activeOption.outerHeight(true);scroll=self.$dropdown_content.scrollTop()||0;y=self.$activeOption.offset().top-self.$dropdown_content.offset().top+scroll;scroll_top=y;scroll_bottom=y-height_menu+height_item;if(y+height_item>height_menu+scroll){self.$dropdown_content.stop().animate({scrollTop:scroll_bottom},animate?self.settings.scrollDuration:0);}else if(y=0;i--){if(self.items.indexOf(hash_key(result.items[i].id))!==-1){result.items.splice(i,1);}}}return result;},refreshOptions:function(triggerDropdown){var i,j,k,n,groups,groups_order,option,option_html,optgroup,optgroups,html,html_children,has_create_option;var $active,$active_before,$create;if(typeof triggerDropdown==='undefined'){triggerDropdown=true;}var self=this;var query=self.$control_input.val();var results=self.search(query);var $dropdown_content=self.$dropdown_content;var active_before=self.$activeOption&&hash_key(self.$activeOption.attr('data-value'));n=results.items.length;if(typeof self.settings.maxOptions==='number'){n=Math.min(n,self.settings.maxOptions);}groups={};if(self.settings.optgroupOrder){groups_order=self.settings.optgroupOrder;for(i=0;i0||has_create_option;if(self.hasOptions){if(results.items.length>0){$active_before=active_before&&self.getOption(active_before);if($active_before&&$active_before.length){$active=$active_before;}else if(self.settings.mode==='single'&&self.items.length){$active=self.getOption(self.items[0]);}if(!$active||!$active.length){if($create&&!self.settings.addPrecedence){$active=self.getAdjacentOption($create,1);}else{$active=$dropdown_content.find('[data-selectable]:first');}}}else{$active=$create;}self.setActiveOption($active);if(triggerDropdown&&!self.isOpen){self.open();}}else{self.setActiveOption(null);if(triggerDropdown&&self.isOpen){self.close();}}},addOption:function(data){var i,n,optgroup,value,self=this;if($.isArray(data)){for(i=0,n=data.length;i=0&&index<$options.length?$options.eq(index):$();},getElementWithValue:function(value,$els){value=hash_key(value);if(value){for(var i=0,n=$els.length;i=self.settings.maxItems)){self.close();}else{self.positionDropdown();}self.updatePlaceholder();self.trigger('item_add',value,$item);self.updateOriginalInput();}});},removeItem:function(value){var self=this;var $item,i,idx;$item=(typeof value==='object')?value:self.getItem(value);value=hash_key($item.attr('data-value'));i=self.items.indexOf(value);if(i!==-1){$item.remove();if($item.hasClass('active')){idx=self.$activeItems.indexOf($item[0]);self.$activeItems.splice(idx,1);}self.items.splice(i,1);self.lastQuery=null;if(!self.settings.persist&&self.userOptions.hasOwnProperty(value)){self.removeOption(value);}if(i0);self.$control_input.data('grow',!isFull&&!isLocked);},isFull:function(){return this.settings.maxItems!==null&&this.items.length>=this.settings.maxItems;},updateOriginalInput:function(){var i,n,options,self=this;if(self.$input[0].tagName.toLowerCase()==='select'){options=[];for(i=0,n=self.items.length;i');}if(!options.length&&!this.$input.attr('multiple')){options.push('');}self.$input.html(options.join(''));}else{self.$input.val(self.getValue());}if(self.isSetup){self.trigger('change',self.$input.val());}},updatePlaceholder:function(){if(!this.settings.placeholder)return;var $input=this.$control_input;if(this.items.length){$input.removeAttr('placeholder');}else{$input.attr('placeholder',this.settings.placeholder);}$input.triggerHandler('update');},open:function(){var self=this;if(self.isLocked||self.isOpen||(self.settings.mode==='multi'&&self.isFull()))return;self.focus();self.isOpen=true;self.refreshState();self.$dropdown.css({visibility:'hidden',display:'block'});self.positionDropdown();self.$dropdown.css({visibility:'visible'});self.trigger('dropdown_open',self.$dropdown);},close:function(){var self=this;var trigger=self.isOpen;if(self.settings.mode==='single'&&self.items.length){self.hideInput();}self.isOpen=false;self.$dropdown.hide();self.setActiveOption(null);self.refreshState();if(trigger)self.trigger('dropdown_close',self.$dropdown);},positionDropdown:function(){var $control=this.$control;var offset=this.settings.dropdownParent==='body'?$control.offset():$control.position();offset.top+=$control.outerHeight(true);this.$dropdown.css({width:$control.outerWidth(),top:offset.top,left:offset.left});},clear:function(){var self=this;if(!self.items.length)return;self.$control.children(':not(input)').remove();self.items=[];self.setCaret(0);self.updatePlaceholder();self.updateOriginalInput();self.refreshState();self.showInput();self.trigger('clear');},insertAtCaret:function($el){var caret=Math.min(this.caretPos,this.items.length);if(caret===0){this.$control.prepend($el);}else{$(this.$control[0].childNodes[caret]).before($el);}this.setCaret(caret+1);},deleteSelection:function(e){var i,n,direction,selection,values,caret,option_select,$option_select,$tail;var self=this;direction=(e&&e.keyCode===KEY_BACKSPACE)?-1:1;selection=getSelection(self.$control_input[0]);if(self.$activeOption&&!self.settings.hideSelected){option_select=self.getAdjacentOption(self.$activeOption,-1).attr('data-value');}values=[];if(self.$activeItems.length){$tail=self.$control.children('.active:'+(direction>0?'last':'first'));caret=self.$control.children(':not(input)').index($tail);if(direction>0){caret++;}for(i=0,n=self.$activeItems.length;i0&&selection.start===self.$control_input.val().length){values.push(self.items[self.caretPos]);}}if(!values.length||(typeof self.settings.onDelete==='function'&&self.settings.onDelete.apply(self,[values])===false)){return false;}if(typeof caret!=='undefined'){self.setCaret(caret);}while(values.length){self.removeItem(values.pop());}self.showInput();self.positionDropdown();self.refreshOptions(true);if(option_select){$option_select=self.getOption(option_select);if($option_select.length){self.setActiveOption($option_select);}}return true;},advanceSelection:function(direction,e){var tail,selection,idx,valueLength,cursorAtEdge,$tail;var self=this;if(direction===0)return;if(self.rtl)direction*=-1;tail=direction>0?'last':'first';selection=getSelection(self.$control_input[0]);if(self.isFocused&&!self.isInputHidden){valueLength=self.$control_input.val().length;cursorAtEdge=direction<0?selection.start===0&&selection.length===0:selection.start===valueLength;if(cursorAtEdge&&!valueLength){self.advanceCaret(direction,e);}}else{$tail=self.$control.children('.active:'+tail);if($tail.length){idx=self.$control.children(':not(input)').index($tail);self.setActiveItem(null);self.setCaret(direction>0?idx+1:idx);}}},advanceCaret:function(direction,e){var self=this,fn,$adj;if(direction===0)return;fn=direction>0?'next':'prev';if(self.isShiftDown){$adj=self.$control_input[fn]();if($adj.length){self.hideInput();self.setActiveItem($adj);e&&e.preventDefault();}}else{self.setCaret(self.caretPos+direction);}},setCaret:function(i){var self=this;if(self.settings.mode==='single'){i=self.items.length;}else{i=Math.max(0,Math.min(self.items.length,i));}var j,n,fn,$children,$child;$children=self.$control.children(':not(input)');for(j=0,n=$children.length;j'+'
'+''+data.title+''+'×'+'
'+'
');}},options);self.setup=(function(){var original=self.setup;return function(){original.apply(self,arguments);self.$dropdown_header=$(options.html(options));self.$dropdown.prepend(self.$dropdown_header);};})();});Selectize.define('optgroup_columns',function(options){var self=this;options=$.extend({equalizeWidth:true,equalizeHeight:true},options);this.getAdjacentOption=function($option,direction){var $options=$option.closest('[data-group]').find('[data-selectable]');var index=$options.index($option)+direction;return index>=0&&index<$options.length?$options.eq(index):$();};this.onKeyDown=(function(){var original=self.onKeyDown;return function(e){var index,$option,$options,$optgroup;if(this.isOpen&&(e.keyCode===KEY_LEFT||e.keyCode===KEY_RIGHT)){self.ignoreHover=true;$optgroup=this.$activeOption.closest('[data-group]');index=$optgroup.find('[data-selectable]').index(this.$activeOption);if(e.keyCode===KEY_LEFT){$optgroup=$optgroup.prev('[data-group]');}else{$optgroup=$optgroup.next('[data-group]');}$options=$optgroup.find('[data-selectable]');$option=$options.eq(Math.min($options.length-1,index));if($option.length){this.setActiveOption($option);}return;}return original.apply(this,arguments);};})();var equalizeSizes=function(){var i,n,height_max,width,width_last,width_parent,$optgroups;$optgroups=$('[data-group]',self.$dropdown_content);n=$optgroups.length;if(!n||!self.$dropdown_content.width())return;if(options.equalizeHeight){height_max=0;for(i=0;i1){width_last=width_parent-width*(n-1);$optgroups.eq(n-1).css({width:width_last});}}};if(options.equalizeHeight||options.equalizeWidth){hook.after(this,'positionDropdown',equalizeSizes);hook.after(this,'refreshOptions',equalizeSizes);}});Selectize.define('remove_button',function(options){if(this.settings.mode==='single')return;options=$.extend({label:'×',title:'Remove',className:'remove',append:true},options);var self=this;var html=''+options.label+'';var append=function(html_container,html_element){var pos=html_container.search(/(<\/[^>]+>\s*)$/);return html_container.substring(0,pos)+html_element+html_container.substring(pos);};this.setup=(function(){var original=self.setup;return function(){if(options.append){var render_item=self.settings.render.item;self.settings.render.item=function(data){return append(render_item.apply(this,arguments),html);};}original.apply(this,arguments);this.$control.on('click','.'+options.className,function(e){e.preventDefault();if(self.isLocked)return;var $item=$(e.target).parent();self.setActiveItem($item);if(self.deleteSelection()){self.setCaret(self.items.length);}});};})();});Selectize.define('restore_on_backspace',function(options){var self=this;options.text=options.text||function(option){return option[this.settings.labelField];};this.onKeyDown=(function(e){var original=self.onKeyDown;return function(e){var index,option;if(e.keyCode===KEY_BACKSPACE&&this.$control_input.val()===''&&!this.$activeItems.length){index=this.caretPos-1;if(index>=0&&index