diff --git a/assets/scripts/dist/choices.min.js b/assets/scripts/dist/choices.min.js index ec414f9..6805c17 100644 --- a/assets/scripts/dist/choices.min.js +++ b/assets/scripts/dist/choices.min.js @@ -1,2 +1,2 @@ -!function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return e[n].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var i={};return t.m=e,t.c=i,t.p="/assets/scripts/dist/",t(0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function s(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t1)for(var r=1;r=document.body.offsetHeight;return t?this.containerOuter.classList.add(this.config.classNames.flippedState):this.containerOuter.classList.remove(this.config.classNames.flippedState),this}},{key:"hideDropdown",value:function(){var e=this.containerOuter.classList.contains(this.config.classNames.flippedState);return this.containerOuter.classList.remove(this.config.classNames.openState),this.dropdown.classList.remove(this.config.classNames.activeState),e&&this.containerOuter.classList.remove(this.config.classNames.flippedState),this}},{key:"toggleDropdown",value:function(){return this.dropdown.classList.contains(this.config.classNames.activeState)?this.hideDropdown():this.showDropdown(),this}},{key:"setValue",value:function(e){var t=this;if(this.initialised===!0){var i=[].concat(s(e));i.forEach(function(e,i){if((0,c.isType)("Object",e)){if(!e.value)return;"text"!==t.passedElement.type?t._addChoice(!0,!1,e.value,e.label,-1):t._addItem(e.value,e.label,e.id)}else(0,c.isType)("String",e)&&("text"!==t.passedElement.type?t._addChoice(!0,!1,e,e,-1):t._addItem(e))})}return this}},{key:"setValueByChoice",value:function(e){var t=this;return"text"!==this.passedElement.type&&!function(){var i=t.store.getChoices();(0,c.isType)("Array",e)||(e=[e]),e.forEach(function(e,n){var s=i.find(function(t){return t.value===e});s?s.selected?console.warn("Attempting to select choice already selected"):t._addItem(s.value,s.label,s.id):console.warn("Attempting to select choice that does not exist")})}(),this}},{key:"setChoices",value:function(e,t,i){var n=this;if(this.initialised===!0&&("select-one"===this.passedElement.type||"select-multiple"===this.passedElement.type)){if(!(0,c.isType)("Array",e)||!t)return;e&&e.length&&(this.containerOuter.classList.remove(this.config.classNames.loadingState),e.forEach(function(e,s){0===s&&"select-one"===n.passedElement.type?n._addChoice(!0,!!e.disabled&&e.disabled,e[t],e[i]):n._addChoice(!!e.selected&&e.selected,!!e.disabled&&e.disabled,e[t],e[i])}))}return 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.config.classNames.disabledState)),this}},{key:"ajax",value:function(e){var t=this;if(this.initialised===!0&&("select-one"===this.passedElement.type||"select-multiple"===this.passedElement.type)){if(this.containerOuter.classList.add(this.config.classNames.loadingState),"select-one"===this.passedElement.type){var i=this._getTemplate("item",{id:-1,value:"Loading",label:this.config.loadingText,active:!0});this.itemList.appendChild(i)}var n=function(e,i,n){(0,c.isType)("Array",e)&&i&&e&&e.length&&(t.containerOuter.classList.remove(t.config.classNames.loadingState),e.forEach(function(e,s){0===s&&"select-one"===t.passedElement.type?t._addChoice(!0,!1,e[i],e[n]):t._addChoice(!1,!1,e[i],e[n])}))};e(n)}return 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:"_triggerChange",value:function(e){if(e&&this.config.callbackOnChange){var t=this.config.callbackOnChange;(0,c.isType)("Function",t)?t(e,this.passedElement):console.error("callbackOnChange: Callback is not a function")}}},{key:"_handleEnter",value:function(e,t){var i=!0;if(this.config.addItems?this.config.maxItemCount&&this.config.maxItemCount>0&&this.config.maxItemCount<=this.itemList.children.length?i=!1:this.config.duplicateItems===!1&&this.passedElement.value&&(i=!e.some(function(e){return e.value===t})):i=!1,i){var n=!0;this.config.regexFilter&&(n=this._regexFilter(t)),n&&(this.toggleDropdown(),this._addItem(t),this._triggerChange(t),this.clearInput(this.passedElement))}}},{key:"_handleBackspace",value:function(e){if(this.config.removeItems&&e){var t=e[e.length-1],i=e.some(function(e){return e.highlighted===!0});this.config.editItems&&!i&&t?(this.input.value=t.value,this._removeItem(t),this._triggerChange(t.value)):(i||this.highlightItem(t),this.removeHighlightedItems())}}},{key:"_onKeyDown",value:function(e){if(e.target===this.input){var t=e.ctrlKey||e.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),f=this.dropdown.classList.contains(this.config.classNames.activeState),p=this.itemList&&this.itemList.children,v=String.fromCharCode(e.keyCode);switch("text"!==this.passedElement.type&&/[a-zA-Z0-9-_ ]/.test(v)&&!f&&this.showDropdown(),this.canSearch=this.config.search,e.keyCode){case o:t&&p&&(this.canSearch=!1,this.config.removeItems&&!this.input.value&&this.input===document.activeElement&&this.highlightAll(this.itemList.children));break;case s:if(e.target.value&&"text"===this.passedElement.type){var m=this.input.value;this._handleEnter(h,m)}if(f){var g=this.dropdown.querySelector("."+this.config.classNames.highlightedState);if(g){var y=g.getAttribute("data-value"),b=g.innerHTML,_=g.getAttribute("data-id");this._addItem(y,b,_),this._triggerChange(y),this.clearInput(this.passedElement),"select-one"===this.passedElement.type&&(this.isSearching=!1,this.store.dispatch((0,a.activateChoices)()),this.toggleDropdown())}}break;case r:f&&this.toggleDropdown();break;case u:case l:if(f){var E=this.dropdown.querySelector("."+this.config.classNames.highlightedState),I=e.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)),e.preventDefault()}break;case i:case n:d&&!e.target.value&&"select-one"!==this.passedElement.type&&(this._handleBackspace(h),e.preventDefault())}}}},{key:"_onKeyUp",value:function(e){var t=this;if(e.target===this.input){String.fromCharCode(e.keyCode);if("text"===this.passedElement.type){var i=this.dropdown.classList.contains(this.config.classNames.activeState),n=void 0;if(this.input.value){var s=this.store.getItemsFilteredByActive(),o=!s.some(function(e){return e.value===t.input.value});n=this.config.maxItemCount&&this.config.maxItemCount>0&&this.config.maxItemCount<=this.itemList.children.length?this._getTemplate("notice","Only "+this.config.maxItemCount+" options can be added."):this.config.duplicateItems||o?this._getTemplate("notice",'Add "'+this.input.value+'"'):this._getTemplate("notice","Only unique values can be added."),(this.config.regexFilter&&this._regexFilter(this.input.value)||!this.config.regexFilter)&&(this.dropdown.innerHTML=n.outerHTML,this.dropdown.classList.contains(this.config.classNames.activeState)||this.showDropdown())}else i&&this.hideDropdown()}if(this.canSearch&&this.input===document.activeElement){var r=this.store.getChoices(),l=r.some(function(e){return e.active!==!0});if(this.input.value&&this.input.value.length>1){var h=function(){var e=(0,c.isType)("String",t.input.value)?t.input.value.trim():t.input.value,i=(0,c.isType)("String",t.currentValue)?t.currentValue.trim():t.currentValue;if(e.length>=1&&e!==i+" "){var n=t.store.getChoicesFiltedBySelectable(),s=e,o=new u.default(n,{keys:["label","value"],shouldSort:!0,include:"score"}),r=o.search(s);t.currentValue=e,t.highlightPosition=0,t.isSearching=!0,t.store.dispatch((0,a.filterChoices)(r))}};h()}else l&&(this.isSearching=!1,this.store.dispatch((0,a.activateChoices)(!0)))}}}},{key:"_onInput",value:function(e){"select-one"!==this.passedElement.type&&(this.input.style.width=(0,c.getWidthOfInput)(this.input))}},{key:"_onMouseDown",value:function(e){var t=this;if(2!==e.button){var i=this.store.getItemsFilteredByActive();if(this.containerOuter.contains(e.target))!function(){e.preventDefault();var n=!!e.shiftKey;"text"===t.passedElement.type||t.dropdown.classList.contains(t.config.classNames.activeState)||t.showDropdown(),t.input!==document.activeElement&&t.input.focus(),e.target.hasAttribute("data-button")?t.config.removeItems&&t.config.removeItemButton&&!function(){var n=e.target.parentNode.getAttribute("data-id"),s=i.find(function(e){return e.id===parseInt(n)});t._removeItem(s),t._triggerChange(s.value)}():e.target.hasAttribute("data-item")?t.config.removeItems&&!function(){var s=e.target.getAttribute("data-id");i.forEach(function(e){e.id!==parseInt(s)||e.highlighted?n||t.unhighlightItem(e):t.highlightItem(e)})}():e.target.hasAttribute("data-option")&&!function(){var i=e.target.getAttribute("data-id"),n=t.store.getChoicesFilteredByActive(),s=n.find(function(e){return e.id===parseInt(i)});s.selected||s.disabled||(t._addItem(s.value,s.label,s.id),t._triggerChange(s.value),"select-one"===t.passedElement.type&&(t.input.value="",t.isSearching=!1,t.store.dispatch((0,a.activateChoices)(!0)),t.toggleDropdown()))}()}();else{var n=this.dropdown.classList.contains(this.config.classNames.activeState),s=i.some(function(e){return e.highlighted===!0});s&&this.unhighlightAll(),this.containerOuter.classList.remove(this.config.classNames.focusState),n&&this.toggleDropdown()}}}},{key:"_onMouseOver",value:function(e){(e.target===this.dropdown||(0,c.findAncestor)(e.target,this.config.classNames.listDropdown))&&e.target.hasAttribute("data-option")&&this._highlightChoice(e.target)}},{key:"_onPaste",value:function(e){e.target===this.input&&(this.config.paste||e.preventDefault())}},{key:"_onFocus",value:function(e){var t=this.dropdown.classList.contains(this.config.classNames.activeState);e.target!==this.input||t?"select-one"!==this.passedElement.type||e.target!==this.containerOuter||t||(this.containerOuter.classList.add(this.config.classNames.focusState),this.showDropdown(),this.config.search&&this.input.focus()):(this.containerOuter.classList.add(this.config.classNames.focusState),"select-one"!==this.passedElement.type&&"select-multiple"!==this.passedElement.type||this.showDropdown())}},{key:"_onBlur",value:function(e){var t=this.dropdown.classList.contains(this.config.classNames.activeState);e.target===this.input&&this.containerOuter.classList.remove(this.config.classNames.focusState),t&&this.hideDropdown()}},{key:"_regexFilter",value:function(e){if(e){var t=new RegExp(this.config.regexFilter,"i");return t.test(e)}}},{key:"_scrollToChoice",value:function(e,t){var i=this;if(e){var n=this.choiceList.offsetHeight,s=e.offsetHeight,o=e.offsetTop+s,r=this.choiceList.scrollTop+n,a=t>0?this.choiceList.scrollTop+o-r:e.offsetTop,c=function l(e,t,n){var s=!1,o=void 0,r=void 0,a=4;n>0?(o=(t-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>t&&(s=!0)),s&&requestAnimationFrame(function(e){l(e,t,n)})};requestAnimationFrame(function(e){c(e,a,t)})}}},{key:"_highlightChoice",value:function(e){var t=this,i=Array.from(this.dropdown.querySelectorAll("[data-option-selectable]"));if(i&&i.length){var n=Array.from(this.dropdown.querySelectorAll("."+this.config.classNames.highlightedState));if(n.forEach(function(e){e.classList.remove(t.config.classNames.highlightedState)}),e)e.classList.add(this.config.classNames.highlightedState),this.highlightPosition=i.indexOf(e);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.config.classNames.highlightedState)}}}},{key:"_addItem",value:function(e,t){var i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=this.store.getItems(),s=(0,c.isType)("String",e)?e.trim():e,o=t||s,r=parseInt(i)||-1;this.config.prependValue&&(s=this.config.prependValue+s.toString()),this.config.appendValue&&(s+=this.config.appendValue.toString());var l=n?n.length+1:1;if(this.store.dispatch((0,a.addItem)(s,o,l,r)),"select-one"===this.passedElement.type&&this.removeActiveItems(l),this.config.callbackOnAddItem){var u=this.config.callbackOnAddItem;(0,c.isType)("Function",u)?u(l,s,this.passedElement):console.error("callbackOnAddItem: Callback is not a function")}return this}},{key:"_removeItem",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this.config.callbackOnRemoveItem:arguments[1];if(!e||!(0,c.isType)("Object",e))return void console.error("removeItem: No item object was passed to be removed");var i=e.id,n=(e.value,e.choiceId);return this.store.dispatch((0,a.removeItem)(i,n)),t?void((0,c.isType)("Function",t)||console.error("callbackOnRemoveItem: Callback is not a function")):this}},{key:"_addChoice",value:function(e,t,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,t)),e&&!t&&this._addItem(i,n,r)}}},{key:"_addGroup",value:function(e,t,i){var n=this,s=Array.from(e.getElementsByTagName("OPTION")),o=t;s?(this.store.dispatch((0,a.addGroup)(e.label,o,!0,e.disabled)),s.forEach(function(e,t){var i=e.disabled||e.parentNode.disabled;n._addChoice(e.selected,i,e.value,e.innerHTML,o)})):this.store.dispatch((0,a.addGroup)(e.label,e.id,!1,e.disabled))}},{key:"_getTemplate",value:function(e){if(e){for(var t=this.config.templates,i=arguments.length,n=Array(i>1?i-1:0),s=1;s\n '):(0,c.strToEl)('\n
\n ')},containerInner:function(){return(0,c.strToEl)('
')},itemList:function(){return(0,c.strToEl)('
')},item:function(i){return e.config.removeItemButton&&"select-one"!==e.passedElement.type?(0,c.strToEl)('\n
\n '+i.label+'\n \n
\n '):(0,c.strToEl)('\n
\n '+i.label+"\n
\n ")},choiceList:function(){return(0,c.strToEl)('
')},choiceGroup:function(e){return(0,c.strToEl)('\n
\n
'+e.value+"
\n
\n ")},choice:function(e){return(0,c.strToEl)('\n
\n '+e.label+"\n
\n ")},input:function(){return(0,c.strToEl)('')},dropdown:function(){return(0,c.strToEl)('
')},notice:function(e,i){return(0,c.strToEl)('
'+e+"
")},option:function(e){return(0,c.strToEl)('")}};this.config.templates=i}},{key:"_createInput",value:function(){var e=this,t=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=t,this.containerInner=i,this.input=o,this.choiceList=s,this.itemList=n,this.dropdown=r,this.passedElement.classList.add(this.config.classNames.input,this.config.classNames.hiddenState),this.passedElement.tabIndex="-1",this.passedElement.setAttribute("style","display:none;"),this.passedElement.setAttribute("aria-hidden","true"),this.passedElement.setAttribute("data-choice","active"),(0,c.wrap)(this.passedElement,i),(0,c.wrap)(i,t),this.config.placeholder&&(this.config.placeholderValue||this.passedElement.placeholder)){var a=this.config.placeholderValue||this.passedElement.placeholder;o.placeholder=a,"select-one"!==this.passedElement.type&&(o.style.width=(0,c.getWidthOfInput)(o))}if(this.config.addItems||this.disable(),t.appendChild(i),t.appendChild(r),i.appendChild(n),r.appendChild(s),"select-multiple"===this.passedElement.type||"text"===this.passedElement.type?i.appendChild(o):this.config.search&&r.insertBefore(o,r.firstChild),"select-multiple"===this.passedElement.type||"select-one"===this.passedElement.type){var l=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));this.highlightPosition=0,this.isSearching=!1,l&&l.length?l.forEach(function(t,i){var n=0===i;e._addGroup(t,i,n)}):!function(){var t=Array.from(e.passedElement.options),i=[];t.forEach(function(e){i.push({value:e.value,label:e.innerHTML,selected:e.selected,disabled:e.disabled||e.parentNode.disabled})}),i.concat(e.presetChoices).forEach(function(t,i){0===i?e._addChoice(!0,!!t.disabled&&t.disabled,t.value,t.label):e._addChoice(!!t.selected&&t.selected,!!t.disabled&&t.disabled,t.value,t.label)})}()}else"text"===this.passedElement.type&&this.presetItems.forEach(function(t){if((0,c.isType)("Object",t)){if(!t.value)return;e._addItem(t.value,t.label,t.id)}else(0,c.isType)("String",t)&&e._addItem(t)})}},{key:"renderGroups",value:function(e,t,i){var n=this,s=i||document.createDocumentFragment();return e.forEach(function(e,i){var o=t.filter(function(t){return"select-one"===n.passedElement.type?t.groupId===e.id:t.groupId===e.id&&!t.selected});if(o.length>=1){var r=n._getTemplate("choiceGroup",e);s.appendChild(r),n.renderChoices(o,s)}}),s}},{key:"renderChoices",value:function(e,t){var i=this,n=t||document.createDocumentFragment();return e.forEach(function(e,t){var s=i._getTemplate("choice",e);"select-one"===i.passedElement.type?n.appendChild(s):e.selected||n.appendChild(s)}),n}},{key:"renderItems",value:function(e,t){var i=this,n=t||document.createDocumentFragment(),s=this.store.getItemsReducedToValues(e);return"text"===this.passedElement.type?this.passedElement.setAttribute("value",s.join(this.config.delimiter)):!function(){var t=document.createDocumentFragment();e.forEach(function(e){var n=i._getTemplate("option",e);t.appendChild(n)}),i.passedElement.innerHTML="",i.passedElement.appendChild(t)}(),e.forEach(function(e){var t=i._getTemplate("item",e);n.appendChild(t)}),n}},{key:"render",value:function(){if(this.currentState=this.store.getState(),this.currentState!==this.prevState){if(!(this.currentState.choices===this.prevState.choices&&this.currentState.groups===this.prevState.groups||"select-multiple"!==this.passedElement.type&&"select-one"!==this.passedElement.type)){var e=this.store.getGroupsFilteredByActive(),t=this.store.getChoicesFilteredByActive(),i=document.createDocumentFragment();if(this.choiceList.innerHTML="",e.length>=1&&this.isSearching!==!0?i=this.renderGroups(e,t,i):t.length>=1&&(i=this.renderChoices(t,i)),i.childNodes&&i.childNodes.length>0)this.choiceList.appendChild(i),this._highlightChoice();else{var n=this.isSearching?this._getTemplate("notice","No results found"):this._getTemplate("notice","No choices to choose from");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&&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.passedElement.type&&"select-one"===this.passedElement.type&&this.containerOuter.addEventListener("focus",this._onFocus),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.passedElement.type&&"select-one"===this.passedElement.type&&this.containerOuter.removeEventListener("focus",this._onFocus),this.input.removeEventListener("input",this._onInput),this.input.removeEventListener("paste",this._onPaste),this.input.removeEventListener("focus",this._onFocus),this.input.removeEventListener("blur",this._onBlur)}}]),e}();window.Choices=e.exports=f},function(e,t){"use strict";Array.from||(Array.from=function(){var e=Object.prototype.toString,t=function(t){return"function"==typeof t||"[object Function]"===e.call(t)},i=function(e){var t=Number(e);return isNaN(t)?0:0!==t&&isFinite(t)?(t>0?1:-1)*Math.floor(Math.abs(t)):t},n=Math.pow(2,53)-1,s=function(e){var t=i(e);return Math.min(Math.max(t,0),n)};return function(e){var i=this,n=Object(e);if(null==e)throw new TypeError("Array.from requires an array-like object - not null or undefined");var o,r=arguments.length>1?arguments[1]:void 0;if("undefined"!=typeof r){if(!t(r))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(o=arguments[2])}for(var a,c=s(n.length),l=t(i)?Object(new i(c)):new Array(c),u=0;u=0?t:0},t.getElementOffset=function(e,t){var i=t;return i>1&&(i=1),i>0&&(i=0),Math.max(e.offsetHeight*i)},t.getAdjacentEl=function(e,t){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2]; +!function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return e[n].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var i={};return t.m=e,t.c=i,t.p="/assets/scripts/dist/",t(0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function s(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t1)for(var r=1;r=document.body.offsetHeight;return t?this.containerOuter.classList.add(this.config.classNames.flippedState):this.containerOuter.classList.remove(this.config.classNames.flippedState),this}},{key:"hideDropdown",value:function(){var e=this.containerOuter.classList.contains(this.config.classNames.flippedState);return this.containerOuter.classList.remove(this.config.classNames.openState),this.dropdown.classList.remove(this.config.classNames.activeState),e&&this.containerOuter.classList.remove(this.config.classNames.flippedState),this}},{key:"toggleDropdown",value:function(){return this.dropdown.classList.contains(this.config.classNames.activeState)?this.hideDropdown():this.showDropdown(),this}},{key:"setValue",value:function(e){var t=this;if(this.initialised===!0){var i=[].concat(s(e));i.forEach(function(e,i){if((0,c.isType)("Object",e)){if(!e.value)return;"text"!==t.passedElement.type?t._addChoice(!0,!1,e.value,e.label,-1):t._addItem(e.value,e.label,e.id)}else(0,c.isType)("String",e)&&("text"!==t.passedElement.type?t._addChoice(!0,!1,e,e,-1):t._addItem(e))})}return this}},{key:"setValueByChoice",value:function(e){var t=this;return"text"!==this.passedElement.type&&!function(){var i=t.store.getChoices();(0,c.isType)("Array",e)||(e=[e]),e.forEach(function(e,n){var s=i.find(function(t){return t.value===e});s?s.selected?console.warn("Attempting to select choice already selected"):t._addItem(s.value,s.label,s.id):console.warn("Attempting to select choice that does not exist")})}(),this}},{key:"setChoices",value:function(e,t,i){var n=this;if(this.initialised===!0&&("select-one"===this.passedElement.type||"select-multiple"===this.passedElement.type)){if(!(0,c.isType)("Array",e)||!t)return;e&&e.length&&(this.containerOuter.classList.remove(this.config.classNames.loadingState),e.forEach(function(e,s){0===s&&"select-one"===n.passedElement.type?n._addChoice(!0,!!e.disabled&&e.disabled,e[t],e[i]):n._addChoice(!!e.selected&&e.selected,!!e.disabled&&e.disabled,e[t],e[i])}))}return 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.config.classNames.disabledState)),this}},{key:"ajax",value:function(e){var t=this;if(this.initialised===!0&&("select-one"===this.passedElement.type||"select-multiple"===this.passedElement.type)){if(this.containerOuter.classList.add(this.config.classNames.loadingState),"select-one"===this.passedElement.type){var i=this._getTemplate("item",{id:-1,value:"Loading",label:this.config.loadingText,active:!0});this.itemList.appendChild(i)}var n=function(e,i,n){(0,c.isType)("Array",e)&&i&&e&&e.length&&(t.containerOuter.classList.remove(t.config.classNames.loadingState),e.forEach(function(e,s){0===s&&"select-one"===t.passedElement.type?t._addChoice(!0,!1,e[i],e[n]):t._addChoice(!1,!1,e[i],e[n])}))};e(n)}return 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:"_triggerChange",value:function(e){if(e&&this.config.callbackOnChange){var t=this.config.callbackOnChange;(0,c.isType)("Function",t)?t(e,this.passedElement):console.error("callbackOnChange: Callback is not a function")}}},{key:"_handleEnter",value:function(e,t){var i=!0;if(this.config.addItems?this.config.maxItemCount&&this.config.maxItemCount>0&&this.config.maxItemCount<=this.itemList.children.length?i=!1:this.config.duplicateItems===!1&&this.passedElement.value&&(i=!e.some(function(e){return e.value===t})):i=!1,i){var n=!0;this.config.regexFilter&&(n=this._regexFilter(t)),n&&(this.toggleDropdown(),this._addItem(t),this._triggerChange(t),this.clearInput(this.passedElement))}}},{key:"_handleBackspace",value:function(e){if(this.config.removeItems&&e){var t=e[e.length-1],i=e.some(function(e){return e.highlighted===!0});this.config.editItems&&!i&&t?(this.input.value=t.value,this._removeItem(t),this._triggerChange(t.value)):(i||this.highlightItem(t),this.removeHighlightedItems())}}},{key:"_onKeyDown",value:function(e){if(e.target===this.input){var t=e.ctrlKey||e.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),f=this.dropdown.classList.contains(this.config.classNames.activeState),p=this.itemList&&this.itemList.children,v=String.fromCharCode(e.keyCode);switch("text"!==this.passedElement.type&&/[a-zA-Z0-9-_ ]/.test(v)&&!f&&this.showDropdown(),this.canSearch=this.config.search,e.keyCode){case o:t&&p&&(this.canSearch=!1,this.config.removeItems&&!this.input.value&&this.input===document.activeElement&&this.highlightAll(this.itemList.children));break;case s:if(e.target.value&&"text"===this.passedElement.type){var m=this.input.value;this._handleEnter(h,m)}if(f){var g=this.dropdown.querySelector("."+this.config.classNames.highlightedState);if(g){var y=g.getAttribute("data-value"),b=g.innerHTML,_=g.getAttribute("data-id");this._addItem(y,b,_),this._triggerChange(y),this.clearInput(this.passedElement),"select-one"===this.passedElement.type&&(this.isSearching=!1,this.store.dispatch((0,a.activateChoices)()),this.toggleDropdown())}}break;case r:f&&this.toggleDropdown();break;case u:case l:if(f){var E=this.dropdown.querySelector("."+this.config.classNames.highlightedState),I=e.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)),e.preventDefault()}break;case i:case n:d&&!e.target.value&&"select-one"!==this.passedElement.type&&(this._handleBackspace(h),e.preventDefault())}}}},{key:"_onKeyUp",value:function(e){var t=this;if(e.target===this.input){String.fromCharCode(e.keyCode);if("text"===this.passedElement.type){var i=this.dropdown.classList.contains(this.config.classNames.activeState),n=void 0;if(this.input.value){var s=this.store.getItemsFilteredByActive(),o=!s.some(function(e){return e.value===t.input.value});n=this.config.maxItemCount&&this.config.maxItemCount>0&&this.config.maxItemCount<=this.itemList.children.length?this._getTemplate("notice","Only "+this.config.maxItemCount+" options can be added."):this.config.duplicateItems||o?this._getTemplate("notice",'Add "'+this.input.value+'"'):this._getTemplate("notice","Only unique values can be added."),(this.config.regexFilter&&this._regexFilter(this.input.value)||!this.config.regexFilter)&&(this.dropdown.innerHTML=n.outerHTML,this.dropdown.classList.contains(this.config.classNames.activeState)||this.showDropdown())}else i&&this.hideDropdown()}if(this.canSearch&&this.input===document.activeElement){var r=this.store.getChoices(),l=r.some(function(e){return e.active!==!0});if(this.input.value&&this.input.value.length>1){var h=function(){var e=(0,c.isType)("String",t.input.value)?t.input.value.trim():t.input.value,i=(0,c.isType)("String",t.currentValue)?t.currentValue.trim():t.currentValue;if(e.length>=1&&e!==i+" "){var n=t.store.getChoicesFiltedBySelectable(),s=e,o=new u.default(n,{keys:["label","value"],shouldSort:!0,include:"score"}),r=o.search(s);t.currentValue=e,t.highlightPosition=0,t.isSearching=!0,t.store.dispatch((0,a.filterChoices)(r))}};h()}else l&&(this.isSearching=!1,this.store.dispatch((0,a.activateChoices)(!0)))}}}},{key:"_onInput",value:function(e){"select-one"!==this.passedElement.type&&(this.input.style.width=(0,c.getWidthOfInput)(this.input))}},{key:"_onMouseDown",value:function(e){var t=this;if(2!==e.button){var i=this.store.getItemsFilteredByActive();if(this.containerOuter.contains(e.target))!function(){e.preventDefault();var n=!!e.shiftKey;"text"===t.passedElement.type||t.dropdown.classList.contains(t.config.classNames.activeState)||t.showDropdown(),t.input!==document.activeElement&&t.input.focus(),e.target.hasAttribute("data-button")?t.config.removeItems&&t.config.removeItemButton&&!function(){var n=e.target.parentNode.getAttribute("data-id"),s=i.find(function(e){return e.id===parseInt(n)});t._removeItem(s),t._triggerChange(s.value)}():e.target.hasAttribute("data-item")?t.config.removeItems&&!function(){var s=e.target.getAttribute("data-id");i.forEach(function(e){e.id!==parseInt(s)||e.highlighted?n||t.unhighlightItem(e):t.highlightItem(e)})}():e.target.hasAttribute("data-option")&&!function(){var i=e.target.getAttribute("data-id"),n=t.store.getChoicesFilteredByActive(),s=n.find(function(e){return e.id===parseInt(i)});s.selected||s.disabled||(t._addItem(s.value,s.label,s.id),t._triggerChange(s.value),"select-one"===t.passedElement.type&&(t.input.value="",t.isSearching=!1,t.store.dispatch((0,a.activateChoices)(!0)),t.toggleDropdown()))}()}();else{var n=this.dropdown.classList.contains(this.config.classNames.activeState),s=i.some(function(e){return e.highlighted===!0});s&&this.unhighlightAll(),this.containerOuter.classList.remove(this.config.classNames.focusState),n&&this.toggleDropdown()}}}},{key:"_onMouseOver",value:function(e){(e.target===this.dropdown||(0,c.findAncestor)(e.target,this.config.classNames.listDropdown))&&e.target.hasAttribute("data-option")&&this._highlightChoice(e.target)}},{key:"_onPaste",value:function(e){e.target===this.input&&(this.config.paste||e.preventDefault())}},{key:"_onFocus",value:function(e){var t=this.dropdown.classList.contains(this.config.classNames.activeState);e.target!==this.input||t?"select-one"!==this.passedElement.type||e.target!==this.containerOuter||t||(this.containerOuter.classList.add(this.config.classNames.focusState),this.showDropdown(),this.canSearch&&this.input.focus()):(this.containerOuter.classList.add(this.config.classNames.focusState),"select-one"!==this.passedElement.type&&"select-multiple"!==this.passedElement.type||this.showDropdown())}},{key:"_onBlur",value:function(e){var t=this.dropdown.classList.contains(this.config.classNames.activeState);e.target===this.input&&this.containerOuter.classList.remove(this.config.classNames.focusState),t&&this.hideDropdown()}},{key:"_regexFilter",value:function(e){if(e){var t=new RegExp(this.config.regexFilter,"i");return t.test(e)}}},{key:"_scrollToChoice",value:function(e,t){var i=this;if(e){var n=this.choiceList.offsetHeight,s=e.offsetHeight,o=e.offsetTop+s,r=this.choiceList.scrollTop+n,a=t>0?this.choiceList.scrollTop+o-r:e.offsetTop,c=function l(e,t,n){var s=!1,o=void 0,r=void 0,a=4;n>0?(o=(t-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>t&&(s=!0)),s&&requestAnimationFrame(function(e){l(e,t,n)})};requestAnimationFrame(function(e){c(e,a,t)})}}},{key:"_highlightChoice",value:function(e){var t=this,i=Array.from(this.dropdown.querySelectorAll("[data-option-selectable]"));if(i&&i.length){var n=Array.from(this.dropdown.querySelectorAll("."+this.config.classNames.highlightedState));if(n.forEach(function(e){e.classList.remove(t.config.classNames.highlightedState)}),e)e.classList.add(this.config.classNames.highlightedState),this.highlightPosition=i.indexOf(e);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.config.classNames.highlightedState)}}}},{key:"_addItem",value:function(e,t){var i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=this.store.getItems(),s=(0,c.isType)("String",e)?e.trim():e,o=t||s,r=parseInt(i)||-1;this.config.prependValue&&(s=this.config.prependValue+s.toString()),this.config.appendValue&&(s+=this.config.appendValue.toString());var l=n?n.length+1:1;if(this.store.dispatch((0,a.addItem)(s,o,l,r)),"select-one"===this.passedElement.type&&this.removeActiveItems(l),this.config.callbackOnAddItem){var u=this.config.callbackOnAddItem;(0,c.isType)("Function",u)?u(l,s,this.passedElement):console.error("callbackOnAddItem: Callback is not a function")}return this}},{key:"_removeItem",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this.config.callbackOnRemoveItem:arguments[1];if(!e||!(0,c.isType)("Object",e))return void console.error("removeItem: No item object was passed to be removed");var i=e.id,n=(e.value,e.choiceId);return this.store.dispatch((0,a.removeItem)(i,n)),t?void((0,c.isType)("Function",t)||console.error("callbackOnRemoveItem: Callback is not a function")):this}},{key:"_addChoice",value:function(e,t,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,t)),e&&!t&&this._addItem(i,n,r)}}},{key:"_addGroup",value:function(e,t,i){var n=this,s=Array.from(e.getElementsByTagName("OPTION")),o=t;s?(this.store.dispatch((0,a.addGroup)(e.label,o,!0,e.disabled)),s.forEach(function(e,t){var i=e.disabled||e.parentNode.disabled;n._addChoice(e.selected,i,e.value,e.innerHTML,o)})):this.store.dispatch((0,a.addGroup)(e.label,e.id,!1,e.disabled))}},{key:"_getTemplate",value:function(e){if(e){for(var t=this.config.templates,i=arguments.length,n=Array(i>1?i-1:0),s=1;s\n '):(0,c.strToEl)('\n
\n ')},containerInner:function(){return(0,c.strToEl)('
')},itemList:function(){return(0,c.strToEl)('
')},item:function(i){return e.config.removeItemButton&&"select-one"!==e.passedElement.type?(0,c.strToEl)('\n
\n '+i.label+'\n \n
\n '):(0,c.strToEl)('\n
\n '+i.label+"\n
\n ")},choiceList:function(){return(0,c.strToEl)('
')},choiceGroup:function(e){return(0,c.strToEl)('\n
\n
'+e.value+"
\n
\n ")},choice:function(e){return(0,c.strToEl)('\n
\n '+e.label+"\n
\n ")},input:function(){return(0,c.strToEl)('')},dropdown:function(){return(0,c.strToEl)('
')},notice:function(e,i){return(0,c.strToEl)('
'+e+"
")},option:function(e){return(0,c.strToEl)('")}};this.config.templates=i}},{key:"_createInput",value:function(){var e=this,t=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=t,this.containerInner=i,this.input=o,this.choiceList=s,this.itemList=n,this.dropdown=r,this.passedElement.classList.add(this.config.classNames.input,this.config.classNames.hiddenState),this.passedElement.tabIndex="-1",this.passedElement.setAttribute("style","display:none;"),this.passedElement.setAttribute("aria-hidden","true"),this.passedElement.setAttribute("data-choice","active"),(0,c.wrap)(this.passedElement,i),(0,c.wrap)(i,t),this.config.placeholder&&(this.config.placeholderValue||this.passedElement.placeholder)){var a=this.config.placeholderValue||this.passedElement.placeholder;o.placeholder=a,"select-one"!==this.passedElement.type&&(o.style.width=(0,c.getWidthOfInput)(o))}if(this.config.addItems||this.disable(),t.appendChild(i),t.appendChild(r),i.appendChild(n),r.appendChild(s),"select-multiple"===this.passedElement.type||"text"===this.passedElement.type?i.appendChild(o):this.config.search&&r.insertBefore(o,r.firstChild),"select-multiple"===this.passedElement.type||"select-one"===this.passedElement.type){var l=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));this.highlightPosition=0,this.isSearching=!1,l&&l.length?l.forEach(function(t,i){var n=0===i;e._addGroup(t,i,n)}):!function(){var t=Array.from(e.passedElement.options),i=[];t.forEach(function(e){i.push({value:e.value,label:e.innerHTML,selected:e.selected,disabled:e.disabled||e.parentNode.disabled})}),i.concat(e.presetChoices).forEach(function(t,i){0===i?e._addChoice(!0,!!t.disabled&&t.disabled,t.value,t.label):e._addChoice(!!t.selected&&t.selected,!!t.disabled&&t.disabled,t.value,t.label)})}()}else"text"===this.passedElement.type&&this.presetItems.forEach(function(t){if((0,c.isType)("Object",t)){if(!t.value)return;e._addItem(t.value,t.label,t.id)}else(0,c.isType)("String",t)&&e._addItem(t)})}},{key:"renderGroups",value:function(e,t,i){var n=this,s=i||document.createDocumentFragment();return e.forEach(function(e,i){var o=t.filter(function(t){return"select-one"===n.passedElement.type?t.groupId===e.id:t.groupId===e.id&&!t.selected});if(o.length>=1){var r=n._getTemplate("choiceGroup",e);s.appendChild(r),n.renderChoices(o,s)}}),s}},{key:"renderChoices",value:function(e,t){var i=this,n=t||document.createDocumentFragment();return e.forEach(function(e,t){var s=i._getTemplate("choice",e);"select-one"===i.passedElement.type?n.appendChild(s):e.selected||n.appendChild(s)}),n}},{key:"renderItems",value:function(e,t){var i=this,n=t||document.createDocumentFragment(),s=this.store.getItemsReducedToValues(e);return"text"===this.passedElement.type?this.passedElement.setAttribute("value",s.join(this.config.delimiter)):!function(){var t=document.createDocumentFragment();e.forEach(function(e){var n=i._getTemplate("option",e);t.appendChild(n)}),i.passedElement.innerHTML="",i.passedElement.appendChild(t)}(),e.forEach(function(e){var t=i._getTemplate("item",e);n.appendChild(t)}),n}},{key:"render",value:function(){if(this.currentState=this.store.getState(),this.currentState!==this.prevState){if(!(this.currentState.choices===this.prevState.choices&&this.currentState.groups===this.prevState.groups||"select-multiple"!==this.passedElement.type&&"select-one"!==this.passedElement.type)){var e=this.store.getGroupsFilteredByActive(),t=this.store.getChoicesFilteredByActive(),i=document.createDocumentFragment();if(this.choiceList.innerHTML="",this.choiceList.scrollTop=0,e.length>=1&&this.isSearching!==!0?i=this.renderGroups(e,t,i):t.length>=1&&(i=this.renderChoices(t,i)),i.childNodes&&i.childNodes.length>0)this.choiceList.appendChild(i),this._highlightChoice();else{var n=this.isSearching?this._getTemplate("notice","No results found"):this._getTemplate("notice","No choices to choose from");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&&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.passedElement.type&&"select-one"===this.passedElement.type&&this.containerOuter.addEventListener("focus",this._onFocus),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.passedElement.type&&"select-one"===this.passedElement.type&&this.containerOuter.removeEventListener("focus",this._onFocus),this.input.removeEventListener("input",this._onInput),this.input.removeEventListener("paste",this._onPaste),this.input.removeEventListener("focus",this._onFocus),this.input.removeEventListener("blur",this._onBlur)}}]),e}();window.Choices=e.exports=f},function(e,t){"use strict";Array.from||(Array.from=function(){var e=Object.prototype.toString,t=function(t){return"function"==typeof t||"[object Function]"===e.call(t)},i=function(e){var t=Number(e);return isNaN(t)?0:0!==t&&isFinite(t)?(t>0?1:-1)*Math.floor(Math.abs(t)):t},n=Math.pow(2,53)-1,s=function(e){var t=i(e);return Math.min(Math.max(t,0),n)};return function(e){var i=this,n=Object(e);if(null==e)throw new TypeError("Array.from requires an array-like object - not null or undefined");var o,r=arguments.length>1?arguments[1]:void 0;if("undefined"!=typeof r){if(!t(r))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(o=arguments[2])}for(var a,c=s(n.length),l=t(i)?Object(new i(c)):new Array(c),u=0;u=0?t:0},t.getElementOffset=function(e,t){var i=t;return i>1&&(i=1),i>0&&(i=0),Math.max(e.offsetHeight*i)},t.getAdjacentEl=function(e,t){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2]; if(e&&t){var n=e.parentNode.parentNode,s=Array.from(n.querySelectorAll(t)),o=s.indexOf(e),r=i>0?1:-1;return s[o+r]}},t.getScrollPosition=function(e){return"bottom"===e?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},t.isInView=function(e,t,i){return this.getScrollPosition(t)>this.getElemDistance(e)+this.getElementOffset(e,i)},t.isScrolledIntoView=function(e,t){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(e){var n=void 0;return n=i>0?t.scrollTop+t.offsetHeight>=e.offsetTop+e.offsetHeight:e.offsetTop>=t.scrollTop}},t.stripHTML=function(e){var t=document.createElement("DIV");return t.innerHTML=e,t.textContent||t.innerText||""},t.addAnimation=function(e,t){var i=s(),n=function o(){e.classList.remove(t),e.removeEventListener(i,o,!1)};e.classList.add(t),e.addEventListener(i,n,!1)},t.getRandomNumber=function(e,t){return Math.floor(Math.random()*(t-e)+e)},t.strToEl=function(){var e=document.createElement("div");return function(t){var i;for(e.innerHTML=t,i=e.children[0];e.firstChild;)e.removeChild(e.firstChild);return i}}());t.getWidthOfInput=function(e){var t=e.value||e.placeholder,i=e.offsetWidth;if(t){var n=o(""+t+"");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),t&&n.offsetWidth!==e.offsetWidth&&(i=n.offsetWidth+4),document.body.removeChild(n)}return i+"px"},t.sortByAlpha=function(e,t){var i=(e.label||e.value).toLowerCase(),n=(t.label||t.value).toLowerCase();return in?1:0}},function(e,t,i){!function(t){"use strict";function i(){console.log.apply(console,arguments)}function n(e,t){var i,n,s,o;for(this.list=e,this.options=t=t||{},i=0,o=["sort","shouldSort","verbose","tokenize"],n=o.length;i1)throw new Error("Key weight has to be > 0 and <= 1");e=e.name}else this._keyMap[e]={weight:1};this._analyze(e,o(u,e,[]),u,i)}},n.prototype._analyze=function(e,t,n,s){var r,c,l,u,h,d,f,p,v,m,g,y,b,_,E,I=this.options,w=!1;if(void 0!==t&&null!==t)if(c=[],"string"==typeof t){if(r=t.split(a),I.verbose&&i("---------\nKey:",e),I.verbose&&i("Record:",r),this.options.tokenize){for(l=this.tokenSearchers,u=l.length,_=0;_0){if(t={item:r.item},u.indexOf("matches")!==-1)for(n=r.output,t.matches=[],i=0;iS.maxPatternLength){if(y=e.match(new RegExp(this.pattern.replace(a,"|"))),b=!!y)for(E=[],t=0,I=y.length;t=h;i--)if(v=this.patternAlphabet[e.charAt(i-1)],v&&(_[i-1]=1),0===t?f[i]=(f[i+1]<<1|1)&v:f[i]=(f[i+1]<<1|1)&v|((p[i+1]|p[i])<<1|1)|p[i+1],f[i]&this.matchmask&&(m=this._bitapScore(t,i-1),m<=o)){if(o=m,r=i-1,g.push(r),!(r>s))break;h=Math.max(1,2*s-r)}if(this._bitapScore(t+1,s)>o)break;p=f}return E=this._getMatchedIndices(_),{isMatch:r>=0,score:0===m?.001:m,matchedIndices:E}},r.prototype._getMatchedIndices=function(e){for(var t,i=[],n=-1,s=-1,o=0,r=r=e.length;o-1&&(i=e.map(function(e){return e.id===parseInt(t.choiceId)&&(e.selected=!0),e})),{v:i};case"REMOVE_ITEM":return t.choiceId>-1?{v:e.map(function(e){return e.id===parseInt(t.choiceId)&&(e.selected=!1),e})}:{v:e};case"FILTER_CHOICES":var s=t.results,r=e.map(function(e,t){return e.active=s.some(function(t){if(t.item.id===e.id)return e.score=t.score,!0}),e}).sort(function(e,t){return e.score-t.score});return{v:r};case"ACTIVATE_CHOICES":return{v:e.map(function(e){return e.active=t.active,e}).sort(o.sortByAlpha)};default:return{v:e}}}();if("object"===("undefined"==typeof i?"undefined":s(i)))return i.v};t.default=r}]); \ No newline at end of file diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 4e420fd..73ca652 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -814,7 +814,7 @@ export class Choices { this.store.dispatch(filterChoices(results)); } }; - + handleFilter(); } else if(hasUnactiveChoices) { // Otherwise reset choices to active @@ -973,7 +973,7 @@ export class Choices { } else if(this.passedElement.type === 'select-one' && e.target === this.containerOuter && !hasActiveDropdown) { this.containerOuter.classList.add(this.config.classNames.focusState); this.showDropdown(); - if(this.config.search) { + if(this.canSearch) { this.input.focus(); } } @@ -1394,6 +1394,7 @@ export class Choices { }); }); + // Join choices with preset choices and add them allChoices .concat(this.presetChoices) .forEach((o, index) => { @@ -1428,26 +1429,25 @@ export class Choices { renderGroups(groups, choices, fragment) { const groupFragment = fragment || document.createDocumentFragment(); - groups - .forEach((group, i) => { - // Grab options that are children of this group - const groupChoices = choices.filter((choice) => { - if(this.passedElement.type === 'select-one') { - return choice.groupId === group.id - } else { - return choice.groupId === group.id && !choice.selected; - } - }); - - if(groupChoices.length >= 1) { - const dropdownGroup = this._getTemplate('choiceGroup', group); - - groupFragment.appendChild(dropdownGroup); - - this.renderChoices(groupChoices, groupFragment); + groups.forEach((group, i) => { + // Grab options that are children of this group + const groupChoices = choices.filter((choice) => { + if(this.passedElement.type === 'select-one') { + return choice.groupId === group.id + } else { + return choice.groupId === group.id && !choice.selected; } }); + if(groupChoices.length >= 1) { + const dropdownGroup = this._getTemplate('choiceGroup', group); + + groupFragment.appendChild(dropdownGroup); + + this.renderChoices(groupChoices, groupFragment); + } + }); + return groupFragment; } @@ -1462,16 +1462,15 @@ export class Choices { // Create a fragment to store our list items (so we don't have to update the DOM for each item) const choicesFragment = fragment || document.createDocumentFragment(); - choices - .forEach((choice, i) => { - const dropdownItem = this._getTemplate('choice', choice); + choices.forEach((choice, i) => { + const dropdownItem = this._getTemplate('choice', choice); - if(this.passedElement.type === 'select-one') { - choicesFragment.appendChild(dropdownItem); - } else if(!choice.selected) { - choicesFragment.appendChild(dropdownItem); - } - }); + if(this.passedElement.type === 'select-one') { + choicesFragment.appendChild(dropdownItem); + } else if(!choice.selected) { + choicesFragment.appendChild(dropdownItem); + } + }); return choicesFragment; } @@ -1543,6 +1542,8 @@ export class Choices { // Clear choices this.choiceList.innerHTML = ''; + // Scroll back to top of choices list + this.choiceList.scrollTop = 0; // If we have grouped options if(activeGroups.length >= 1 && this.isSearching !== true) { diff --git a/assets/styles/css/base.css b/assets/styles/css/base.css index 6e0f138..e80ce13 100644 --- a/assets/styles/css/base.css +++ b/assets/styles/css/base.css @@ -1,6 +1,10 @@ /*============================================= = Generic styling = =============================================*/ +* { + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; } + *, *:before, *:after { box-sizing: border-box; } @@ -8,16 +12,20 @@ html { font-size: 62.5%; } html, body { + position: relative; margin: 0; - height: 100%; - widows: 100%; } + width: 100%; } body { - background-color: #333333; font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; font-size: 1.6rem; line-height: 1.4; - color: #FFFFFF; } + color: #FFFFFF; + background-color: #333; + background: -webkit-linear-gradient(right top, #333, #262626); + background: linear-gradient(to left bottom, #333, #262626); + height: 100%; + overflow-x: hidden; } label { display: block; @@ -39,9 +47,9 @@ h1, h2, h3, h4, h5, h6 { line-height: 1.2; } a, a:visited, a:focus { - color: #00bcd4; + color: #FFFFFF; text-decoration: none; - font-weight: bolder; } + font-weight: 600; } h1, .h1 { font-size: 3.2rem; } @@ -64,12 +72,17 @@ h6, .h6 { .container { display: block; margin: auto; - max-width: 35em; - padding: 2.4rem; } + max-width: 40em; + padding: 4.8rem; } + @media (max-width: 620px) { + .container { + padding: 0; } } .section { background-color: #FFFFFF; padding: 2.4rem; color: #333; } + .section a, .section a:visited, .section a:focus { + color: #00bcd4; } /*===== End of Section comment block ======*/ diff --git a/assets/styles/css/base.min.css b/assets/styles/css/base.min.css index 03e7df5..ee4bdf8 100644 --- a/assets/styles/css/base.min.css +++ b/assets/styles/css/base.min.css @@ -1 +1 @@ -*,:after,:before{box-sizing:border-box}body,html{margin:0;height:100%;widows:100%}html{font-size:62.5%}body{background-color:#333;font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:1.6rem;line-height:1.4;color:#fff}hr,label{display:block}label{margin-bottom:.8rem;font-size:1.4rem;font-weight:500}hr{margin:3.6rem 0;border:0;border-bottom:1px solid #eaeaea;height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:1.2rem;font-weight:400;line-height:1.2}a,a:focus,a:visited{color:#00bcd4;text-decoration:none;font-weight:bolder}.h1,h1{font-size:3.2rem}.h2,h2{font-size:2.4rem}.h3,h3{font-size:2rem}.h4,h4{font-size:1.8rem}.h5,h5{font-size:1.6rem}.h6,h6{font-size:1.4rem}.container{display:block;margin:auto;max-width:35em;padding:2.4rem}.section{background-color:#fff;padding:2.4rem;color:#333} \ No newline at end of file +*{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}*,:after,:before{box-sizing:border-box}body,html{position:relative;margin:0;width:100%}html{font-size:62.5%}body{font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:1.6rem;line-height:1.4;color:#fff;background-color:#333;background:-webkit-linear-gradient(right top,#333,#262626);background:linear-gradient(to left bottom,#333,#262626);height:100%;overflow-x:hidden}hr,label{display:block}label{margin-bottom:.8rem;font-size:1.4rem;font-weight:500}hr{margin:3.6rem 0;border:0;border-bottom:1px solid #eaeaea;height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:1.2rem;font-weight:400;line-height:1.2}a,a:focus,a:visited{color:#fff;text-decoration:none;font-weight:600}.h1,h1{font-size:3.2rem}.h2,h2{font-size:2.4rem}.h3,h3{font-size:2rem}.h4,h4{font-size:1.8rem}.h5,h5{font-size:1.6rem}.h6,h6{font-size:1.4rem}.container{display:block;margin:auto;max-width:40em;padding:4.8rem}@media (max-width:620px){.container{padding:0}}.section{background-color:#fff;padding:2.4rem;color:#333}.section a,.section a:focus,.section a:visited{color:#00bcd4} \ No newline at end of file diff --git a/assets/styles/scss/base.scss b/assets/styles/scss/base.scss index 9892a2f..7c4769e 100644 --- a/assets/styles/scss/base.scss +++ b/assets/styles/scss/base.scss @@ -10,26 +10,33 @@ $global-font-size-h6: 1.4rem; = Generic styling = =============================================*/ +* { + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale +} + + *, *:before, *:after { box-sizing: border-box } -html { - font-size: 62.5%; -} +html { font-size: 62.5%; } html, body { + position: relative; margin: 0; - height: 100%; - widows: 100%; + width: 100%; } body { - background-color: #333333; font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; font-size: 1.6rem; line-height: 1.4; color: #FFFFFF; + background-color: #333; + background: linear-gradient(to left bottom,#333,#262626); + height: 100%; + overflow-x: hidden; } label { @@ -55,9 +62,9 @@ h1, h2, h3, h4, h5, h6 { } a, a:visited, a:focus { - color: #00bcd4; + color: #FFFFFF; text-decoration: none; - font-weight: bolder; + font-weight: 600; } h1, .h1 { font-size: $global-font-size-h1; } @@ -70,14 +77,16 @@ h6, .h6 { font-size: $global-font-size-h6; } .container { display: block; margin: auto; - max-width: 35em; - padding: $global-guttering; + max-width: 40em; + padding: $global-guttering*2; + @media (max-width: 620px) { padding: 0; } } .section { background-color: #FFFFFF; padding: $global-guttering; color: #333; + a, a:visited, a:focus { color: #00bcd4; } } /*===== End of Section comment block ======*/ \ No newline at end of file diff --git a/index.html b/index.html index 7440c25..f8d0c7d 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,8 @@ Choices - + + @@ -16,9 +17,10 @@
-

Choices

+

Choices.js

A lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.

For all config options, visit the GitHub repo.

+

Text inputs

@@ -187,7 +189,7 @@ items: ['josh@joshuajohnson.co.uk', { value: 'joe@bloggs.co.uk', label: 'Joe Bloggs' } ], }); - var choices7 = new Choices('#choices-7', { search: false }).setValue(['Set value 1', 'Set value 2']); + var choices7 = new Choices('#choices-7', { search: false }); var choices10 = new Choices('#choices-10', { placeholder: true, @@ -250,9 +252,7 @@ {value: 'Two', label: 'Label Two', disabled: true}, {value: 'Three', label: 'Label Three'}, ], - }); - - choices15.setChoices([ + }).setChoices([ {value: 'Four', label: 'Label Four', disabled: true}, {value: 'Five', label: 'Label Five'}, {value: 'Six', label: 'Label Six', selected: true}, @@ -264,9 +264,7 @@ {value: 'Two', label: 'Label Two', disabled: true}, {value: 'Three', label: 'Label Three'}, ], - }); - - choices16.setValueByChoice('Two'); + }).setValueByChoice('Two'); }); diff --git a/package.json b/package.json index ab853c0..5a4a549 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "choices.js", - "version": "1.0.2", + "version": "1.0.3", "description": "A vanilla JS customisable text input/select box plugin", "main": "./assets/scripts/dist/choices.min.js", "scripts": {