(function(d,k){typeof define=="function"&&define.amd?define(["jquery"],k):typeof module=="object"&&typeof module.exports=="object"?module.exports=k(require("jquery")):d.Selectize=k(d.jQuery)})(this,function(d){"use strict";var k=function(e,t){if(!(typeof t=="string"&&!t.length)){var i=typeof t=="string"?new RegExp(t,"i"):t,n=function(r){var s=0;if(r.nodeType===3){var o=r.data.search(i);if(o>=0&&r.data.length>0){var a=r.data.match(i),l=document.createElement("span");l.className="highlight";var c=r.splitText(o),u=c.splitText(a[0].length),f=c.cloneNode(!0);l.appendChild(f),c.parentNode.replaceChild(l,c),s=1}}else if(r.nodeType===1&&r.childNodes&&!/(script|style)/i.test(r.tagName)&&(r.className!=="highlight"||r.tagName!=="SPAN"))for(var h=0;hcrypto.getRandomValues(new Uint8Array(e)).reduce((t,i)=>t+=(i&=63)<36?i.toString(36):i<62?(i-26).toString(36).toUpperCase():i>62?"-":"_","");var A=function(e,t){this.items=e,this.settings=t||{diacritics:!0}};A.prototype.tokenize=function(e,t){if(e=se(String(e||"").toLowerCase()),!e||!e.length)return[];var i,n,r,s,o=[],a=e.split(/ +/);for(i=0,n=a.length;i0)&&s.items.push({score:r,id:u})}):i.iterator(i.items,function(c,u){s.items.push({score:1,id:u})}),a=i.getSortFunction(s,t),a&&s.items.sort(a),s.total=s.items.length,typeof t.limit=="number"&&(s.items=s.items.slice(0,t.limit)),s};var Q=function(e,t){return typeof e=="number"&&typeof t=="number"?e>t?1:et?1:t>e?-1:0)},re=function(e,t){var i,n,r,s;for(i=1,n=arguments.length;i/g,">").replace(/"/g,""")},Ie=function(e){return(e+"").replace(/\$/g,"$$$$")},L={};L.before=function(e,t,i){var n=e[t];e[t]=function(){return i.apply(e,arguments),n.apply(e,arguments)}},L.after=function(e,t,i){var n=e[t];e[t]=function(){var r=n.apply(e,arguments);return i.apply(e,arguments),r}};var ye=function(e){var t=!1;return function(){t||(t=!0,e.apply(this,arguments))}},Oe=function(e,t){var i;return function(){var n=this,r=arguments;window.clearTimeout(i),i=window.setTimeout(function(){e.apply(n,r)},t)}},te=function(e,t,i){var n,r=e.trigger,s={};e.trigger=function(){var o=arguments[0];if(t.indexOf(o)!==-1)s[o]=arguments;else return r.apply(e,arguments)},i.apply(e,[]),e.trigger=r;for(n in s)s.hasOwnProperty(n)&&r.apply(e,s[n])},be=function(e,t,i,n){e.on(t,i,function(r){for(var s=r.target;s&&s.parentNode!==e[0];)s=s.parentNode;return r.currentTarget=s,n.apply(this,[r])})},R=function(e){var t={};if(e===void 0)return console.warn("WARN getInputSelection cannot locate input control"),t;if("selectionStart"in e)t.start=e.selectionStart,t.length=e.selectionEnd-t.start;else if(document.selection){e.focus();var i=document.selection.createRange(),n=document.selection.createRange().text.length;i.moveStart("character",-e.value.length),t.start=i.text.length-n,t.length=n}return t},_e=function(e,t,i){var n,r,s={};if(i)for(n=0,r=i.length;n").css({position:"absolute",width:"auto",padding:0,whiteSpace:"pre"}),d("
").css({position:"absolute",width:0,height:0,overflow:"hidden"}).attr({"aria-hidden":!0}).append(w.$testInput).appendTo("body")),w.$testInput.text(e),_e(t,w.$testInput,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]),w.$testInput.width()):0},Ce=function(e){var t=null,i=function(n,r){var s,o,a,g,l,c,u,f,h;if(n=n||window.event||{},r=r||{},!(n.metaKey||n.altKey)&&!(!r.force&&e.data("grow")===!1)){s=e.val(),n.type&&n.type.toLowerCase()==="keydown"&&(o=n.keyCode,a=o>=48&&o<=57||o>=65&&o<=90||o>=96&&o<=111||o>=186&&o<=222||o===32,o===q||o===z?(h=R(e[0]),h.length?s=s.substring(0,h.start)+s.substring(h.start+h.length):o===z&&h.start?s=s.substring(0,h.start-1)+s.substring(h.start+1):o===q&&typeof h.start!="undefined"&&(s=s.substring(0,h.start)+s.substring(h.start+1))):a&&(u=n.shiftKey,f=String.fromCharCode(n.keyCode),u?f=f.toUpperCase():f=f.toLowerCase(),s+=f));var g=e.attr("readonly")?0:4;l=e.attr("placeholder"),l?c=ie(l,e)+g:c=0,g=Math.max(ie(s,e),c)+g,g!==t&&(t=g,e.width(g),e.triggerHandler("resize"))}};e.on("keydown keyup update blur",i),i()},$e=function(e){var t=document.createElement("div");return t.appendChild(e.cloneNode(!0)),t.innerHTML},Fe=function(e,t){t||(t={});var i="Selectize";console.error(i+": "+e),t.explanation&&(console.group&&console.group(),console.error(t.explanation),console.group&&console.groupEnd())},xe=function(e){try{JSON.parse(e)}catch(t){return!1}return!0};function ne(e,t){return navigator.userAgentData?e===navigator.userAgentData.platform:t.test(navigator.userAgent)}var w=function(e,t){var i,n,r,s,o,a=this;o=e[0],o.selectize=a;var l=window.getComputedStyle&&window.getComputedStyle(o,null);if(s=l?l.getPropertyValue("direction"):o.currentStyle&&o.currentStyle.direction,s=s||e.parents("[dir]:first").attr("dir")||"",a.settings={},++w.count,d.extend(a,{order:0,settings:t,$input:e,tabIndex:e.attr("tabindex")||"",tagType:o.tagName.toLowerCase()==="select"?K:me,rtl:/rtl/i.test(s),eventNS:".selectize-"+new Date().getTime()+"-"+Math.random().toString(36).substr(2,5),highlightedValue:null,isBlurring:!1,isOpen:!1,isDisabled:!1,isRequired:e.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:"",lastValidValue:"",lastOpenTarget:!1,caretPos:0,loading:0,loadedSearches:{},isDropdownClosing:!1,$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:t.loadThrottle===null?a.onSearchChange:Oe(a.onSearchChange,t.loadThrottle)}),a.sifter=new A(this.options,{diacritics:t.diacritics}),a.settings.options){for(n=0,r=a.settings.options.length;n").addClass(t.wrapperClass).addClass(y+" selectize-control").addClass(h),a=d("
").addClass(t.inputClass+x+" selectize-input items").appendTo(o),l=d('').appendTo(a).attr("tabindex",s.is(":disabled")?"-1":e.tabIndex),f=d(t.dropdownParent||o),c=d("
").addClass(t.dropdownClass).addClass(h+" selectize-dropdown").hide().appendTo(f),u=d("
").addClass(t.dropdownContentClass+" selectize-dropdown-content").attr("tabindex","-1").appendTo(c),(p=s.attr("id"))&&(l.attr("id",p+"-selectized"),d("label[for='"+p+"']").attr("for",p+"-selectized")),e.settings.copyClassesToDropdown&&c.addClass(y),o.css({width:s[0].style.width}),e.plugins.names.length&&(O="plugin-"+e.plugins.names.join(" plugin-"),o.addClass(O),c.addClass(O)),(t.maxItems===null||t.maxItems>1)&&e.tagType===K&&s.attr("multiple","multiple"),e.settings.placeholder&&l.attr("placeholder",t.placeholder),e.settings.search||(l.attr("readonly",!0),l.attr("inputmode","none"),a.css("cursor","pointer")),!e.settings.splitOn&&e.settings.delimiter){var _=e.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");e.settings.splitOn=new RegExp("\\s*"+_+"+\\s*")}s.attr("autocorrect")&&l.attr("autocorrect",s.attr("autocorrect")),s.attr("autocapitalize")&&l.attr("autocapitalize",s.attr("autocapitalize")),s.is("input")&&(l[0].type=s[0].type),e.$wrapper=o,e.$control=a,e.$control_input=l,e.$dropdown=c,e.$dropdown_content=u,c.on("mouseenter mousedown mouseup click","[data-disabled]>[data-selectable]",function(m){m.stopImmediatePropagation()}),c.on("mouseenter","[data-selectable]",function(){return e.onOptionHover.apply(e,arguments)}),c.on("mouseup click","[data-selectable]",function(){return e.onOptionSelect.apply(e,arguments)}),be(a,"mouseup","*:not(input)",function(){return e.onItemSelect.apply(e,arguments)}),Ce(l),a.on({mousedown:function(){return e.onMouseDown.apply(e,arguments)},click:function(){return e.onClick.apply(e,arguments)}}),l.on({mousedown:function(m){(e.$control_input.val()!==""||e.settings.openOnFocus)&&m.stopPropagation()},keydown:function(){return e.onKeyDown.apply(e,arguments)},keypress:function(){return e.onKeyPress.apply(e,arguments)},input:function(){return e.onInput.apply(e,arguments)},resize:function(){e.positionDropdown.apply(e,[])},blur:function(){return e.onBlur.apply(e,arguments)},focus:function(){return e.onFocus.apply(e,arguments)},paste:function(){return e.onPaste.apply(e,arguments)}}),r.on("keydown"+i,function(m){e.isCmdDown=m[P?"metaKey":"ctrlKey"],e.isCtrlDown=m[P?"altKey":"ctrlKey"],e.isShiftDown=m.shiftKey}),r.on("keyup"+i,function(m){m.keyCode===ve&&(e.isCtrlDown=!1),m.keyCode===he&&(e.isShiftDown=!1),m.keyCode===ge&&(e.isCmdDown=!1)}),r.on("mousedown"+i,function(m){if(e.isFocused){if(m.target===e.$dropdown[0]||e.$dropdown.has(m.target).length)return!1;m.target!==e.$control[0]&&e.blur(m.target)}}),n.on(["scroll"+i,"resize"+i].join(" "),function(){e.isOpen&&e.positionDropdown.apply(e,arguments)}),n.on("mousemove"+i,function(){e.ignoreHover=e.settings.ignoreHover}),this.revertSettings={$children:s.children().detach(),tabindex:s.attr("tabindex")},s.attr("tabindex",-1).hide().after(e.$wrapper),Array.isArray(t.items)&&(e.lastValidValue=t.items,e.setValue(t.items),delete t.items),Z&&s.on("invalid"+i,function(m){m.preventDefault(),e.isInvalid=!0,e.refreshState()}),e.updateOriginalInput(),e.refreshItems(),e.refreshState(),e.updatePlaceholder(),e.isSetup=!0,s.is(":disabled")&&e.disable(),e.on("change",this.onChange),s.data("selectize",e),s.addClass("selectized"),e.trigger("initialize"),t.preload===!0&&e.onSearchChange("")},setupTemplates:function(){var e=this,t=e.settings.labelField,i=e.settings.valueField,n=e.settings.optgroupLabelField,r={optgroup:function(s){return'
'+s.html+"
"},optgroup_header:function(s,o){return'
'+o(s[n])+"
"},option:function(s,o){var a=s.classes?" "+s.classes:"";a+=s[i]===""?" selectize-dropdown-emptyoptionlabel":"";var l=s.styles?' style="'+s.styles+'"':"";return"'+o(s[t])+"
"},item:function(s,o){return'
'+o(s[t])+"
"},option_create:function(s,o){return'
Add '+o(s.input)+"
"}};e.settings.render=d.extend({},r,e.settings.render)},setupCallbacks:function(){var e,t,i={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",dropdown_item_activate:"onDropdownItemActivate",dropdown_item_deactivate:"onDropdownItemDeactivate"};for(e in i)i.hasOwnProperty(e)&&(t=this.settings[i[e]],t&&this.on(e,t))},onClick:function(e){var t=this;t.isDropdownClosing||(!t.isFocused||!t.isOpen)&&(t.focus(),e.preventDefault())},onMouseDown:function(e){var t=this,i=e.isDefaultPrevented(),n=d(e.target);if(t.isFocused||i||window.setTimeout(function(){t.isOpen||t.focus()},0),n!==t.$control_input[0]||t.$control_input.val()==="")return t.settings.mode==="single"?t.isOpen?t.close():t.open():(i||t.setActiveItem(null),t.settings.openOnFocus||(t.isOpen&&n===t.lastOpenTarget?(t.close(),t.lastOpenTarget=!1):(t.isOpen||(t.refreshOptions(),t.open()),t.lastOpenTarget=n))),!1},onChange:function(){var e=this;e.getValue()!==""&&(e.lastValidValue=e.getValue()),this.$input.trigger("input"),this.$input.trigger("change")},onPaste:function(e){var t=this;if(t.isFull()||t.isInputHidden||t.isLocked){e.preventDefault();return}t.settings.splitOn&&setTimeout(function(){var i=t.$control_input.val();if(!!i.match(t.settings.splitOn))for(var n=i.trim().split(t.settings.splitOn),r=0,s=n.length;ra&&(c=o,o=a,a=c),r=o;r<=a;r++)l=i.$control[0].childNodes[r],i.$activeItems.indexOf(l)===-1&&(d(l).addClass("active"),i.$activeItems.push(l));t.preventDefault()}else n==="mousedown"&&i.isCtrlDown||n==="keydown"&&this.isShiftDown?e.hasClass("active")?(s=i.$activeItems.indexOf(e[0]),i.$activeItems.splice(s,1),e.removeClass("active")):i.$activeItems.push(e.addClass("active")[0]):(d(i.$activeItems).removeClass("active"),i.$activeItems=[e.addClass("active")[0]]);i.hideInput(),this.isFocused||i.focus()}},setActiveOption:function(e,t,i){var n,r,s,o,a,l=this;l.$activeOption&&(l.$activeOption.removeClass("active"),l.trigger("dropdown_item_deactivate",l.$activeOption.attr("data-value"))),l.$activeOption=null,e=d(e),e.length&&(l.$activeOption=e.addClass("active"),l.isOpen&&l.trigger("dropdown_item_activate",l.$activeOption.attr("data-value")),(t||!ee(t))&&(n=l.$dropdown_content.height(),r=l.$activeOption.outerHeight(!0),t=l.$dropdown_content.scrollTop()||0,s=l.$activeOption.offset().top-l.$dropdown_content.offset().top+t,o=s,a=s-n+r,s+r>n+t?l.$dropdown_content.stop().animate({scrollTop:a},i?l.settings.scrollDuration:0):s=0;t--)o.items.indexOf(F(r.items[t].id))!==-1&&r.items.splice(t,1);return r},refreshOptions:function(e){var t,i,n,r,s,o,a,l,c,u,f,h,g,v,y,O;typeof e=="undefined"&&(e=!0);var p=this,x=p.$control_input.val().trim(),_=p.search(x),m=p.$dropdown_content,E=p.$activeOption&&F(p.$activeOption.attr("data-value"));for(r=_.items.length,typeof p.settings.maxOptions=="number"&&(r=Math.min(r,p.settings.maxOptions)),s={},o=[],t=0;t0||g&&p.settings.showAddOptionOnCreate||p.settings.setFirstOptionActive,p.hasOptions?(_.items.length>0?(y=E&&p.getOption(E),_.query!==""&&p.settings.setFirstOptionActive?v=m.find("[data-selectable]:first"):_.query!==""&&y&&y.length?v=y:p.settings.mode==="single"&&p.items.length&&(v=p.getOption(p.items[0])),(!v||!v.length)&&(O&&!p.settings.addPrecedence?v=p.getAdjacentOption(O,1):v=m.find("[data-selectable]:first"))):v=O,p.setActiveOption(v),e&&!p.isOpen&&p.open()):(p.setActiveOption(null),e&&p.isOpen&&p.close())},addOption:function(e){var t,i,n,r=this;if(Array.isArray(e)){for(t=0,i=e.length;t0?e.eq(0):d()},getAdjacentOption:function(e,t){var i=this.$dropdown.find("[data-selectable]"),n=i.index(e)+t;return n>=0&&n0),e.$control_input.data("grow",!t&&!i)},isFull:function(){return this.settings.maxItems!==null&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(e){var t,i,n,r,s,o,a,l,c,u=this;e=e||{},u.tagType===K?(o=u.$input.find("option"),n=[],r=[],s=[],c=[],o.get().forEach(function(f){n.push(f.value)}),u.items.forEach(function(f){a=u.options[f][u.settings.labelField]||"",c.push(f),n.indexOf(f)==-1&&r.push('")}),s=n.filter(function(f){return c.indexOf(f)<0}).map(function(f){return'option[value="'+T(f)+'"]'}),n.length-s.length+r.length===0&&!u.$input.attr("multiple")&&r.push(''),u.$input.find(s.join(", ")).remove(),u.$input.append(r.join(""))):(u.$input.val(u.getValue()),u.$input.attr("value",u.$input.val())),u.isSetup&&(e.silent||u.trigger("change",u.$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||e.settings.mode==="multi"&&e.isFull()||(e.focus(),e.isOpen=!0,e.refreshState(),e.$dropdown.css({visibility:"hidden",display:"block"}),e.setupDropdownHeight(),e.positionDropdown(),e.$dropdown.css({visibility:"visible"}),e.trigger("dropdown_open",e.$dropdown))},close:function(){var e=this,t=e.isOpen;e.settings.mode==="single"&&e.items.length&&(e.hideInput(),e.isBlurring&&e.$control_input[0].blur()),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=this.settings.dropdownParent==="body"?e.offset():e.position();t.top+=e.outerHeight(!0);var i=this.$wrapper[0].style.width!=="fit-content"?this.settings.dropdownParent==="body"?"max-content":"100%":"max-content";this.settings.minWidth&&this.settings.minWidth>i&&(i=this.settings.minWidth),this.settings.dropdownParent!=="body"&&i==="max-content"&&e.outerWidth(!0)>=this.$dropdown.outerWidth(!0)&&(i="100%"),this.$dropdown.css({width:i,minWidth:e.outerWidth(!0),top:t.top,left:t.left})},setupDropdownHeight:function(){if(typeof this.settings.dropdownSize=="object"&&this.settings.dropdownSize.sizeType!=="auto"){var e=this.settings.dropdownSize.sizeValue;if(this.settings.dropdownSize.sizeType==="numberItems"){for(var t=this.$dropdown_content.find("*").not(".optgroup, .highlight").not(this.settings.ignoreOnDropwdownHeight),i=0,n=0,r=0,s=0,o=0;o0?"last":"first")),o=u.$control.children(":not(input)").index(c),n>0&&o++,t=0,i=u.$activeItems.length;t0&&r.start===u.$control_input.val().length&&s.push(u.items[u.caretPos]));if(!s.length||typeof u.settings.onDelete=="function"&&u.settings.onDelete.apply(u,[s])===!1)return!1;for(typeof o!="undefined"&&u.setCaret(o);s.length;)u.removeItem(s.pop());return u.showInput(),u.positionDropdown(),u.refreshOptions(!0),a&&(l=u.getOption(a),l.length&&u.setActiveOption(l)),!0},advanceSelection:function(e,t){var i,n,r,s,o,a,l=this;e!==0&&(l.rtl&&(e*=-1),i=e>0?"last":"first",n=R(l.$control_input[0]),l.isFocused&&!l.isInputHidden?(s=l.$control_input.val().length,o=e<0?n.start===0&&n.length===0:n.start===s,o&&!s&&l.advanceCaret(e,t)):(a=l.$control.children(".active:"+i),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 i=this,n,r;e!==0&&(n=e>0?"next":"prev",i.isShiftDown?(r=i.$control_input[n](),r.length&&(i.hideInput(),i.setActiveItem(r),t&&t.preventDefault())):i.setCaret(i.caretPos+e))},setCaret:function(e){var t=this;if(t.settings.mode==="single"?e=t.items.length:e=Math.max(0,Math.min(t.items.length,e)),!t.isPending){var i,n,r,s,o;for(s=t.$control.children(":not(input)"),i=0,n=s.length;i'+p+""+O)}var x={placeholder:y,options:[],optgroups:[],items:[]};v==="select"?f(g,x):u(g,x),h=new w(g,d.extend(!0,{},t,x,e)),h.settings_user=e}})},d.fn.selectize.defaults=w.defaults,d.fn.selectize.support={validity:Z},w.define("auto_position",function(){var e=this;const t={top:"top",bottom:"bottom"};e.positionDropdown=function(){return function(){const i=this.$control,n=this.settings.dropdownParent==="body"?i.offset():i.position();n.top+=i.outerHeight(!0);const r=this.$dropdown.prop("scrollHeight")+5,s=this.$control.get(0).getBoundingClientRect().top,o=this.$wrapper.height(),a=e.$control.get(0).getBoundingClientRect().bottom,l=s+r+o>window.innerHeight&&a-r-o>=0?t.top:t.bottom;let c=this.$wrapper[0].style.width!=="fit-content"?this.settings.dropdownParent==="body"?"max-content":"100%":"max-content";const u={width:c,minWidth:i.outerWidth(!0),left:n.left};if(l===t.top){const f={bottom:n.top,top:"unset"};this.settings.dropdownParent==="body"&&(f.top=n.top-this.$dropdown.outerHeight(!0)-i.outerHeight(!0),f.bottom="unset"),Object.assign(u,f),this.$dropdown.addClass("selectize-position-top"),this.$control.addClass("selectize-position-top")}else Object.assign(u,{top:n.top,bottom:"unset"}),this.$dropdown.removeClass("selectize-position-top"),this.$control.removeClass("selectize-position-top");this.settings.dropdownParent!=="body"&&c==="max-content"&&i.outerWidth(!0)>=this.$dropdown.outerWidth(!0)&&(c="100%"),this.$dropdown.css(u)}}()}),w.define("auto_select_on_type",function(e){var t=this;t.onBlur=function(){var i=t.onBlur;return function(n){var r=t.getFirstItemMatchedByTextContent(t.lastValue,!0);return typeof r.attr("data-value")!="undefined"&&t.getValue()!==r.attr("data-value")&&t.setValue(r.attr("data-value")),i.apply(this,arguments)}}()}),w.define("autofill_disable",function(e){var t=this;t.setup=function(){var i=t.setup;return function(){i.apply(t,arguments),t.$control_input.attr({name:G(21),autocomplete:G(21)})}}()}),w.define("clear_button",function(e){var t=this;e=d.extend({title:"Clear",className:"clear",label:"\xD7",html:function(i){return' '+i.label+""}},e),t.setup=function(){var i=t.setup;return function(){i.apply(t,arguments),t.$button_clear=d(e.html(e)),t.settings.mode==="single"&&t.$wrapper.addClass("single"),t.$wrapper.append(t.$button_clear),(t.getValue()===""||t.getValue().length===0)&&t.$wrapper.find("."+e.className).css("display","none"),t.on("change",function(){t.getValue()===""||t.getValue().length===0?t.$wrapper.find("."+e.className).css("display","none"):t.$wrapper.find("."+e.className).css("display","")}),t.$wrapper.on("click","."+e.className,function(n){n.preventDefault(),n.stopImmediatePropagation(),n.stopPropagation(),!t.isLocked&&(t.clear(),t.$wrapper.find("."+e.className).css("display","none"))})}}()}),w.define("drag_drop",function(e){if(!d.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if(this.settings.mode==="multi"){var t=this;t.lock=function(){var i=t.lock;return function(){var n=t.$control.data("sortable");return n&&n.disable(),i.apply(t,arguments)}}(),t.unlock=function(){var i=t.unlock;return function(){var n=t.$control.data("sortable");return n&&n.enable(),i.apply(t,arguments)}}(),t.setup=function(){var i=t.setup;return function(){i.apply(this,arguments);var n=t.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:t.isLocked,start:function(r,s){s.placeholder.css("width",s.helper.css("width")),n.addClass("dragging")},stop:function(){n.removeClass("dragging");var r=t.$activeItems?t.$activeItems.slice():null,s=[];n.children("[data-value]").each(function(){s.push(d(this).attr("data-value"))}),t.isFocused=!1,t.setValue(s),t.isFocused=!0,t.setActiveItem(r),t.positionDropdown()}})}}()}}),w.define("dropdown_header",function(e){var t=this;e=d.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(i){return'
'+i.title+'×
'}},e),t.setup=function(){var i=t.setup;return function(){i.apply(t,arguments),t.$dropdown_header=d(e.html(e)),t.$dropdown.prepend(t.$dropdown_header),t.$dropdown_header.find("."+e.closeClass).on("click",function(){t.close()})}}()}),w.define("optgroup_columns",function(e){var t=this;e=d.extend({equalizeWidth:!0,equalizeHeight:!0},e),this.getAdjacentOption=function(r,s){var o=r.closest("[data-group]").find("[data-selectable]"),a=o.index(r)+s;return a>=0&&a
',r=r.firstChild,o.body.appendChild(r),s=i.width=r.offsetWidth-r.clientWidth,o.body.removeChild(r)),s},n=function(){var r,s,o,a,l,c,u;if(u=d("[data-group]",t.$dropdown_content),s=u.length,!(!s||!t.$dropdown_content.width())){if(e.equalizeHeight){for(o=0,r=0;r1&&(l=c-a*(s-1),u.eq(s-1).css({width:l})))}};(e.equalizeHeight||e.equalizeWidth)&&(L.after(this,"positionDropdown",n),L.after(this,"refreshOptions",n))}),w.define("read-only",function(e){var t=this;this.setup=function(){var i=t.setup;return function(){i.apply(this,arguments),this.$dropdown.hasClass("read-only")&&this.$control_input.attr("readonly","readonly")}}(),this.readonly=function(){return function(i){i?(this.$control_input.attr("readonly","readonly"),this.$dropdown.addClass("read-only")):(this.$control_input.removeAttr("readonly"),this.$dropdown.removeClass("read-only"))}}()}),w.define("remove_button",function(e){if(this.settings.mode!=="single"){e=d.extend({label:"×",title:"Remove",className:"remove",append:!0},e);var t=function(i,n){var r=i,s=''+n.label+"",o=function(a,l){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+l+a.substring(c)};i.setup=function(){var a=r.setup;return function(){if(n.append){var l=r.settings.render.item;r.settings.render.item=function(c){return o(l.apply(i,arguments),s)}}a.apply(i,arguments),i.$control.on("click","."+n.className,function(c){if(c.preventDefault(),!r.isLocked){var u=d(c.currentTarget).parent();return r.setActiveItem(u),r.deleteSelection()&&r.setCaret(r.items.length),!1}})}}()};t(this,e)}}),w.define("restore_on_backspace",function(e){var t=this;e.text=e.text||function(i){return i[this.settings.labelField]},this.onKeyDown=function(){var i=t.onKeyDown;return function(n){var r,s;if(n.keyCode===z&&this.$control_input.val()===""&&!this.$activeItems.length&&(r=this.caretPos-1,r>=0&&r"+(o.length-a)+""))}}(),this.onFocus=function(i){const n=t.onFocus;return function(r){if(n.apply(this,r),!r)return;const s=this.$control;s.find(".item").show(),s.find("span").remove()}}()}),w});