diff --git a/README.md b/README.md index 206ea5e..958621b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Choices.js - in development +# Choices.js - beta A lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency. Coming soon. @@ -17,35 +17,70 @@ Coming soon. var choice = new Choices('[data-choice']); var choice = new Choices('.js-choice'); - // Passing options + // Passing options (with default options) var choices = new Choices(elements, { items: [], + maxItemCount: -1, addItems: true, removeItems: true, - removeButton: false, + removeItemButton: false, editItems: false, - maxItems: false, + duplicateItems: true, delimiter: ',', - allowDuplicates: true, - allowPaste: true, - allowSearch: true, - regexFilter: false, + paste: true, + searchOptions: true, + regexFilter: null, placeholder: true, - placeholderValue: '', - prependValue: false, - appendValue: false, - highlightAll: true, + placeholderValue: null, + prependValue: null, + appendValue: null, loadingText: 'Loading...', + templates: {}, + classNames: { + containerOuter: 'choices', + containerInner: 'choices__inner', + input: 'choices__input', + inputCloned: 'choices__input--cloned', + list: 'choices__list', + listItems: 'choices__list--multiple', + listSingle: 'choices__list--single', + listDropdown: 'choices__list--dropdown', + item: 'choices__item', + itemSelectable: 'choices__item--selectable', + itemDisabled: 'choices__item--disabled', + itemOption: 'choices__item--option', + group: 'choices__group', + groupHeading : 'choices__heading', + button: 'choices__button', + activeState: 'is-active', + focusState: 'is-focused', + openState: 'is-open', + disabledState: 'is-disabled', + highlightedState: 'is-highlighted', + hiddenState: 'is-hidden', + flippedState: 'is-flipped', + selectedState: 'is-selected', + }, + callbackOnInit: () => {}, + callbackOnAddItem: (id, value, passedInput) => {}, + callbackOnRemoveItem: (id, value, passedInput) => {}, }); ``` ## Installation -To install via NPM, run `npm install --save-dev choices.js` +To install via NPM, run `npm install --save-dev choices.js` + +## Terminology +| Word | Definition | +| ------ | ---------- | +| Choice | A choice is a value a user can select. A choice would be equivelant to the `` element within a select input. | +| Group | A group is a collection of choices. A group should be seen as equivalent to a `` element within a select input.| +| Item | An item is an inputted value (if you are using Choices with a text input) or a selected choice (if you are using Choices with a select element). | ## Options -#### items -Type: `Array` Default: `[]` +### items +Type: Default: `[]` Usage: Add pre-selected items to input. @@ -68,87 +103,89 @@ Pass an array of objects: }] ``` -#### addItems +### maxItemCount +Type: `Number` Default:`-1` + +Usage: The amount of items a user can input/select ("-1" indicates no limit). + +### addItems Type: `Boolean` Default:`true` -Usage: Whether a user can add items. +Usage: Whether a user can add items to the passed input's value. -#### removeItems +### removeItems Type: `Boolean` Default:`true` Usage: Whether a user can remove items (only affects text and multiple select input types). -#### removeButton +### removeButton Type: `Boolean` Default:`false` Usage: Whether a button should show that, when clicked, will remove an item (only affects text and multiple select input types). -#### editItems +### editItems Type: `Boolean` Default:`false` Usage: Whether a user can edit selected items (only affects text input types). -#### maxItems -Type: `Boolean` Default:`null` +Usage: Optionally set an item limit (`-1` indicates no limit). -Usage: Optionally set an item limit. - -#### delimiter +### delimiter Type: `String` Default:`,` Usage: What divides each value (only affects text input types). -#### allowDuplicates +### allowDuplicates Type: `Boolean` Default:`true` Usage: Whether a user can input a duplicate item (only affects text input types). -#### allowPaste +### allowPaste Type: `Boolean` Default:`true` Usage: Whether a user can paste into the input. -#### allowSearch +### allowSearch Type: `Boolean` Default:`true` Usage: Whether a user can filter options by searching (only affects select input types). -#### regexFilter +### regexFilter Type: `Regex` Default:`null` Usage: A filter that will need to pass for a user to successfully add an item (only affects text input types). -#### placeholder +### placeholder Type: `Boolean` Default:`true` Usage: Whether the input should show a placeholder. Used in conjunction with `placeholderValue`. If `placeholder` is set to true and no value is passed to `placeholderValue`, the passed input's placeholder attribute will be used as the placeholder value. -#### placeholderValue +### placeholderValue Type: `String` Default:`null` Usage: The value of the inputs placeholder. -#### prependValue +### prependValue Type: `String` Default:`null` Usage: Prepend a value to each item added to input (only affects text input types). -#### appendValue +### appendValue Type: `String` Default:`null` Usage: Append a value to each item added to input (only affects text input types). -#### highlightAll +### highlightAll Type: `Boolean` Default:`true` Usage: Whether a user can highlight items. -#### loadingText +### loadingText Type: `String` Default:`Loading...` Usage: The loading text that is shown when options are populated via an AJAX callback. -#### classNames +### classNames Type: `Object` Default: ``` @@ -181,72 +218,86 @@ classNames: { Usage: Classes added to HTML generated by Choices. -#### callbackOnInit +### callbackOnInit Type: `Function` Default:`() => {}` Usage: Function to run once Choices initialises. -#### callbackOnAddItem +### callbackOnAddItem Type: `Function` Default:`(id, value, passedInput) => {}` Usage: Function to run each time an item is added. -#### callbackOnRemoveItem +### callbackOnRemoveItem Type: `Function` Default:`(id, value, passedInput) => {}` Usage: Function to run each time an item is removed. ## Methods -#### highlightAll(); +Methods can be called either directly or by chaining: + +```js +// Calling a method by chaining +const choices = new Choices(element, { + addItems: false, + removeItems: false, +}).setValue(['Set value 1', 'Set value 2']).disable(); + +// Calling a method directly +choices.setValue(['Set value 1', 'Set value 2']) +choices.disable(); +``` + +### highlightAll(); Usage: Highlight each chosen item (selected items can be removed). -#### unhighlightAll(); +### unhighlightAll(); Usage: Un-highlight each chosen item. -#### removeItemsByValue(value); +### removeItemsByValue(value); Usage: Remove each item by a given value. -#### removeActiveItems(excludedId); +### removeActiveItems(excludedId); Usage: Remove each selectable item. -#### removeSelectedItems(); +### removeSelectedItems(); Usage: Remove each item the user has selected. -#### showDropdown(); -Usage: Show option list dropdown. +### showDropdown(); +Usage: Show option list dropdown (only affects select inputs). -#### hideDropdown(); -Usage: Hide option list dropdown. +### hideDropdown(); +Usage: Hide option list dropdown (only affects select inputs). -#### toggleDropdown(); +### toggleDropdown(); Usage: Toggle dropdown between showing/hidden. -#### setValue(args); -Usage: Set value of input based on an array of objects or strings. +### setValue(args); +Usage: Set value of input based on an array of objects or strings. This behaves exactly the same as passing items via the `items` option but can be called after initialising Choices on an text input (only affects text inputs). -#### clearValue(); +### clearValue(); Usage: Clear value of input. -#### clearInput(); -Usage: Clear input. +### clearInput(); +Usage: Clear input of any user inputted text (only affects text inputs). -#### disable(); +### disable(); Usage: Disable input from selecting further options. -#### ajax(fn); +### ajax(fn); Usage: Populate options via a callback. @@ -259,10 +310,12 @@ To setup a local environment: clone this repo, navigate into it's directory in a ```npm install``` ### NPM tasks -* ```npm start``` -* ```npm run js:build``` -* ```npm run css:watch``` -* ```npm run css:build``` +| Task | Usage | +| ------------------- | ------------------------------------------------------------ | +| `npm start` | Fire up local server for development | +| `npm run js:build` | Compile Choices to an uglified JavaScript file | +| `npm run css:watch` | Watch SCSS files for changes. On a change, run build process | +| `npm run css:build` | Compile, minify and prefix SCSS files to CSS | ## Contributions In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using npm scripts...bla bla bla diff --git a/assets/scripts/dist/choices.min.js b/assets/scripts/dist/choices.min.js index a4d82d6..9f86028 100644 --- a/assets/scripts/dist/choices.min.js +++ b/assets/scripts/dist/choices.min.js @@ -1,2 +1,2 @@ -!function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var i={};return e.m=t,e.c=i,e.p="/assets/scripts/dist/",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e1)for(var s=1;s=document.body.offsetHeight;return e?this.containerOuter.classList.add(this.options.classNames.flippedState):this.containerOuter.classList.remove(this.options.classNames.flippedState),this}},{key:"hideDropdown",value:function(){var t=this.containerOuter.classList.contains(this.options.classNames.flippedState);return this.containerOuter.classList.remove(this.options.classNames.openState),this.dropdown.classList.remove(this.options.classNames.activeState),t&&this.containerOuter.classList.remove(this.options.classNames.flippedState),this}},{key:"toggleDropdown",value:function(){var t=this.dropdown.classList.contains(this.options.classNames.activeState);return t?this.hideDropdown():this.showDropdown(),this}},{key:"setValue",value:function(t){var e=this,i=[].concat(s(t));return i.forEach(function(t,i){if((0,l.isType)("Object",t)){if(!t.value)return;"text"!==e.passedElement.type?e._addOption(!0,!1,t.value,t.label,-1):e._addItem(t.value,t.label,t.id)}else(0,l.isType)("String",t)&&("text"!==e.passedElement.type?e._addOption(!0,!1,t,t,-1):e._addItem(t))}),this}},{key:"clearValue",value:function(){return this.store.dispatch((0,a.clearAll)()),this}},{key:"disable",value:function(){return this.passedElement.disabled=!0,this.initialised&&(this.input.disabled=!0,this.containerOuter.classList.add(this.options.classNames.disabledState)),this}},{key:"ajax",value:function(t){var e=this;this.containerOuter.classList.add("is-loading");var i=this._getTemplate("item",{id:-1,value:"Loading",label:this.options.loadingText,active:!0});this.itemList.appendChild(i);var n=function(t,i,n){t&&t.length&&(e.containerOuter.classList.remove("is-loading"),e.input.placeholder="",t.forEach(function(t,s){0===s&&e._addItem(t[i],t[n],s),e._addOption(!1,!1,t[i],t[n])}))};return t(n),this}},{key:"clearInput",value:function(){return this.input.value&&(this.input.value=""),"select-one"!==this.passedElement.type&&(this.input.style.width=(0,l.getWidthOfInput)(this.input)),this}},{key:"_handleEnter",value:function(t,e){var i=!0;if(this.options.addItems?this.options.maxItems&&this.options.maxItems<=this.itemList.children.length?i=!1:this.options.allowDuplicates===!1&&this.passedElement.value&&(i=!t.some(function(t){return t.value===e})):i=!1,i){var n=!0;this.options.regexFilter&&(n=this._regexFilter(e)),n&&(this.toggleDropdown(),this._addItem(e),this.clearInput(this.passedElement))}}},{key:"_handleBackspace",value:function(t){if(this.options.removeItems&&t){var e=t[t.length-1],i=t.some(function(t){return t.selected===!0});this.options.editItems&&!i&&e?(this.input.value=e.value,this._removeItem(e)):(i||this.selectItem(e),this.removeSelectedItems())}}},{key:"_onKeyDown",value:function(t){if(t.target===this.input){var e=t.ctrlKey||t.metaKey,i=46,n=8,s=13,o=65,r=27,c=38,u=40,d=this.store.getItemsFilteredByActive(),h=(this.store.getOptionsFilteredByActive(),this.input===document.activeElement),p=this.dropdown.classList.contains(this.options.classNames.activeState),f=this.itemList&&this.itemList.children,v=String.fromCharCode(event.keyCode);switch("text"!==this.passedElement.type&&/[a-zA-Z0-9-_ ]/.test(v)&&!p&&this.showDropdown(),this.canSearch=this.options.allowSearch,t.keyCode){case o:e&&f&&(this.canSearch=!1,this.options.removeItems&&!this.input.value&&this.options.highlightAll&&this.input===document.activeElement&&this.highlightAll(this.itemList.children));break;case s:if(t.target.value&&"text"===this.passedElement.type){var m=this.input.value;this._handleEnter(d,m)}if(p){var g=this.dropdown.querySelector("."+this.options.classNames.highlightedState);if(g){var y=g.getAttribute("data-value"),b=g.innerHTML,_=g.getAttribute("data-id");this._addItem(y,b,_),this.clearInput(this.passedElement),"select-one"===this.passedElement.type&&(this.isSearching=!1,this.store.dispatch((0,a.activateOptions)()),this.toggleDropdown())}}break;case r:p&&this.toggleDropdown();break;case u:case c:if(p){var E=this.dropdown.querySelector("."+this.options.classNames.highlightedState),I=t.keyCode===u?1:-1,w=void 0;this.canSearch=!1,w=E?(0,l.getAdjacentEl)(E,"[data-option-selectable]",I):this.dropdown.querySelector("[data-option-selectable]"),w&&((0,l.isScrolledIntoView)(w,this.optionList,I)||this._scrollToOption(w,I),this._highlightOption(w)),t.preventDefault()}break;case i:case n:h&&!t.target.value&&"select-one"!==this.passedElement.type&&(this._handleBackspace(d),t.preventDefault())}}}},{key:"_onKeyUp",value:function(t){var e=this;if(t.target===this.input){var i=String.fromCharCode(event.keyCode);if("text"===this.passedElement.type){var n=this.dropdown.classList.contains(this.options.classNames.activeState),s=void 0;if(this.input.value){var o=this.store.getItemsFilteredByActive(),r=!o.some(function(t){return t.value===e.input.value});s=this.options.maxItems&&this.options.maxItems<=this.itemList.children.length?this._getTemplate("notice","Only "+this.options.maxItems+" options can be added."):this.options.allowDuplicates||r?this._getTemplate("notice",'Add "'+this.input.value+'"'):this._getTemplate("notice","Only unique values can be added."),(this.options.regexFilter&&this._regexFilter(this.input.value)||!this.options.regexFilter)&&(this.dropdown.innerHTML=s.outerHTML,this.dropdown.classList.contains(this.options.classNames.activeState)||this.showDropdown())}else n&&this.hideDropdown()}if(this.canSearch&&this.input===document.activeElement){var l=this.store.getOptions(),c=l.some(function(t){return t.active!==!0});if(this.input.value&&l.length&&/[a-zA-Z0-9-_ ]/.test(i)){var d=function(){var t=e.input.value.trim(),i=e.currentValue.trim();if(t.length>=1&&t!==i+" "){var n=e.store.getOptionsFiltedBySelectable(),s=t,o=new u.default(n,{keys:["label","value"],shouldSort:!0,include:"score"}),r=o.search(s);e.currentValue=t,e.highlightPosition=0,e.isSearching=!0,e.store.dispatch((0,a.filterOptions)(r))}};d()}else c&&(this.isSearching=!1,this.store.dispatch((0,a.activateOptions)()))}}}},{key:"_onInput",value:function(t){"select-one"!==this.passedElement.type&&(this.input.style.width=(0,l.getWidthOfInput)(this.input))}},{key:"_onMouseDown",value:function(t){var e=this;if(2!==t.button){var i=this.store.getItemsFilteredByActive();if(this.containerOuter.contains(t.target))!function(){t.preventDefault();var n=!!t.shiftKey;"text"===e.passedElement.type||e.dropdown.classList.contains(e.options.classNames.activeState)||e.showDropdown(),e.input!==document.activeElement&&e.input.focus(),t.target.hasAttribute("data-button")?e.options.removeItems&&e.options.removeButton&&!function(){var n=t.target.parentNode.getAttribute("data-id"),s=i.find(function(t){return t.id===parseInt(n)});e._removeItem(s)}():t.target.hasAttribute("data-item")?e.options.removeItems&&!function(){var s=t.target.getAttribute("data-id");i.forEach(function(t){t.id!==parseInt(s)||t.selected?n||e.deselectItem(t):e.selectItem(t)})}():t.target.hasAttribute("data-option")&&!function(){var i=e.store.getOptionsFilteredByActive(),n=t.target.getAttribute("data-id"),s=i.find(function(t){return t.id===parseInt(n)});s.selected||s.disabled||(e._addItem(s.value,s.label,s.id),"select-one"===e.passedElement.type&&(e.input.value="",e.isSearching=!1,e.store.dispatch((0,a.activateOptions)(!0)),e.toggleDropdown()))}()}();else{var n=this.dropdown.classList.contains(this.options.classNames.activeState),s=i.some(function(t){return t.selected===!0});s&&this.unhighlightAll(),this.containerOuter.classList.remove(this.options.classNames.focusState),n&&this.toggleDropdown()}}}},{key:"_onMouseOver",value:function(t){(t.target===this.dropdown||(0,l.findAncestor)(t.target,this.options.classNames.listDropdown))&&t.target.hasAttribute("data-option")&&this._highlightOption(t.target)}},{key:"_onPaste",value:function(t){t.target===this.input&&(this.options.allowPaste||t.preventDefault())}},{key:"_onFocus",value:function(t){var e=this.dropdown.classList.contains(this.options.classNames.activeState);t.target!==this.input||e||(this.containerOuter.classList.add(this.options.classNames.focusState),"select-one"!==this.passedElement.type&&"select-multiple"!==this.passedElement.type||this.showDropdown())}},{key:"_onBlur",value:function(t){var e=this.dropdown.classList.contains(this.options.classNames.activeState);t.target!==this.input||e?this.hideDropdown():this.containerOuter.classList.remove(this.options.classNames.focusState)}},{key:"_regexFilter",value:function(t){if(t){var e=new RegExp(this.options.regexFilter,"i");return e.test(t)}}},{key:"_scrollToOption",value:function(t,e){var i=this;if(t){var n=this.optionList.offsetHeight,s=t.offsetHeight,o=t.offsetTop+s,r=this.optionList.scrollTop+n,a=e>0?this.optionList.scrollTop+o-r:t.offsetTop,l=function c(t,e,n){var s=!1,o=void 0,r=void 0,a=4;n>0?(o=(e-i.optionList.scrollTop)/a,r=o>1?o:1,i.optionList.scrollTop=i.optionList.scrollTop+r,i.optionList.scrollTop1?o:1,i.optionList.scrollTop=i.optionList.scrollTop-r,i.optionList.scrollTop>e&&(s=!0)),s&&requestAnimationFrame(function(t){c(t,e,n)})};requestAnimationFrame(function(t){l(t,a,e)})}}},{key:"_highlightOption",value:function(t){var e=this,i=Array.from(this.dropdown.querySelectorAll("[data-option-selectable]"));if(i.length){var n=Array.from(this.dropdown.querySelectorAll("."+this.options.classNames.highlightedState));if(n.forEach(function(t){t.classList.remove(e.options.classNames.highlightedState)}),t)t.classList.add(this.options.classNames.highlightedState),this.highlightPosition=i.indexOf(t);else{var s=void 0;s=i.length>this.highlightPosition?i[this.highlightPosition]:i[i.length-1],s||(s=i[0]),s.classList.add(this.options.classNames.highlightedState)}}}},{key:"_addItem",value:function(t,e){var i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3],s=this.store.getItems(),o=t.trim(),r=e||o,c=i||-1;this.options.prependValue&&(o=this.options.prependValue+o.toString()),this.options.appendValue&&(o+=this.options.appendValue.toString());var u=s?s.length+1:1;return this.store.dispatch((0,a.addItem)(o,r,u,c)),"select-one"===this.passedElement.type&&this.removeActiveItems(u),n&&((0,l.isType)("Function",n)?n(u,o,this.passedElement):console.error("callbackOnAddItem: Callback is not a function")),this}},{key:"_removeItem",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?this.options.callbackOnRemoveItem:arguments[1];if(!t||!(0,l.isType)("Object",t))return void console.error("removeItem: No item object was passed to be removed");var i=t.id,n=(t.value,t.optionId);return this.store.dispatch((0,a.removeItem)(i,n)),e?void((0,l.isType)("Function",e)||console.error("callbackOnRemoveItem: Callback is not a function")):this}},{key:"_addOption",value:function(t,e,i,n){var s=arguments.length<=4||void 0===arguments[4]?-1:arguments[4];if(i){n||(n=i);var o=this.store.getOptions(),r=o.length+1;this.store.dispatch((0,a.addOption)(i,n,r,s,e)),t&&!e&&this._addItem(i,n,r)}}},{key:"_addGroup",value:function(t,e,i){var n=this,s=Array.from(t.getElementsByTagName("OPTION")),o=e;s?(this.store.dispatch((0,a.addGroup)(t.label,o,!0,t.disabled)),s.forEach(function(t,e){var i=t.disabled||t.parentNode.disabled;n._addOption(t.selected,i,t.value,t.innerHTML,o)})):this.store.dispatch((0,a.addGroup)(t.label,t.id,!1,t.disabled))}},{key:"_getTemplate",value:function(t){if(t){for(var e=this.options.templates,i=arguments.length,n=Array(i>1?i-1:0),s=1;i>s;s++)n[s-1]=arguments[s];return e[t].apply(e,n)}}},{key:"_createTemplates",value:function(){var t=this,e=this.options.classNames,i={containerOuter:function(){return(0,l.strToEl)('
')},containerInner:function(){return(0,l.strToEl)('
')},itemList:function(){return(0,l.strToEl)('
')},optionList:function(){return(0,l.strToEl)('
')},input:function(){return(0,l.strToEl)('')},dropdown:function(){return(0,l.strToEl)('
')},notice:function(t,i){return(0,l.strToEl)('
'+t+"
")},selectOption:function(t){return(0,l.strToEl)('")},option:function(t){return(0,l.strToEl)('\n
\n '+t.label+"\n
\n ")},optgroup:function(t){return(0,l.strToEl)('\n
\n
'+t.value+"
\n
\n ")},item:function(i){return t.options.removeButton&&"select-one"!==t.passedElement.type?(0,l.strToEl)('\n
\n '+i.label+'\n \n
\n '):(0,l.strToEl)('\n
\n '+i.label+"\n
\n ")}};this.options.templates=(0,l.extend)(this.options.templates,i)}},{key:"_createInput",value:function(){var t=this,e=this._getTemplate("containerOuter"),i=this._getTemplate("containerInner"),n=this._getTemplate("itemList"),s=this._getTemplate("optionList"),o=this._getTemplate("input"),r=this._getTemplate("dropdown");if(this.containerOuter=e,this.containerInner=i,this.input=o,this.optionList=s,this.itemList=n,this.dropdown=r,this.passedElement.classList.add(this.options.classNames.input,this.options.classNames.hiddenState),this.passedElement.tabIndex="-1",this.passedElement.setAttribute("style","display:none;"),this.passedElement.setAttribute("aria-hidden","true"),this.passedElement.removeAttribute("data-choice"),(0,l.wrap)(this.passedElement,i),(0,l.wrap)(i,e),this.options.placeholder&&(this.options.placeholderValue||this.passedElement.placeholder)){var a=this.options.placeholderValue||this.passedElement.placeholder;o.placeholder=a,"select-one"!==this.passedElement.type&&(o.style.width=(0,l.getWidthOfInput)(o))}if(this.options.addItems||this.disable(),e.appendChild(i),e.appendChild(r),i.appendChild(n),r.appendChild(s),"select-multiple"===this.passedElement.type||"text"===this.passedElement.type?i.appendChild(o):this.options.allowSearch&&r.insertBefore(o,r.firstChild),"select-multiple"===this.passedElement.type||"select-one"===this.passedElement.type){this.highlightPosition=0;var c=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(this.isSearching=!1,c&&c.length)c.forEach(function(e,i){var n=0===i;t._addGroup(e,i,n)});else{var u=Array.from(this.passedElement.options);u.forEach(function(e){var i=e.disabled||e.parentNode.disabled;t._addOption(e.selected,i,e.value,e.innerHTML)})}}else"text"===this.passedElement.type&&this.presetItems.forEach(function(e){if((0,l.isType)("Object",e)){if(!e.value)return;t._addItem(e.value,e.label,e.id)}else(0,l.isType)("String",e)&&t._addItem(e)})}},{key:"renderGroups",value:function(t,e,i){var n=this,s=i||document.createDocumentFragment();return t.forEach(function(t,i){var o=e.filter(function(e){return"select-one"===n.passedElement.type?e.groupId===t.id:e.groupId===t.id&&!e.selected});if(o.length>=1){var r=n._getTemplate("optgroup",t);s.appendChild(r),n.renderOptions(o,s)}}),s}},{key:"renderOptions",value:function(t,e){var i=this,n=e||document.createDocumentFragment();return t.forEach(function(t,e){var s=i._getTemplate("option",t);"select-one"===i.passedElement.type?n.appendChild(s):t.selected||n.appendChild(s)}),n}},{key:"renderItems",value:function(t,e){var i=this,n=e||document.createDocumentFragment(),s=this.store.getItemsReducedToValues(t);return"text"===this.passedElement.type?this.passedElement.setAttribute("value",s.join(this.options.delimiter)):!function(){var e=document.createDocumentFragment();t.forEach(function(t){var n=i._getTemplate("selectOption",t);e.appendChild(n)}),i.passedElement.innerHTML="",i.passedElement.appendChild(e)}(),t.forEach(function(t){var e=i._getTemplate("item",t);n.appendChild(e)}),n}},{key:"render",value:function(){if(this.currentState=this.store.getState(),this.currentState!==this.prevState){if(!(this.currentState.options===this.prevState.options&&this.currentState.groups===this.prevState.groups||"select-multiple"!==this.passedElement.type&&"select-one"!==this.passedElement.type)){var t=this.store.getGroupsFilteredByActive(),e=this.store.getOptionsFilteredByActive(),i=document.createDocumentFragment();if(this.optionList.innerHTML="",t.length>=1&&this.isSearching!==!0?i=this.renderGroups(t,e,i):e.length>=1&&(i=this.renderOptions(e,i)),i.children.length)this.optionList.appendChild(i),this._highlightOption();else{var n=this.isSearching?this._getTemplate("notice","No results found"):this._getTemplate("notice","No options to select");this.optionList.appendChild(n)}}if(this.currentState.items!==this.prevState.items){var s=this.store.getItemsFilteredByActive();if(s){var o=this.renderItems(s);this.itemList.innerHTML="",o.children.length&&this.itemList.appendChild(o)}}this.prevState=this.currentState}}},{key:"_addEventListeners",value:function(){document.addEventListener("keyup",this._onKeyUp),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("mousedown",this._onMouseDown),document.addEventListener("mouseover",this._onMouseOver),this.input.addEventListener("input",this._onInput),this.input.addEventListener("paste",this._onPaste),this.input.addEventListener("focus",this._onFocus),this.input.addEventListener("blur",this._onBlur)}},{key:"_removeEventListeners",value:function(){document.removeEventListener("keyup",this._onKeyUp),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("mousedown",this._onMouseDown),document.removeEventListener("mouseover",this._onMouseOver),this.input.removeEventListener("input",this._onInput),this.input.removeEventListener("paste",this._onPaste),this.input.removeEventListener("focus",this._onFocus),this.input.removeEventListener("blur",this._onBlur)}}]),t}();window.Choices=t.exports=p},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.addItem=function(t,e,i,n){return{type:"ADD_ITEM",value:t,label:e,id:i,optionId:n}},e.removeItem=function(t,e){return{type:"REMOVE_ITEM",id:t,optionId:e}},e.selectItem=function(t,e){return{type:"SELECT_ITEM",id:t,selected:e}},e.addOption=function(t,e,i,n,s){return{type:"ADD_OPTION",value:t,label:e,id:i,groupId:n,disabled:s}},e.filterOptions=function(t){return{type:"FILTER_OPTIONS",results:t}},e.activateOptions=function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];return{type:"ACTIVATE_OPTIONS",active:t}},e.addGroup=function(t,e,i,n){return{type:"ADD_GROUP",value:t,id:e,active:i,disabled:n}},e.clearAll=function(){return{type:"CLEAR_ALL"}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=(e.hasClass=function(t,e){return new RegExp(" "+e+" ").test(" "+t.className+" ")},e.capitalise=function(t){return t.replace(/\w\S*/g,function(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()})},e.isType=function(t,e){var i=Object.prototype.toString.call(e).slice(8,-1);return void 0!==e&&null!==e&&i===t}),n=(e.extend=function o(){for(var t={},e=!1,n=arguments.length,s=function(n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e&&i("Object",n[s])?t[s]=o(!0,t[s],n[s]):t[s]=n[s])},r=0;n>r;r++){var a=arguments[r];i("Object",a)?s(a):console.error("Custom options must be an object")}return t},e.whichTransitionEvent=function(){var t,e=document.createElement("fakeelement"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in i)if(void 0!==e.style[t])return i[t]},e.whichAnimationEvent=function(){var t,e=document.createElement("fakeelement"),i={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in i)if(void 0!==e.style[t])return i[t]}),s=(e.getParentsUntil=function(t,e,i){for(var n=[];t&&t!==document;t=t.parentNode){if(e){var s=e.charAt(0);if("."===s&&t.classList.contains(e.substr(1)))break;if("#"===s&&t.id===e.substr(1))break;if("["===s&&t.hasAttribute(e.substr(1,e.length-1)))break;if(t.tagName.toLowerCase()===e)break}if(i){var o=i.charAt(0);"."===o&&t.classList.contains(i.substr(1))&&n.push(t),"#"===o&&t.id===i.substr(1)&&n.push(t),"["===o&&t.hasAttribute(i.substr(1,i.length-1))&&n.push(t),t.tagName.toLowerCase()===i&&n.push(t)}else n.push(t)}return 0===n.length?null:n},e.wrap=function(t,e){return e=e||document.createElement("div"),t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e),e.appendChild(t)},e.getSiblings=function(t){for(var e=[],i=t.parentNode.firstChild;i;i=i.nextSibling)1===i.nodeType&&i!==t&&e.push(i);return e},e.findAncestor=function(t,e){for(;(t=t.parentElement)&&!t.classList.contains(e););return t},e.debounce=function(t,e,i){var n;return function(){var s=this,o=arguments,r=function(){n=null,i||t.apply(s,o)},a=i&&!n;clearTimeout(n),n=setTimeout(r,e),a&&t.apply(s,o)}},e.getElemDistance=function(t){var e=0;if(t.offsetParent)do e+=t.offsetTop,t=t.offsetParent;while(t);return e>=0?e:0},e.getElementOffset=function(t,e){var i=e;return i>1&&(i=1),i>0&&(i=0),Math.max(t.offsetHeight*i)},e.getAdjacentEl=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t&&e){var n=t.parentNode.parentNode,s=Array.from(n.querySelectorAll(e)),o=s.indexOf(t),r=i>0?1:-1;return s[o+r]}},e.getScrollPosition=function(t){return"bottom"===t?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},e.isInView=function(t,e,i){return this.getScrollPosition(e)>this.getElemDistance(t)+this.getElementOffset(t,i)},e.isScrolledIntoView=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t){var n=void 0;return n=i>0?e.scrollTop+e.offsetHeight>=t.offsetTop+t.offsetHeight:t.offsetTop>=e.scrollTop}},e.stripHTML=function(t){var e=document.createElement("DIV");return e.innerHTML=t,e.textContent||e.innerText||""},e.addAnimation=function(t,e){var i=n(),s=function o(){t.classList.remove(e),t.removeEventListener(i,o,!1)};t.classList.add(e),t.addEventListener(i,s,!1)},e.getRandomNumber=function(t,e){return Math.floor(Math.random()*(e-t)+t)},e.strToEl=function(){var t=document.createElement("div");return function(e){var i;for(t.innerHTML=e,i=t.children[0];t.firstChild;)t.removeChild(t.firstChild);return i}}());e.getWidthOfInput=function(t){var e=t.value||t.placeholder,i=t.offsetWidth;if(e){var n=s(""+e+"");n.style.position="absolute",n.style.padding="0",n.style.top="-9999px",n.style.left="-9999px",n.style.width="auto",n.style.whiteSpace="pre",document.body.appendChild(n),e&&n.offsetWidth!==t.offsetWidth&&(i=n.offsetWidth+4),document.body.removeChild(n)}return i+"px"}},function(t,e,i){!function(e){"use strict";function i(){console.log.apply(console,arguments)}function n(t,e){var i,n,s,o;for(this.list=t,this.options=e=e||{},i=0,o=["sort","shouldSort","verbose","tokenize"],n=o.length;n>i;i++)s=o[i],this.options[s]=s in e?e[s]:l[s];for(i=0,o=["searchFn","sortFn","keys","getFn","include"],n=o.length;n>i;i++)s=o[i],this.options[s]=e[s]||l[s]}function s(t,e,i){var n,r,a,l,c,u;if(e){if(a=e.indexOf("."),-1!==a?(n=e.slice(0,a),r=e.slice(a+1)):n=e,l=t[n],null!==l&&void 0!==l)if(r||"string"!=typeof l&&"number"!=typeof l)if(o(l))for(c=0,u=l.length;u>c;c++)s(l[c],r,i);else r&&s(l,r,i);else i.push(l)}else i.push(t);return i}function o(t){return"[object Array]"===Object.prototype.toString.call(t)}function r(t,e){e=e||{},this.options=e,this.options.location=e.location||r.defaultOptions.location,this.options.distance="distance"in e?e.distance:r.defaultOptions.distance,this.options.threshold="threshold"in e?e.threshold:r.defaultOptions.threshold,this.options.maxPatternLength=e.maxPatternLength||r.defaultOptions.maxPatternLength,this.pattern=e.caseSensitive?t:t.toLowerCase(),this.patternLen=t.length,this.patternLen<=this.options.maxPatternLength&&(this.matchmask=1<s;s++)this.tokenSearchers.push(new i(n[s],t));this.fullSeacher=new i(e,t)},n.prototype._startSearch=function(){var t,e,i,n,s=this.options,o=s.getFn,r=this.list,a=r.length,l=this.options.keys,c=l.length,u=null;if("string"==typeof r[0])for(i=0;a>i;i++)this._analyze("",r[i],i,i);else for(this._keyMap={},i=0;a>i;i++)for(u=r[i],n=0;c>n;n++){if(t=l[n],"string"!=typeof t){if(e=1-t.weight||1,this._keyMap[t.name]={weight:e},t.weight<=0||t.weight>1)throw new Error("Key weight has to be > 0 and <= 1");t=t.name}else this._keyMap[t]={weight:1};this._analyze(t,o(u,t,[]),u,i)}},n.prototype._analyze=function(t,e,n,s){var r,l,c,u,d,h,p,f,v,m,g,y,b,_,E,I=this.options,w=!1;if(void 0!==e&&null!==e)if(l=[],"string"==typeof e){if(r=e.split(a),I.verbose&&i("---------\nKey:",t),I.verbose&&i("Record:",r),this.options.tokenize){ -for(c=this.tokenSearchers,u=c.length,_=0;__;_++)h+=l[_];h/=f,I.verbose&&i("Token score average:",h)}v=this.fullSeacher.search(e),I.verbose&&i("Full text score:",v.score),p=v.score,void 0!==h&&(p=(p+h)/2),I.verbose&&i("Score average:",p),(w||v.isMatch)&&(d=this.resultMap[s],d?d.output.push({key:t,score:p,matchedIndices:v.matchedIndices}):(this.resultMap[s]={item:n,output:[{key:t,score:p,matchedIndices:v.matchedIndices}]},this.results.push(this.resultMap[s])))}else if(o(e))for(_=0;_e;e++)r=s[e].score,a=u?u[s[e].key].weight:1,c=r*a,1!==a?l=Math.min(l,c):(n+=c,s[e].nScore=c);1===l?d[t].score=n/o:d[t].score=l,this.options.verbose&&i(d[t])}},n.prototype._sort=function(){var t=this.options;t.shouldSort&&(t.verbose&&i("\n\nSorting...."),this.results.sort(t.sortFn))},n.prototype._format=function(){var t,e,n,s,o,r=this.options,a=r.getFn,l=[],c=this.results,u=r.include;for(r.verbose&&i("\n\nOutput:\n\n",c),s=r.id?function(t){c[t].item=a(c[t].item,r.id,[])[0]}:function(){},o=function(t){var e,i,n,s,o,r=c[t];if(u.length>0){if(e={item:r.item},-1!==u.indexOf("matches"))for(n=r.output,e.matches=[],i=0;ie;e++)s(e),t=o(e),l.push(t);return l},r.defaultOptions={location:0,distance:100,threshold:.6,maxPatternLength:32},r.prototype._calculatePatternAlphabet=function(){var t={},e=0;for(e=0;eS.maxPatternLength){if(y=t.match(new RegExp(this.pattern.replace(a,"|"))),b=!!y)for(E=[],e=0,I=y.length;I>e;e++)w=y[e],E.push([t.indexOf(w),w.length-1]);return{isMatch:b,score:b?.5:1,matchedIndices:E}}for(s=S.location,n=t.length,o=S.threshold,r=t.indexOf(this.pattern,s),_=[],e=0;n>e;e++)_[e]=0;for(-1!=r&&(o=Math.min(this._bitapScore(0,r),o),r=t.lastIndexOf(this.pattern,s+this.patternLen),-1!=r&&(o=Math.min(this._bitapScore(0,r),o))),r=-1,m=1,g=[],u=this.patternLen+n,e=0;el;)this._bitapScore(e,s+c)<=o?l=c:u=c,c=Math.floor((u-l)/2+l);for(u=c,d=Math.max(1,s-c+1),h=Math.min(s+c,n)+this.patternLen,p=Array(h+2),p[h+1]=(1<=d;i--)if(v=this.patternAlphabet[t.charAt(i-1)],v&&(_[i-1]=1),0===e?p[i]=(p[i+1]<<1|1)&v:p[i]=(p[i+1]<<1|1)&v|((f[i+1]|f[i])<<1|1)|f[i+1],p[i]&this.matchmask&&(m=this._bitapScore(e,i-1),o>=m)){if(o=m,r=i-1,g.push(r),!(r>s))break;d=Math.max(1,2*s-r)}if(this._bitapScore(e+1,s)>o)break;f=p}return E=this._getMatchedIndices(_),{isMatch:r>=0,score:0===m?.001:m,matchedIndices:E}},r.prototype._getMatchedIndices=function(t){for(var e,i=[],n=-1,s=-1,o=0,r=r=t.length;r>o;o++)e=t[o],e&&-1===n?n=o:e||-1===n||(s=o-1,i.push([n,s]),n=-1);return t[o-1]&&i.push([n,o-1]),i},t.exports=n}(this)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Store=void 0;var o=function(){function t(t,e){for(var i=0;ii;i++)e[i]=arguments[i];return function(t){return function(i,n,s){var r=t(i,n,s),l=r.dispatch,c=[],u={getState:r.getState,dispatch:function(t){return l(t)}};return c=e.map(function(t){return t(u)}),l=a.default.apply(void 0,c)(r.dispatch),o({},r,{dispatch:l})}}}var o=Object.assign||function(t){for(var e=1;ei;i++)e[i]=arguments[i];return function(){if(0===e.length)return arguments.length<=0?void 0:arguments[0];var t=e[e.length-1],i=e.slice(0,-1);return i.reduceRight(function(t,e){return e(t)},t.apply(void 0,arguments))}}e.__esModule=!0,e.default=i},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var s=i(6),o=i(18),r=n(o),a=i(19),l=n(a),c=i(20),u=n(c),d=(0,s.combineReducers)({items:r.default,groups:l.default,options:u.default}),h=function(t,e){return"CLEAR_ALL"===e.type&&(t=void 0),d(t,e)};e.default=h},function(t,e){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e-1?t.map(function(t){return t.id===parseInt(e.optionId)&&(t.selected=!0),t}):t;case"REMOVE_ITEM":return e.optionId>-1?t.map(function(t){return t.id===parseInt(e.optionId)&&(t.selected=!1),t}):t;case"FILTER_OPTIONS":var n=e.results,s=t.map(function(t,e){return t.active=n.some(function(e){return e.item.id===t.id?(t.score=e.score,!0):void 0}),t}).sort(function(t,e){return t.score-e.score});return s;case"ACTIVATE_OPTIONS":return t.map(function(t){return t.active=e.active,t});default:return t}};e.default=n}]); \ No newline at end of file +!function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var i={};return e.m=t,e.c=i,e.p="/assets/scripts/dist/",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e1)for(var s=1;s=document.body.offsetHeight;return e?this.containerOuter.classList.add(this.options.classNames.flippedState):this.containerOuter.classList.remove(this.options.classNames.flippedState),this}},{key:"hideDropdown",value:function(){var t=this.containerOuter.classList.contains(this.options.classNames.flippedState);return this.containerOuter.classList.remove(this.options.classNames.openState),this.dropdown.classList.remove(this.options.classNames.activeState),t&&this.containerOuter.classList.remove(this.options.classNames.flippedState),this}},{key:"toggleDropdown",value:function(){var t=this.dropdown.classList.contains(this.options.classNames.activeState);return t?this.hideDropdown():this.showDropdown(),this}},{key:"setValue",value:function(t){var e=this,i=[].concat(s(t));return i.forEach(function(t,i){if((0,c.isType)("Object",t)){if(!t.value)return;"text"!==e.passedElement.type?e._addChoice(!0,!1,t.value,t.label,-1):e._addItem(t.value,t.label,t.id)}else(0,c.isType)("String",t)&&("text"!==e.passedElement.type?e._addChoice(!0,!1,t,t,-1):e._addItem(t))}),this}},{key:"clearValue",value:function(){return this.store.dispatch((0,a.clearAll)()),this}},{key:"disable",value:function(){return this.passedElement.disabled=!0,this.initialised&&(this.input.disabled=!0,this.containerOuter.classList.add(this.options.classNames.disabledState)),this}},{key:"ajax",value:function(t){var e=this;this.containerOuter.classList.add("is-loading");var i=this._getTemplate("item",{id:-1,value:"Loading",label:this.options.loadingText,active:!0});this.itemList.appendChild(i);var n=function(t,i,n){t&&t.length&&(e.containerOuter.classList.remove("is-loading"),e.input.placeholder="",t.forEach(function(t,s){0===s&&e._addItem(t[i],t[n],s),e._addChoice(!1,!1,t[i],t[n])}))};return t(n),this}},{key:"clearInput",value:function(){return this.input.value&&(this.input.value=""),"select-one"!==this.passedElement.type&&(this.input.style.width=(0,c.getWidthOfInput)(this.input)),this}},{key:"_handleEnter",value:function(t,e){var i=!0;if(this.options.addItems?this.options.maxItemCount&&this.options.maxItemCount>0&&this.options.maxItemCount<=this.itemList.children.length?i=!1:this.options.duplicateItems===!1&&this.passedElement.value&&(i=!t.some(function(t){return t.value===e})):i=!1,i){var n=!0;this.options.regexFilter&&(n=this._regexFilter(e)),n&&(this.toggleDropdown(),this._addItem(e),this.clearInput(this.passedElement))}}},{key:"_handleBackspace",value:function(t){if(this.options.removeItems&&t){var e=t[t.length-1],i=t.some(function(t){return t.selected===!0});this.options.editItems&&!i&&e?(this.input.value=e.value,this._removeItem(e)):(i||this.selectItem(e),this.removeSelectedItems())}}},{key:"_onKeyDown",value:function(t){if(t.target===this.input){var e=t.ctrlKey||t.metaKey,i=46,n=8,s=13,o=65,r=27,l=38,u=40,h=this.store.getItemsFilteredByActive(),d=(this.store.getChoicesFilteredByActive(),this.input===document.activeElement),p=this.dropdown.classList.contains(this.options.classNames.activeState),f=this.itemList&&this.itemList.children,v=String.fromCharCode(event.keyCode);switch("text"!==this.passedElement.type&&/[a-zA-Z0-9-_ ]/.test(v)&&!p&&this.showDropdown(),this.canSearch=this.options.searchOptions,t.keyCode){case o:e&&f&&(this.canSearch=!1,this.options.removeItems&&!this.input.value&&this.input===document.activeElement&&this.highlightAll(this.itemList.children));break;case s:if(t.target.value&&"text"===this.passedElement.type){var m=this.input.value;this._handleEnter(h,m)}if(p){var g=this.dropdown.querySelector("."+this.options.classNames.highlightedState);if(g){var y=g.getAttribute("data-value"),b=g.innerHTML,_=g.getAttribute("data-id");this._addItem(y,b,_),this.clearInput(this.passedElement),"select-one"===this.passedElement.type&&(this.isSearching=!1,this.store.dispatch((0,a.activateChoices)()),this.toggleDropdown())}}break;case r:p&&this.toggleDropdown();break;case u:case l:if(p){var E=this.dropdown.querySelector("."+this.options.classNames.highlightedState),I=t.keyCode===u?1:-1,w=void 0;this.canSearch=!1,w=E?(0,c.getAdjacentEl)(E,"[data-option-selectable]",I):this.dropdown.querySelector("[data-option-selectable]"),w&&((0,c.isScrolledIntoView)(w,this.choiceList,I)||this._scrollToChoice(w,I),this._highlightChoice(w)),t.preventDefault()}break;case i:case n:d&&!t.target.value&&"select-one"!==this.passedElement.type&&(this._handleBackspace(h),t.preventDefault())}}}},{key:"_onKeyUp",value:function(t){var e=this;if(t.target===this.input){var i=String.fromCharCode(event.keyCode);if("text"===this.passedElement.type){var n=this.dropdown.classList.contains(this.options.classNames.activeState),s=void 0;if(this.input.value){var o=this.store.getItemsFilteredByActive(),r=!o.some(function(t){return t.value===e.input.value});s=this.options.maxItemCount&&this.options.maxItemCount>0&&this.options.maxItemCount<=this.itemList.children.length?this._getTemplate("notice","Only "+this.options.maxItemCount+" options can be added."):this.options.duplicateItems||r?this._getTemplate("notice",'Add "'+this.input.value+'"'):this._getTemplate("notice","Only unique values can be added."),(this.options.regexFilter&&this._regexFilter(this.input.value)||!this.options.regexFilter)&&(this.dropdown.innerHTML=s.outerHTML,this.dropdown.classList.contains(this.options.classNames.activeState)||this.showDropdown())}else n&&this.hideDropdown()}if(this.canSearch&&this.input===document.activeElement){var c=this.store.getChoices(),l=c.some(function(t){return t.active!==!0});if(this.input.value&&c.length&&/[a-zA-Z0-9-_ ]/.test(i)){var h=function(){var t=e.input.value.trim(),i=e.currentValue.trim();if(t.length>=1&&t!==i+" "){var n=e.store.getChoicesFiltedBySelectable(),s=t,o=new u.default(n,{keys:["label","value"],shouldSort:!0,include:"score"}),r=o.search(s);e.currentValue=t,e.highlightPosition=0,e.isSearching=!0,e.store.dispatch((0,a.filterChoices)(r))}};h()}else l&&(this.isSearching=!1,this.store.dispatch((0,a.activateChoices)()))}}}},{key:"_onInput",value:function(t){"select-one"!==this.passedElement.type&&(this.input.style.width=(0,c.getWidthOfInput)(this.input))}},{key:"_onMouseDown",value:function(t){var e=this;if(2!==t.button){var i=this.store.getItemsFilteredByActive();if(this.containerOuter.contains(t.target))!function(){t.preventDefault();var n=!!t.shiftKey;"text"===e.passedElement.type||e.dropdown.classList.contains(e.options.classNames.activeState)||e.showDropdown(),e.input!==document.activeElement&&e.input.focus(),t.target.hasAttribute("data-button")?e.options.removeItems&&e.options.removeItemButton&&!function(){var n=t.target.parentNode.getAttribute("data-id"),s=i.find(function(t){return t.id===parseInt(n)});e._removeItem(s)}():t.target.hasAttribute("data-item")?e.options.removeItems&&!function(){var s=t.target.getAttribute("data-id");i.forEach(function(t){t.id!==parseInt(s)||t.selected?n||e.deselectItem(t):e.selectItem(t)})}():t.target.hasAttribute("data-option")&&!function(){var i=e.store.getChoicesFilteredByActive(),n=t.target.getAttribute("data-id"),s=i.find(function(t){return t.id===parseInt(n)});s.selected||s.disabled||(e._addItem(s.value,s.label,s.id),"select-one"===e.passedElement.type&&(e.input.value="",e.isSearching=!1,e.store.dispatch((0,a.activateChoices)(!0)),e.toggleDropdown()))}()}();else{var n=this.dropdown.classList.contains(this.options.classNames.activeState),s=i.some(function(t){return t.selected===!0});s&&this.unhighlightAll(),this.containerOuter.classList.remove(this.options.classNames.focusState),n&&this.toggleDropdown()}}}},{key:"_onMouseOver",value:function(t){(t.target===this.dropdown||(0,c.findAncestor)(t.target,this.options.classNames.listDropdown))&&t.target.hasAttribute("data-option")&&this._highlightChoice(t.target)}},{key:"_onPaste",value:function(t){t.target===this.input&&(this.options.paste||t.preventDefault())}},{key:"_onFocus",value:function(t){var e=this.dropdown.classList.contains(this.options.classNames.activeState);t.target!==this.input||e||(this.containerOuter.classList.add(this.options.classNames.focusState),"select-one"!==this.passedElement.type&&"select-multiple"!==this.passedElement.type||this.showDropdown())}},{key:"_onBlur",value:function(t){var e=this.dropdown.classList.contains(this.options.classNames.activeState);t.target!==this.input||e?this.hideDropdown():this.containerOuter.classList.remove(this.options.classNames.focusState)}},{key:"_regexFilter",value:function(t){if(t){var e=new RegExp(this.options.regexFilter,"i");return e.test(t)}}},{key:"_scrollToChoice",value:function(t,e){var i=this;if(t){var n=this.choiceList.offsetHeight,s=t.offsetHeight,o=t.offsetTop+s,r=this.choiceList.scrollTop+n,a=e>0?this.choiceList.scrollTop+o-r:t.offsetTop,c=function l(t,e,n){var s=!1,o=void 0,r=void 0,a=4;n>0?(o=(e-i.choiceList.scrollTop)/a,r=o>1?o:1,i.choiceList.scrollTop=i.choiceList.scrollTop+r,i.choiceList.scrollTop1?o:1,i.choiceList.scrollTop=i.choiceList.scrollTop-r,i.choiceList.scrollTop>e&&(s=!0)),s&&requestAnimationFrame(function(t){l(t,e,n)})};requestAnimationFrame(function(t){c(t,a,e)})}}},{key:"_highlightChoice",value:function(t){var e=this,i=Array.from(this.dropdown.querySelectorAll("[data-option-selectable]"));if(i&&i.length){var n=Array.from(this.dropdown.querySelectorAll("."+this.options.classNames.highlightedState));if(n.forEach(function(t){t.classList.remove(e.options.classNames.highlightedState)}),t)t.classList.add(this.options.classNames.highlightedState),this.highlightPosition=i.indexOf(t);else{var s=void 0;s=i.length>this.highlightPosition?i[this.highlightPosition]:i[i.length-1],s||(s=i[0]),s.classList.add(this.options.classNames.highlightedState)}}}},{key:"_addItem",value:function(t,e){var i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3],s=this.store.getItems(),o=t.trim(),r=e||o,l=i||-1;this.options.prependValue&&(o=this.options.prependValue+o.toString()),this.options.appendValue&&(o+=this.options.appendValue.toString());var u=s?s.length+1:1;return this.store.dispatch((0,a.addItem)(o,r,u,l)),"select-one"===this.passedElement.type&&this.removeActiveItems(u),n&&((0,c.isType)("Function",n)?n(u,o,this.passedElement):console.error("callbackOnAddItem: Callback is not a function")),this}},{key:"_removeItem",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?this.options.callbackOnRemoveItem:arguments[1];if(!t||!(0,c.isType)("Object",t))return void console.error("removeItem: No item object was passed to be removed");var i=t.id,n=(t.value,t.choiceId);return this.store.dispatch((0,a.removeItem)(i,n)),e?void((0,c.isType)("Function",e)||console.error("callbackOnRemoveItem: Callback is not a function")):this}},{key:"_addChoice",value:function(t,e,i,n){var s=arguments.length<=4||void 0===arguments[4]?-1:arguments[4];if(i){n||(n=i);var o=this.store.getChoices(),r=o?o.length+1:1;this.store.dispatch((0,a.addChoice)(i,n,r,s,e)),t&&!e&&this._addItem(i,n,r)}}},{key:"_addGroup",value:function(t,e,i){var n=this,s=Array.from(t.getElementsByTagName("OPTION")),o=e;s?(this.store.dispatch((0,a.addGroup)(t.label,o,!0,t.disabled)),s.forEach(function(t,e){var i=t.disabled||t.parentNode.disabled;n._addChoice(t.selected,i,t.value,t.innerHTML,o)})):this.store.dispatch((0,a.addGroup)(t.label,t.id,!1,t.disabled))}},{key:"_getTemplate",value:function(t){if(t){for(var e=this.options.templates,i=arguments.length,n=Array(i>1?i-1:0),s=1;i>s;s++)n[s-1]=arguments[s];return e[t].apply(e,n)}}},{key:"_createTemplates",value:function(){var t=this,e=this.options.classNames,i={containerOuter:function(){return(0,c.strToEl)('
')},containerInner:function(){return(0,c.strToEl)('
')},itemList:function(){return(0,c.strToEl)('
')},choiceList:function(){return(0,c.strToEl)('
')},input:function(){return(0,c.strToEl)('')},dropdown:function(){return(0,c.strToEl)('
')},notice:function(t,i){return(0,c.strToEl)('
'+t+"
")},selectOption:function(t){return(0,c.strToEl)('")},option:function(t){return(0,c.strToEl)('\n
\n '+t.label+"\n
\n ")},optgroup:function(t){return(0,c.strToEl)('\n
\n
'+t.value+"
\n
\n ")},item:function(i){return t.options.removeItemButton&&"select-one"!==t.passedElement.type?(0,c.strToEl)('\n
\n '+i.label+'\n \n
\n '):(0,c.strToEl)('\n
\n '+i.label+"\n
\n ")}};this.options.templates=(0,c.extend)(this.options.templates,i)}},{key:"_createInput",value:function(){var t=this,e=this._getTemplate("containerOuter"),i=this._getTemplate("containerInner"),n=this._getTemplate("itemList"),s=this._getTemplate("choiceList"),o=this._getTemplate("input"),r=this._getTemplate("dropdown");if(this.containerOuter=e,this.containerInner=i,this.input=o,this.choiceList=s,this.itemList=n,this.dropdown=r,this.passedElement.classList.add(this.options.classNames.input,this.options.classNames.hiddenState),this.passedElement.tabIndex="-1",this.passedElement.setAttribute("style","display:none;"),this.passedElement.setAttribute("aria-hidden","true"),this.passedElement.removeAttribute("data-choice"),(0,c.wrap)(this.passedElement,i),(0,c.wrap)(i,e),this.options.placeholder&&(this.options.placeholderValue||this.passedElement.placeholder)){var a=this.options.placeholderValue||this.passedElement.placeholder;o.placeholder=a,"select-one"!==this.passedElement.type&&(o.style.width=(0,c.getWidthOfInput)(o))}if(this.options.addItems||this.disable(),e.appendChild(i),e.appendChild(r),i.appendChild(n),r.appendChild(s),"select-multiple"===this.passedElement.type||"text"===this.passedElement.type?i.appendChild(o):this.options.searchOptions&&r.insertBefore(o,r.firstChild),"select-multiple"===this.passedElement.type||"select-one"===this.passedElement.type){this.highlightPosition=0;var l=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(this.isSearching=!1,l&&l.length)l.forEach(function(e,i){var n=0===i;t._addGroup(e,i,n)});else{var u=Array.from(this.passedElement.options);u.forEach(function(e){var i=e.disabled||e.parentNode.disabled;t._addChoice(e.selected,i,e.value,e.innerHTML)})}}else"text"===this.passedElement.type&&this.presetItems.forEach(function(e){if((0,c.isType)("Object",e)){if(!e.value)return;t._addItem(e.value,e.label,e.id)}else(0,c.isType)("String",e)&&t._addItem(e)})}},{key:"renderGroups",value:function(t,e,i){var n=this,s=i||document.createDocumentFragment();return t.forEach(function(t,i){var o=e.filter(function(e){return"select-one"===n.passedElement.type?e.groupId===t.id:e.groupId===t.id&&!e.selected});if(o.length>=1){var r=n._getTemplate("optgroup",t);s.appendChild(r),n.renderOptions(o,s)}}),s}},{key:"renderOptions",value:function(t,e){var i=this,n=e||document.createDocumentFragment();return t.forEach(function(t,e){var s=i._getTemplate("option",t);"select-one"===i.passedElement.type?n.appendChild(s):t.selected||n.appendChild(s)}),n}},{key:"renderItems",value:function(t,e){var i=this,n=e||document.createDocumentFragment(),s=this.store.getItemsReducedToValues(t);return"text"===this.passedElement.type?this.passedElement.setAttribute("value",s.join(this.options.delimiter)):!function(){var e=document.createDocumentFragment();t.forEach(function(t){var n=i._getTemplate("selectOption",t);e.appendChild(n)}),i.passedElement.innerHTML="",i.passedElement.appendChild(e)}(),t.forEach(function(t){var e=i._getTemplate("item",t);n.appendChild(e)}),n}},{key:"render",value:function(){if(this.currentState=this.store.getState(),this.currentState!==this.prevState){if(!(this.currentState.options===this.prevState.options&&this.currentState.groups===this.prevState.groups||"select-multiple"!==this.passedElement.type&&"select-one"!==this.passedElement.type)){var t=this.store.getGroupsFilteredByActive(),e=this.store.getChoicesFilteredByActive(),i=document.createDocumentFragment();if(this.choiceList.innerHTML="",t.length>=1&&this.isSearching!==!0?i=this.renderGroups(t,e,i):e.length>=1&&(i=this.renderOptions(e,i)),i.children.length)this.choiceList.appendChild(i),this._highlightChoice();else{var n=this.isSearching?this._getTemplate("notice","No results found"):this._getTemplate("notice","No options to select");this.choiceList.appendChild(n)}}if(this.currentState.items!==this.prevState.items){var s=this.store.getItemsFilteredByActive();if(s){var o=this.renderItems(s);this.itemList.innerHTML="",o.children.length&&this.itemList.appendChild(o)}}this.prevState=this.currentState}}},{key:"_addEventListeners",value:function(){document.addEventListener("keyup",this._onKeyUp),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("mousedown",this._onMouseDown),document.addEventListener("mouseover",this._onMouseOver),this.input.addEventListener("input",this._onInput),this.input.addEventListener("paste",this._onPaste),this.input.addEventListener("focus",this._onFocus),this.input.addEventListener("blur",this._onBlur)}},{key:"_removeEventListeners",value:function(){document.removeEventListener("keyup",this._onKeyUp),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("mousedown",this._onMouseDown),document.removeEventListener("mouseover",this._onMouseOver),this.input.removeEventListener("input",this._onInput),this.input.removeEventListener("paste",this._onPaste),this.input.removeEventListener("focus",this._onFocus),this.input.removeEventListener("blur",this._onBlur)}}]),t}();window.Choices=t.exports=p},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.addItem=function(t,e,i,n){return{type:"ADD_ITEM",value:t,label:e,id:i,choiceId:n}},e.removeItem=function(t,e){return{type:"REMOVE_ITEM",id:t,choiceId:e}},e.selectItem=function(t,e){return{type:"SELECT_ITEM",id:t,selected:e}},e.addChoice=function(t,e,i,n,s){return{type:"ADD_CHOICE",value:t,label:e,id:i,groupId:n,disabled:s}},e.filterChoices=function(t){return{type:"FILTER_CHOICES",results:t}},e.activateChoices=function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];return{type:"ACTIVATE_OPTIONS",active:t}},e.addGroup=function(t,e,i,n){return{type:"ADD_GROUP",value:t,id:e,active:i,disabled:n}},e.clearAll=function(){return{type:"CLEAR_ALL"}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=(e.hasClass=function(t,e){return new RegExp(" "+e+" ").test(" "+t.className+" ")},e.capitalise=function(t){return t.replace(/\w\S*/g,function(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()})},e.isType=function(t,e){var i=Object.prototype.toString.call(e).slice(8,-1);return void 0!==e&&null!==e&&i===t}),n=(e.extend=function o(){for(var t={},e=!1,n=arguments.length,s=function(n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e&&i("Object",n[s])?t[s]=o(!0,t[s],n[s]):t[s]=n[s])},r=0;n>r;r++){var a=arguments[r];i("Object",a)?s(a):console.error("Custom options must be an object")}return t},e.whichTransitionEvent=function(){var t,e=document.createElement("fakeelement"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in i)if(void 0!==e.style[t])return i[t]},e.whichAnimationEvent=function(){var t,e=document.createElement("fakeelement"),i={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in i)if(void 0!==e.style[t])return i[t]}),s=(e.getParentsUntil=function(t,e,i){for(var n=[];t&&t!==document;t=t.parentNode){if(e){var s=e.charAt(0);if("."===s&&t.classList.contains(e.substr(1)))break;if("#"===s&&t.id===e.substr(1))break;if("["===s&&t.hasAttribute(e.substr(1,e.length-1)))break;if(t.tagName.toLowerCase()===e)break}if(i){var o=i.charAt(0);"."===o&&t.classList.contains(i.substr(1))&&n.push(t),"#"===o&&t.id===i.substr(1)&&n.push(t),"["===o&&t.hasAttribute(i.substr(1,i.length-1))&&n.push(t),t.tagName.toLowerCase()===i&&n.push(t)}else n.push(t)}return 0===n.length?null:n},e.wrap=function(t,e){return e=e||document.createElement("div"),t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e),e.appendChild(t)},e.getSiblings=function(t){for(var e=[],i=t.parentNode.firstChild;i;i=i.nextSibling)1===i.nodeType&&i!==t&&e.push(i);return e},e.findAncestor=function(t,e){for(;(t=t.parentElement)&&!t.classList.contains(e););return t},e.debounce=function(t,e,i){var n;return function(){var s=this,o=arguments,r=function(){n=null,i||t.apply(s,o)},a=i&&!n;clearTimeout(n),n=setTimeout(r,e),a&&t.apply(s,o)}},e.getElemDistance=function(t){var e=0;if(t.offsetParent)do e+=t.offsetTop,t=t.offsetParent;while(t);return e>=0?e:0},e.getElementOffset=function(t,e){var i=e;return i>1&&(i=1),i>0&&(i=0),Math.max(t.offsetHeight*i)},e.getAdjacentEl=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t&&e){var n=t.parentNode.parentNode,s=Array.from(n.querySelectorAll(e)),o=s.indexOf(t),r=i>0?1:-1;return s[o+r]}},e.getScrollPosition=function(t){return"bottom"===t?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},e.isInView=function(t,e,i){return this.getScrollPosition(e)>this.getElemDistance(t)+this.getElementOffset(t,i)},e.isScrolledIntoView=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t){var n=void 0;return n=i>0?e.scrollTop+e.offsetHeight>=t.offsetTop+t.offsetHeight:t.offsetTop>=e.scrollTop}},e.stripHTML=function(t){var e=document.createElement("DIV");return e.innerHTML=t,e.textContent||e.innerText||""},e.addAnimation=function(t,e){var i=n(),s=function o(){t.classList.remove(e),t.removeEventListener(i,o,!1)};t.classList.add(e),t.addEventListener(i,s,!1)},e.getRandomNumber=function(t,e){return Math.floor(Math.random()*(e-t)+t)},e.strToEl=function(){var t=document.createElement("div");return function(e){var i;for(t.innerHTML=e,i=t.children[0];t.firstChild;)t.removeChild(t.firstChild);return i}}());e.getWidthOfInput=function(t){var e=t.value||t.placeholder,i=t.offsetWidth;if(e){var n=s(""+e+"");n.style.position="absolute",n.style.padding="0",n.style.top="-9999px",n.style.left="-9999px",n.style.width="auto",n.style.whiteSpace="pre",document.body.appendChild(n),e&&n.offsetWidth!==t.offsetWidth&&(i=n.offsetWidth+4),document.body.removeChild(n)}return i+"px"}},function(t,e,i){!function(e){"use strict";function i(){console.log.apply(console,arguments)}function n(t,e){var i,n,s,o;for(this.list=t,this.options=e=e||{},i=0,o=["sort","shouldSort","verbose","tokenize"],n=o.length;n>i;i++)s=o[i],this.options[s]=s in e?e[s]:c[s];for(i=0,o=["searchFn","sortFn","keys","getFn","include"],n=o.length;n>i;i++)s=o[i],this.options[s]=e[s]||c[s]}function s(t,e,i){var n,r,a,c,l,u;if(e){if(a=e.indexOf("."),-1!==a?(n=e.slice(0,a),r=e.slice(a+1)):n=e,c=t[n],null!==c&&void 0!==c)if(r||"string"!=typeof c&&"number"!=typeof c)if(o(c))for(l=0,u=c.length;u>l;l++)s(c[l],r,i);else r&&s(c,r,i);else i.push(c)}else i.push(t);return i}function o(t){return"[object Array]"===Object.prototype.toString.call(t)}function r(t,e){e=e||{},this.options=e,this.options.location=e.location||r.defaultOptions.location,this.options.distance="distance"in e?e.distance:r.defaultOptions.distance,this.options.threshold="threshold"in e?e.threshold:r.defaultOptions.threshold,this.options.maxPatternLength=e.maxPatternLength||r.defaultOptions.maxPatternLength,this.pattern=e.caseSensitive?t:t.toLowerCase(),this.patternLen=t.length,this.patternLen<=this.options.maxPatternLength&&(this.matchmask=1<s;s++)this.tokenSearchers.push(new i(n[s],t));this.fullSeacher=new i(e,t)},n.prototype._startSearch=function(){var t,e,i,n,s=this.options,o=s.getFn,r=this.list,a=r.length,c=this.options.keys,l=c.length,u=null;if("string"==typeof r[0])for(i=0;a>i;i++)this._analyze("",r[i],i,i);else for(this._keyMap={},i=0;a>i;i++)for(u=r[i],n=0;l>n;n++){if(t=c[n],"string"!=typeof t){if(e=1-t.weight||1,this._keyMap[t.name]={weight:e},t.weight<=0||t.weight>1)throw new Error("Key weight has to be > 0 and <= 1");t=t.name}else this._keyMap[t]={weight:1};this._analyze(t,o(u,t,[]),u,i)}},n.prototype._analyze=function(t,e,n,s){var r,c,l,u,h,d,p,f,v,m,g,y,b,_,E,I=this.options,w=!1;if(void 0!==e&&null!==e)if(c=[],"string"==typeof e){if(r=e.split(a),I.verbose&&i("---------\nKey:",t), +I.verbose&&i("Record:",r),this.options.tokenize){for(l=this.tokenSearchers,u=l.length,_=0;__;_++)d+=c[_];d/=f,I.verbose&&i("Token score average:",d)}v=this.fullSeacher.search(e),I.verbose&&i("Full text score:",v.score),p=v.score,void 0!==d&&(p=(p+d)/2),I.verbose&&i("Score average:",p),(w||v.isMatch)&&(h=this.resultMap[s],h?h.output.push({key:t,score:p,matchedIndices:v.matchedIndices}):(this.resultMap[s]={item:n,output:[{key:t,score:p,matchedIndices:v.matchedIndices}]},this.results.push(this.resultMap[s])))}else if(o(e))for(_=0;_e;e++)r=s[e].score,a=u?u[s[e].key].weight:1,l=r*a,1!==a?c=Math.min(c,l):(n+=l,s[e].nScore=l);1===c?h[t].score=n/o:h[t].score=c,this.options.verbose&&i(h[t])}},n.prototype._sort=function(){var t=this.options;t.shouldSort&&(t.verbose&&i("\n\nSorting...."),this.results.sort(t.sortFn))},n.prototype._format=function(){var t,e,n,s,o,r=this.options,a=r.getFn,c=[],l=this.results,u=r.include;for(r.verbose&&i("\n\nOutput:\n\n",l),s=r.id?function(t){l[t].item=a(l[t].item,r.id,[])[0]}:function(){},o=function(t){var e,i,n,s,o,r=l[t];if(u.length>0){if(e={item:r.item},-1!==u.indexOf("matches"))for(n=r.output,e.matches=[],i=0;ie;e++)s(e),t=o(e),c.push(t);return c},r.defaultOptions={location:0,distance:100,threshold:.6,maxPatternLength:32},r.prototype._calculatePatternAlphabet=function(){var t={},e=0;for(e=0;eS.maxPatternLength){if(y=t.match(new RegExp(this.pattern.replace(a,"|"))),b=!!y)for(E=[],e=0,I=y.length;I>e;e++)w=y[e],E.push([t.indexOf(w),w.length-1]);return{isMatch:b,score:b?.5:1,matchedIndices:E}}for(s=S.location,n=t.length,o=S.threshold,r=t.indexOf(this.pattern,s),_=[],e=0;n>e;e++)_[e]=0;for(-1!=r&&(o=Math.min(this._bitapScore(0,r),o),r=t.lastIndexOf(this.pattern,s+this.patternLen),-1!=r&&(o=Math.min(this._bitapScore(0,r),o))),r=-1,m=1,g=[],u=this.patternLen+n,e=0;ec;)this._bitapScore(e,s+l)<=o?c=l:u=l,l=Math.floor((u-c)/2+c);for(u=l,h=Math.max(1,s-l+1),d=Math.min(s+l,n)+this.patternLen,p=Array(d+2),p[d+1]=(1<=h;i--)if(v=this.patternAlphabet[t.charAt(i-1)],v&&(_[i-1]=1),0===e?p[i]=(p[i+1]<<1|1)&v:p[i]=(p[i+1]<<1|1)&v|((f[i+1]|f[i])<<1|1)|f[i+1],p[i]&this.matchmask&&(m=this._bitapScore(e,i-1),o>=m)){if(o=m,r=i-1,g.push(r),!(r>s))break;h=Math.max(1,2*s-r)}if(this._bitapScore(e+1,s)>o)break;f=p}return E=this._getMatchedIndices(_),{isMatch:r>=0,score:0===m?.001:m,matchedIndices:E}},r.prototype._getMatchedIndices=function(t){for(var e,i=[],n=-1,s=-1,o=0,r=r=t.length;r>o;o++)e=t[o],e&&-1===n?n=o:e||-1===n||(s=o-1,i.push([n,s]),n=-1);return t[o-1]&&i.push([n,o-1]),i},t.exports=n}(this)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Store=void 0;var o=function(){function t(t,e){for(var i=0;ii;i++)e[i]=arguments[i];return function(t){return function(i,n,s){var r=t(i,n,s),c=r.dispatch,l=[],u={getState:r.getState,dispatch:function(t){return c(t)}};return l=e.map(function(t){return t(u)}),c=a.default.apply(void 0,l)(r.dispatch),o({},r,{dispatch:c})}}}e.__esModule=!0;var o=Object.assign||function(t){for(var e=1;ei;i++)e[i]=arguments[i];if(0===e.length)return function(t){return t};var n=function(){var t=e[e.length-1],i=e.slice(0,-1);return{v:function(){return i.reduceRight(function(t,e){return e(t)},t.apply(void 0,arguments))}}}();return"object"==typeof n?n.v:void 0}e.__esModule=!0,e.default=i},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var s=i(6),o=i(20),r=n(o),a=i(21),c=n(a),l=i(22),u=n(l),h=(0,s.combineReducers)({items:r.default,groups:c.default,choices:u.default}),d=function(t,e){return"CLEAR_ALL"===e.type&&(t=void 0),h(t,e)};e.default=d},function(t,e){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e-1?t.map(function(t){return t.id===parseInt(e.choiceId)&&(t.selected=!0),t}):t;case"REMOVE_ITEM":return e.choiceId>-1?t.map(function(t){return t.id===parseInt(e.choiceId)&&(t.selected=!1),t}):t;case"FILTER_CHOICES":var n=e.results,s=t.map(function(t,e){return t.active=n.some(function(e){return e.item.id===t.id?(t.score=e.score,!0):void 0}),t}).sort(function(t,e){return t.score-e.score});return s;case"ACTIVATE_CHOICES":return t.map(function(t){return t.active=e.active,t});default:return t}};e.default=n}]); \ No newline at end of file diff --git a/assets/scripts/src/actions/index.js b/assets/scripts/src/actions/index.js index bcff521..e1b235c 100644 --- a/assets/scripts/src/actions/index.js +++ b/assets/scripts/src/actions/index.js @@ -1,18 +1,18 @@ -export const addItem = (value, label, id, optionId) => { +export const addItem = (value, label, id, choiceId) => { return { type: 'ADD_ITEM', value, label, id, - optionId, + choiceId, } }; -export const removeItem = (id, optionId) => { +export const removeItem = (id, choiceId) => { return { type: 'REMOVE_ITEM', id, - optionId, + choiceId, } }; @@ -24,9 +24,9 @@ export const selectItem = (id, selected) => { } }; -export const addOption = (value, label, id, groupId, disabled) => { +export const addChoice = (value, label, id, groupId, disabled) => { return { - type: 'ADD_OPTION', + type: 'ADD_CHOICE', value, label, id, @@ -35,14 +35,14 @@ export const addOption = (value, label, id, groupId, disabled) => { } }; -export const filterOptions = (results) => { +export const filterChoices = (results) => { return { - type: 'FILTER_OPTIONS', + type: 'FILTER_CHOICES', results, } }; -export const activateOptions = (active = true) => { +export const activateChoices = (active = true) => { return { type: 'ACTIVATE_OPTIONS', active, diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 3e633ec..92bdc27 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -1,6 +1,6 @@ 'use strict'; -import { addItem, removeItem, selectItem, addOption, filterOptions, activateOptions, addGroup, clearAll } from './actions/index'; +import { addItem, removeItem, selectItem, addChoice, filterChoices, activateChoices, addGroup, clearAll } from './actions/index'; import { isScrolledIntoView, getAdjacentEl, findAncestor, wrap, isType, strToEl, extend, getWidthOfInput, debounce } from './lib/utils.js'; import Fuse from 'fuse.js'; import Store from './store/index.js'; @@ -29,21 +29,20 @@ export class Choices { const defaultOptions = { items: [], + maxItemCount: -1, addItems: true, removeItems: true, - removeButton: false, + removeItemButton: false, editItems: false, - maxItems: null, + duplicateItems: true, delimiter: ',', - allowDuplicates: true, - allowPaste: true, - allowSearch: true, + paste: true, + searchOptions: true, regexFilter: null, placeholder: true, placeholderValue: null, prependValue: null, appendValue: null, - highlightAll: true, loadingText: 'Loading...', templates: {}, classNames: { @@ -72,8 +71,8 @@ export class Choices { selectedState: 'is-selected', }, callbackOnInit: () => {}, - callbackOnRemoveItem: () => {}, - callbackOnAddItem: () => {} + callbackOnAddItem: (id, value, passedInput) => {}, + callbackOnRemoveItem: (id, value, passedInput) => {}, }; // Merge options with user options @@ -92,7 +91,7 @@ export class Choices { this.passedElement = isType('String', element) ? document.querySelector(element) : element; this.highlightPosition = 0; - this.canSearch = this.options.allowSearch; + this.canSearch = this.options.searchOptions; // Assign preset items from passed object first this.presetItems = this.options.items; @@ -371,13 +370,13 @@ export class Choices { // If we are dealing with a select input, we need to create an option first // that is then selected. For text inputs we can just add items normally. if(this.passedElement.type !== 'text') { - this._addOption(true, false, item.value, item.label, -1); + this._addChoice(true, false, item.value, item.label, -1); } else { this._addItem(item.value, item.label, item.id); } } else if(isType('String', item)) { if(this.passedElement.type !== 'text') { - this._addOption(true, false, item, item, -1); + this._addChoice(true, false, item, item, -1); } else { this._addItem(item); } @@ -433,7 +432,7 @@ export class Choices { if(index === 0) { this._addItem(result[value], result[label], index); } - this._addOption(false, false, result[value], result[label]); + this._addChoice(false, false, result[value], result[label]); }); } }; @@ -466,11 +465,11 @@ export class Choices { let canUpdate = true; if(this.options.addItems) { - if (this.options.maxItems && this.options.maxItems <= this.itemList.children.length) { + if (this.options.maxItemCount && this.options.maxItemCount > 0 && this.options.maxItemCount <= this.itemList.children.length) { // If there is a max entry limit and we have reached that limit // don't update canUpdate = false; - } else if(this.options.allowDuplicates === false && this.passedElement.value) { + } else if(this.options.duplicateItems === false && this.passedElement.value) { // If no duplicates are allowed, and the value already exists // in the array, don't update canUpdate = !activeItems.some((item) => item.value === value ); @@ -539,7 +538,7 @@ export class Choices { const downKey = 40; const activeItems = this.store.getItemsFilteredByActive(); - const activeOptions = this.store.getOptionsFilteredByActive(); + const activeOptions = this.store.getChoicesFilteredByActive(); const hasFocusedInput = this.input === document.activeElement; const hasActiveDropdown = this.dropdown.classList.contains(this.options.classNames.activeState); @@ -551,14 +550,14 @@ export class Choices { this.showDropdown(); } - this.canSearch = this.options.allowSearch; + this.canSearch = this.options.searchOptions; switch (e.keyCode) { case aKey: // If CTRL + A or CMD + A have been pressed and there are items to select if(ctrlDownKey && hasItems) { this.canSearch = false; - if(this.options.removeItems && !this.input.value && this.options.highlightAll && this.input === document.activeElement) { + if(this.options.removeItems && !this.input.value && this.input === document.activeElement) { // Highlight items this.highlightAll(this.itemList.children); } @@ -584,7 +583,7 @@ export class Choices { if(this.passedElement.type === 'select-one') { this.isSearching = false; - this.store.dispatch(activateOptions()); + this.store.dispatch(activateChoices()); this.toggleDropdown(); } } @@ -616,10 +615,10 @@ export class Choices { if(nextEl) { // We prevent default to stop the cursor moving // when pressing the arrow - if(!isScrolledIntoView(nextEl, this.optionList, directionInt)) { - this._scrollToOption(nextEl, directionInt); + if(!isScrolledIntoView(nextEl, this.choiceList, directionInt)) { + this._scrollToChoice(nextEl, directionInt); } - this._highlightOption(nextEl); + this._highlightChoice(nextEl); } // Prevent default to maintain cursor position whilst @@ -661,9 +660,9 @@ export class Choices { const activeItems = this.store.getItemsFilteredByActive(); const isUnique = !activeItems.some((item) => item.value === this.input.value); - if (this.options.maxItems && this.options.maxItems <= this.itemList.children.length) { - dropdownItem = this._getTemplate('notice', `Only ${ this.options.maxItems } options can be added.`); - } else if(!this.options.allowDuplicates && !isUnique) { + if (this.options.maxItemCount && this.options.maxItemCount > 0 && this.options.maxItemCount <= this.itemList.children.length) { + dropdownItem = this._getTemplate('notice', `Only ${ this.options.maxItemCount } options can be added.`); + } else if(!this.options.duplicateItems && !isUnique) { dropdownItem = this._getTemplate('notice', `Only unique values can be added.`); } else { dropdownItem = this._getTemplate('notice', `Add "${ this.input.value }"`); @@ -684,7 +683,7 @@ export class Choices { // If we have enabled text search if(this.canSearch) { if(this.input === document.activeElement) { - const options = this.store.getOptions(); + const options = this.store.getChoices(); const hasUnactiveOptions = options.some((option) => option.active !== true); // Check that we have a value to search and the input was an alphanumeric character @@ -694,7 +693,7 @@ export class Choices { const currentValue = this.currentValue.trim(); if(newValue.length >= 1 && newValue !== currentValue + ' ') { - const haystack = this.store.getOptionsFiltedBySelectable(); + const haystack = this.store.getChoicesFiltedBySelectable(); const needle = newValue; const fuse = new Fuse(haystack, { keys: ['label', 'value'], @@ -706,7 +705,7 @@ export class Choices { this.currentValue = newValue; this.highlightPosition = 0; this.isSearching = true; - this.store.dispatch(filterOptions(results)); + this.store.dispatch(filterChoices(results)); } }; @@ -714,7 +713,7 @@ export class Choices { } else if(hasUnactiveOptions) { // Otherwise reset options to active this.isSearching = false; - this.store.dispatch(activateOptions()); + this.store.dispatch(activateChoices()); } } } @@ -763,7 +762,7 @@ export class Choices { } if(e.target.hasAttribute('data-button')) { - if(this.options.removeItems && this.options.removeButton) { + if(this.options.removeItems && this.options.removeItemButton) { const itemId = e.target.parentNode.getAttribute('data-id'); const itemToRemove = activeItems.find((item) => item.id === parseInt(itemId)); this._removeItem(itemToRemove); @@ -786,7 +785,7 @@ export class Choices { } } else if(e.target.hasAttribute('data-option')) { // If we are clicking on an option - const options = this.store.getOptionsFilteredByActive(); + const options = this.store.getChoicesFilteredByActive(); const id = e.target.getAttribute('data-id'); const option = options.find((option) => option.id === parseInt(id)); @@ -795,7 +794,7 @@ export class Choices { if(this.passedElement.type === 'select-one') { this.input.value = ""; this.isSearching = false; - this.store.dispatch(activateOptions(true)); + this.store.dispatch(activateChoices(true)); this.toggleDropdown(); } } @@ -828,7 +827,7 @@ export class Choices { // If the dropdown is either the target or one of its children is the target if((e.target === this.dropdown || findAncestor(e.target, this.options.classNames.listDropdown))) { if(e.target.hasAttribute('data-option')) { - this._highlightOption(e.target); + this._highlightChoice(e.target); } } } @@ -842,7 +841,7 @@ export class Choices { _onPaste(e) { if(e.target !== this.input) return; // Disable pasting into the input if option has been set - if(!this.options.allowPaste) { + if(!this.options.paste) { e.preventDefault(); } } @@ -899,20 +898,20 @@ export class Choices { * @return * @private */ - _scrollToOption(option, direction) { + _scrollToChoice(option, direction) { if(!option) return; - const dropdownHeight = this.optionList.offsetHeight; + const dropdownHeight = this.choiceList.offsetHeight; const optionHeight = option.offsetHeight; // Distance from bottom of element to top of parent - const optionPos = option.offsetTop + optionHeight; + const choicePos = option.offsetTop + optionHeight; // Scroll position of dropdown - const containerScrollPos = this.optionList.scrollTop + dropdownHeight; + const containerScrollPos = this.choiceList.scrollTop + dropdownHeight; // Difference between the option and scroll position - let endPoint = direction > 0 ? ((this.optionList.scrollTop + optionPos) - containerScrollPos) : option.offsetTop; + let endPoint = direction > 0 ? ((this.choiceList.scrollTop + choicePos) - containerScrollPos) : option.offsetTop; const animateScroll = (time, endPoint, direction) => { let continueAnimation = false; @@ -920,19 +919,19 @@ export class Choices { const strength = 4; if(direction > 0) { - easing = (endPoint - this.optionList.scrollTop)/strength; + easing = (endPoint - this.choiceList.scrollTop)/strength; distance = easing > 1 ? easing : 1; - this.optionList.scrollTop = this.optionList.scrollTop + distance; - if(this.optionList.scrollTop < endPoint) { + this.choiceList.scrollTop = this.choiceList.scrollTop + distance; + if(this.choiceList.scrollTop < endPoint) { continueAnimation = true; } } else { - easing = (this.optionList.scrollTop - endPoint)/strength; + easing = (this.choiceList.scrollTop - endPoint)/strength; distance = easing > 1 ? easing : 1; - this.optionList.scrollTop = this.optionList.scrollTop - distance; - if(this.optionList.scrollTop > endPoint) { + this.choiceList.scrollTop = this.choiceList.scrollTop - distance; + if(this.choiceList.scrollTop > endPoint) { continueAnimation = true; } } @@ -955,11 +954,11 @@ export class Choices { * @return * @private */ - _highlightOption(el) { + _highlightChoice(el) { // Highlight first element in dropdown const options = Array.from(this.dropdown.querySelectorAll('[data-option-selectable]')); - if(options.length) { + if(options && options.length) { const highlightedOptions = Array.from(this.dropdown.querySelectorAll(`.${this.options.classNames.highlightedState}`)); // Remove any highlighted options @@ -996,11 +995,11 @@ export class Choices { * @return {Object} Class instance * @public */ - _addItem(value, label, optionId = -1, callback = this.options.callbackOnAddItem) { + _addItem(value, label, choiceId = -1, callback = this.options.callbackOnAddItem) { const items = this.store.getItems(); let passedValue = value.trim(); let passedLabel = label || passedValue; - let passedOptionId = optionId || -1; + let passedOptionId = choiceId || -1; // If a prepended value has been passed, prepend it if(this.options.prependValue) { @@ -1047,9 +1046,9 @@ export class Choices { const id = item.id; const value = item.value; - const optionId = item.optionId; + const choiceId = item.choiceId; - this.store.dispatch(removeItem(id, optionId)); + this.store.dispatch(removeItem(id, choiceId)); // Run callback if(callback){ @@ -1061,22 +1060,20 @@ export class Choices { } /** - * Add option to dropdown - * @param {Object} option Option to add - * @param {Number} groupId ID of the options group + * Add choice to dropdoww * @return * @private */ - _addOption(isSelected, isDisabled, value, label, groupId = -1) { + _addChoice(isSelected, isDisabled, value, label, groupId = -1) { if(!value) return if(!label) { label = value; } // Generate unique id - const options = this.store.getOptions(); - const id = options.length + 1; + const choices = this.store.getChoices(); + const id = choices ? choices.length + 1 : 1; - this.store.dispatch(addOption(value, label, id, groupId, isDisabled)); + this.store.dispatch(addChoice(value, label, id, groupId, isDisabled)); if(isSelected && !isDisabled) { this._addItem(value, label, id); @@ -1098,7 +1095,7 @@ export class Choices { this.store.dispatch(addGroup(group.label, groupId, true, group.disabled)); groupOptions.forEach((option, optionIndex) => { const isDisabled = option.disabled || option.parentNode.disabled; - this._addOption(option.selected, isDisabled, option.value, option.innerHTML, groupId); + this._addChoice(option.selected, isDisabled, option.value, option.innerHTML, groupId); }); } else { this.store.dispatch(addGroup(group.label, group.id, false, group.disabled)); @@ -1135,7 +1132,7 @@ export class Choices { itemList: () => { return strToEl(`
`); }, - optionList: () => { + choiceList: () => { return strToEl(`
`); }, input: () => { @@ -1165,7 +1162,7 @@ export class Choices { `); }, item: (data) => { - if(this.options.removeButton && this.passedElement.type !== 'select-one') { + if(this.options.removeItemButton && this.passedElement.type !== 'select-one') { return strToEl(`
${ data.label } @@ -1194,14 +1191,14 @@ export class Choices { const containerOuter = this._getTemplate('containerOuter'); const containerInner = this._getTemplate('containerInner'); const itemList = this._getTemplate('itemList'); - const optionList = this._getTemplate('optionList'); + const choiceList = this._getTemplate('choiceList'); const input = this._getTemplate('input'); const dropdown = this._getTemplate('dropdown'); this.containerOuter = containerOuter; this.containerInner = containerInner; this.input = input; - this.optionList = optionList; + this.choiceList = choiceList; this.itemList = itemList; this.dropdown = dropdown; @@ -1232,11 +1229,11 @@ export class Choices { containerOuter.appendChild(containerInner); containerOuter.appendChild(dropdown); containerInner.appendChild(itemList); - dropdown.appendChild(optionList); + dropdown.appendChild(choiceList); if(this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') { containerInner.appendChild(input); - } else if(this.options.allowSearch) { + } else if(this.options.searchOptions) { dropdown.insertBefore(input, dropdown.firstChild); } @@ -1256,7 +1253,7 @@ export class Choices { const passedOptions = Array.from(this.passedElement.options); passedOptions.forEach((option) => { const isDisabled = option.disabled || option.parentNode.disabled; - this._addOption(option.selected, isDisabled, option.value, option.innerHTML); + this._addChoice(option.selected, isDisabled, option.value, option.innerHTML); }); } @@ -1391,12 +1388,12 @@ export class Choices { if(this.passedElement.type === 'select-multiple' || this.passedElement.type === 'select-one') { // Get active groups/options const activeGroups = this.store.getGroupsFilteredByActive(); - const activeOptions = this.store.getOptionsFilteredByActive(); + const activeOptions = this.store.getChoicesFilteredByActive(); let optListFragment = document.createDocumentFragment(); // Clear options - this.optionList.innerHTML = ''; + this.choiceList.innerHTML = ''; // If we have grouped options if(activeGroups.length >= 1 && this.isSearching !== true) { @@ -1408,12 +1405,12 @@ export class Choices { if(optListFragment.children.length) { // If we actually have anything to add to our dropdown // append it and highlight the first option - this.optionList.appendChild(optListFragment); - this._highlightOption(); + this.choiceList.appendChild(optListFragment); + this._highlightChoice(); } else { // Otherwise show a notice const dropdownItem = this.isSearching ? this._getTemplate('notice', 'No results found') : this._getTemplate('notice', 'No options to select'); - this.optionList.appendChild(dropdownItem); + this.choiceList.appendChild(dropdownItem); } } } diff --git a/assets/scripts/src/reducers/options.js b/assets/scripts/src/reducers/choices.js similarity index 84% rename from assets/scripts/src/reducers/options.js rename to assets/scripts/src/reducers/choices.js index 79518a4..28ef3d2 100644 --- a/assets/scripts/src/reducers/options.js +++ b/assets/scripts/src/reducers/choices.js @@ -1,6 +1,6 @@ -const options = (state = [], action) => { +const choices = (state = [], action) => { switch (action.type) { - case 'ADD_OPTION': + case 'ADD_CHOICE': return [...state, { id: action.id, groupId: action.groupId, @@ -15,9 +15,9 @@ const options = (state = [], action) => { case 'ADD_ITEM': // When an item is added and it has an associated option, // we want to disable it so it can't be chosen again - if(action.optionId > -1) { + if(action.choiceId > -1) { return state.map((option) => { - if(option.id === parseInt(action.optionId)) { + if(option.id === parseInt(action.choiceId)) { option.selected = true; } return option; @@ -29,9 +29,9 @@ const options = (state = [], action) => { case 'REMOVE_ITEM': // When an item is removed and it has an associated option, // we want to re-enable it so it can be chosen again - if(action.optionId > -1) { + if(action.choiceId > -1) { return state.map((option) => { - if(option.id === parseInt(action.optionId)) { + if(option.id === parseInt(action.choiceId)) { option.selected = false; } return option; @@ -40,7 +40,7 @@ const options = (state = [], action) => { return state; } - case 'FILTER_OPTIONS': + case 'FILTER_CHOICES': const filteredResults = action.results; const filteredState = state.map((option, index) => { // Set active state based on whether option is @@ -60,7 +60,7 @@ const options = (state = [], action) => { return filteredState; - case 'ACTIVATE_OPTIONS': + case 'ACTIVATE_CHOICES': return state.map((option) => { option.active = action.active; @@ -73,4 +73,4 @@ const options = (state = [], action) => { } } -export default options; \ No newline at end of file +export default choices; \ No newline at end of file diff --git a/assets/scripts/src/reducers/index.js b/assets/scripts/src/reducers/index.js index 364fb17..44b95fd 100644 --- a/assets/scripts/src/reducers/index.js +++ b/assets/scripts/src/reducers/index.js @@ -1,12 +1,12 @@ import { combineReducers } from 'redux'; import items from './items'; import groups from './groups'; -import options from './options'; +import choices from './choices'; const appReducer = combineReducers({ items, groups, - options + choices }); const rootReducer = (state, action) => { diff --git a/assets/scripts/src/reducers/items.js b/assets/scripts/src/reducers/items.js index c229813..25fd37f 100644 --- a/assets/scripts/src/reducers/items.js +++ b/assets/scripts/src/reducers/items.js @@ -4,7 +4,7 @@ const items = (state = [], action) => { // Add object to items array let newState = [...state, { id: action.id, - optionId: action.optionId, + choiceId: action.choiceId, value: action.value, label: action.label, active: true, diff --git a/assets/scripts/src/store/index.js b/assets/scripts/src/store/index.js index 3d19635..54b49cf 100644 --- a/assets/scripts/src/store/index.js +++ b/assets/scripts/src/store/index.js @@ -75,35 +75,35 @@ export class Store { } /** - * Get options from store + * Get choices from store * @return {Array} Option objects */ - getOptions() { + getChoices() { const state = this.store.getState(); - return state.options; + return state.choices; } /** - * Get active options from store + * Get active choices from store * @return {Array} Option objects */ - getOptionsFilteredByActive() { - const options = this.getOptions(); - const values = options.filter((option) => { - return option.active === true; + getChoicesFilteredByActive() { + const choices = this.getChoices(); + const values = choices.filter((choice) => { + return choice.active === true; },[]); return values; } /** - * Get selectable options from store + * Get selectable choices from store * @return {Array} Option objects */ - getOptionsFiltedBySelectable() { - const options = this.getOptions(); - const values = options.filter((option) => { - return option.selected === false && option.disabled !== true; + getChoicesFiltedBySelectable() { + const choices = this.getChoices(); + const values = choices.filter((choice) => { + return choice.selected === false && choice.disabled !== true; },[]); return values; @@ -124,11 +124,11 @@ export class Store { */ getGroupsFilteredByActive() { const groups = this.getGroups(); - const options = this.getOptions(); + const choices = this.getChoices(); const values = groups.filter((group) => { const isActive = group.active === true && group.disabled === false; - const hasActiveOptions = options.some((option) => { + const hasActiveOptions = choices.some((option) => { return option.active === true && option.disabled === false; }); return isActive && hasActiveOptions ? true : false; diff --git a/index.html b/index.html index dd8a4b3..8ed7b59 100644 --- a/index.html +++ b/index.html @@ -141,13 +141,13 @@ }); const choices2 = new Choices('#choices-2', { - allowPaste: false, - allowDuplicates: false, + paste: false, + duplicateItems: false, editItems: true, }); const choices3 = new Choices('#choices-3', { - allowDuplicates: false, + duplicates: false, editItems: true, regexFilter: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, }); @@ -166,7 +166,7 @@ items: ['josh@joshuajohnson.co.uk', { value: 'joe@bloggs.co.uk', label: 'Joe Bloggs' } ], }); - const choices7 = new Choices('#choices-7', { allowSearch: false }).setValue(['Set value 1', 'Set value 2']); + const choices7 = new Choices('#choices-7', { Search: false }).setValue(['Set value 1', 'Set value 2']); const choicesAjax = new Choices('#choices-12').ajax((callback) => { fetch('https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')