diff --git a/assets/scripts/dist/bundle.js b/assets/scripts/dist/bundle.js index e2e312b..fe55983 100644 --- a/assets/scripts/dist/bundle.js +++ b/assets/scripts/dist/bundle.js @@ -1,2 +1,2 @@ -!function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="/assets/scripts/dist/",e(0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Choices=void 0;var o=function(){function t(t,e){for(var n=0;n1)for(var u=1;u')},containerInner:function(){return(0,l.strToEl)('
')},list:function(){return(0,l.strToEl)('')},input:function(){return(0,l.strToEl)('')},dropdown:function(){return(0,l.strToEl)('
')},notice:function(t){return(0,l.strToEl)('
'+t+"
")},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(t){return(0,l.strToEl)('\n
\n '+t.label+"\n
\n ")}},this.init()}return o(t,[{key:"handleEnter",value:function(t,e){var n=!0;if("text"===this.passedElement.type&&(this.options.addItems?this.options.maxItems&&this.options.maxItems<=this.list.children.length?n=!1:this.options.allowDuplicates===!1&&this.passedElement.value&&(n=!t.some(function(t){return t.value===e})):n=!1,n)){var i=!0;this.options.regexFilter&&(i=this.regexFilter(e)),i&&(this.addItem(e),this.clearInput(this.passedElement))}}},{key:"handleBackspaceKey",value:function(t){if(this.options.removeItems&&t){var e=t[t.length-1],n=t.some(function(t){return t.selected===!0});this.options.editItems&&!n&&e?(this.input.value=e.value,this.removeItem(e)):(this.selectItem(e),this.removeAllSelectedItems())}}},{key:"handleClick",value:function(t,e,n){var i=this;this.options.removeItems&&e&&!function(){var r=e.getAttribute("data-choice-id");t.forEach(function(t){t.id!==parseInt(r)||t.selected?n||i.deselectItem(t):i.selectItem(t)})}()}},{key:"onKeyDown",value:function(t){var e=this.getItemsFilteredByActive(),n=this.getOptionsFilteredByActive(),i=this.input===document.activeElement,r=t.ctrlKey||t.metaKey,o=46,s=8,a=13,c=65,u=27,l=38,d=40,h=this.dropdown&&this.dropdown.classList.contains(this.options.classNames.activeState),p=this.list&&this.list.children;if(t.target===this.input)switch(t.keyCode){case c:r&&p&&this.options.removeItems&&!this.input.value&&this.options.selectAll&&this.input===document.activeElement&&this.selectAll(this.list.children);break;case a:if(t.target.value&&"text"===this.passedElement.type){var f=this.input.value;this.handleEnter(e,f)}if("select-multiple"===this.passedElement.type&&h){var v=this.dropdown.querySelector("."+this.options.classNames.highlightedState);if(v){var m=v.getAttribute("data-choice-value"),y=v.innerHTML,g=v.getAttribute("data-choice-id");this.addItem(m,y,g),this.input.value=""}}break;case u:"select-multiple"===this.passedElement.type&&h&&this.toggleDropdown();break;case d:case l:if("select-multiple"===this.passedElement.type&&h){var b=n.filter(function(t){return!t.selected}),I=!0;if(t.keyCode===d?this.highlightPosition0?this.highlightPosition--:I=!1),I){var E=b[this.highlightPosition];if(E){var w=this.dropdown.querySelector("."+this.options.classNames.highlightedState),O=this.dropdown.querySelector('[data-choice-id="'+E.id+'"]');w&&w.classList.remove(this.options.classNames.highlightedState),O&&O.classList.add(this.options.classNames.highlightedState)}}}break;case o:case s:i&&!t.target.value&&(this.handleBackspaceKey(e),t.preventDefault())}}},{key:"onKeyUp",value:function(t){var e=this;if(t.target===this.input&&"select-multiple"===this.passedElement.type&&this.options.allowSearch){var n=String.fromCharCode(t.keyCode);if(this.input===document.activeElement&&/[a-z0-9]/i.test(n))if(this.input.value){var i=(0,l.debounce)(function(){var t=e.getOptionsFiltedBySelectable(),n=new h.default(t),i=n.search(e.input.value,{fields:["label","value"],sort:[{field:"value",direction:"asc"}],limit:10});e.store.dispatch((0,u.filterOptions)(i))},100);i()}else this.store.dispatch((0,u.activateOptions)())}}},{key:"onClick",value:function(t){var e=this,n=this.getItemsFilteredByActive(),i=!!t.shiftKey;if(this.dropdown&&this.toggleDropdown(),this.containerOuter.contains(t.target))this.input!==document.activeElement&&this.input.focus(),t.target.hasAttribute("data-choice-item")?this.handleClick(n,t.target,i):t.target.hasAttribute("data-choice-option")&&!function(){var n=e.getOptionsFilteredByActive(),i=t.target.getAttribute("data-choice-id"),r=n.find(function(t){return t.id===parseInt(i)});r.selected||e.addItem(r.value,r.label,r.id)}();else{var r=n.some(function(t){return t.selected===!0});r&&this.deselectAll(),"select-multiple"===this.passedElement.type&&this.dropdown.classList.contains(this.options.classNames.activeState)&&this.toggleDropdown()}}},{key:"onPaste",value:function(t){this.options.allowPaste||t.preventDefault()}},{key:"onFocus",value:function(t){this.containerOuter.classList.add(this.options.classNames.activeState)}},{key:"onBlur",value:function(t){this.containerOuter.classList.remove(this.options.classNames.activeState)}},{key:"clearInput",value:function(){this.input.value&&(this.input.value="")}},{key:"regexFilter",value:function(t){var e=new RegExp(this.options.regexFilter,"i"),n=e.test(t);return n}},{key:"getItemById",value:function(t){if(!t||!(0,l.isType)("Number",t))return void console.error("getItemById: An id was not given or was not a number");var e=this.getItems(),n=e.find(function(e){return e.id===parseInt(t)}),i=this.list.querySelector("[data-choice-id='"+n.id+"']");return i}},{key:"selectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,u.selectItem)(e,!0))}}},{key:"deselectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,u.selectItem)(e,!1))}}},{key:"selectAll",value:function(){var t=this,e=this.getItems();e.forEach(function(e){t.selectItem(e)})}},{key:"deselectAll",value:function(){var t=this,e=this.getItems();e.forEach(function(e){t.deselectItem(e)})}},{key:"addItem",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],i=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3];this.options.debug&&console.debug("Add item");var r=t.trim(),o=e||r,s=n||-1;this.options.prependValue&&(r=this.options.prependValue+r.toString()),this.options.appendValue&&(r+=this.options.appendValue.toString());var a=this.store.getState().items.length+1;this.store.dispatch((0,u.addItem)(r,o,a,s)),i&&((0,l.isType)("Function",i)?i(a,t):console.error("callbackOnAddItem: Callback is not a function"))}},{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 n=t.id,i=t.value,r=t.optionId;this.store.dispatch((0,u.removeItem)(n,r)),e&&((0,l.isType)("Function",e)?e(i):console.error("callbackOnRemoveItem: Callback is not a function"))}},{key:"removeItemsByValue",value:function(t){var e=this;t&&(0,l.isType)("String",t)||console.error("removeItemsByValue: No value was passed to be removed");var n=this.getItemsFilteredByActive();n.forEach(function(n){n.value===t&&e.removeItem(n)})}},{key:"removeAllItems",value:function(){var t=this,e=this.getItemsFilteredByActive();e.forEach(function(e){e.active&&t.removeItem(e)})}},{key:"removeAllSelectedItems",value:function(){var t=this,e=this.getItemsFilteredByActive();e.forEach(function(e){e.selected&&e.active&&t.removeItem(e)})}},{key:"showDropdown",value:function(){this.dropdown.classList.add(this.options.classNames.activeState);var t=this.dropdown.getBoundingClientRect(),e=t.top+t.height>=document.body.offsetHeight;e?this.dropdown.classList.add(this.options.classNames.flippedState):this.dropdown.classList.remove(this.options.classNames.flippedState)}},{key:"hideDropdown",value:function(){var t=this.dropdown.classList.contains(this.options.classNames.flippedState);this.dropdown.classList.remove(this.options.classNames.activeState),t&&this.dropdown.classList.remove(this.options.classNames.flippedState)}},{key:"toggleDropdown",value:function(){if(this.dropdown){var t=this.dropdown.classList.contains(this.options.classNames.activeState);t?this.hideDropdown():this.showDropdown()}}},{key:"addOption",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?-1:arguments[1],n=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],i=this.store.getState(),r=i.options.length+1,o=t.value,s=t.innerHTML,a=t.selected;this.store.dispatch((0,u.addOption)(o,s,r,e,n)),a&&this.addItem(o,s,r)}},{key:"addGroup",value:function(t,e,n){var i=this,r=Array.from(t.getElementsByTagName("OPTION")),o=e;r?(this.store.dispatch((0,u.addGroup)(t.label,o,!0,t.disabled)),r.forEach(function(e,n){t.disabled?i.addOption(e,o,!0):i.addOption(e,o)})):this.store.dispatch((0,u.addGroup)(t.label,t.id,!1,t.disabled))}},{key:"getItems",value:function(){var t=this.store.getState();return t.items}},{key:"getItemsFilteredByActive",value:function(){var t=this.getItems(),e=t.filter(function(t){return t.active===!0},[]);return e}},{key:"getItemsReducedToValues",value:function(){var t=this.getItems(),e=t.reduce(function(t,e){return t.push(e.value),t},[]);return e}},{key:"getOptions",value:function(){var t=this.store.getState();return t.options}},{key:"getOptionsFilteredByActive",value:function(){var t=this.getOptions(),e=t.filter(function(t){return t.active===!0&&t.disabled===!1&&t.selected!==!0},[]);return e}},{key:"getOptionsFiltedBySelectable",value:function(){var t=this.getOptions(),e=t.filter(function(t){return t.disabled===!1},[]);return e}},{key:"getGroups",value:function(){var t=this.store.getState();return t.groups}},{key:"getGroupsFilteredByActive",value:function(){var t=this.getGroups(),e=this.getOptions(),n=t.filter(function(t){var n=t.active===!0&&t.disabled===!1,i=e.some(function(t){return t.active===!0&&t.disabled===!1});return!(!n||!i)},[]);return n}},{key:"generateInput",value:function(){var t=this,e=this.templates.containerOuter(),n=this.templates.containerInner(),i=this.templates.list(),r=this.templates.input();if(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"),(0,l.wrap)(this.passedElement,n),(0,l.wrap)(n,e),this.options.placeholder&&this.options.placeholderValue&&(r.placeholder=this.options.placeholderValue,r.style.width=(0,l.getWidthOfInput)(r)),this.options.addItems||(r.disabled=!0,e.classList.add(this.options.classNames.disabledState)),e.appendChild(n),n.appendChild(i),n.appendChild(r),"select-multiple"===this.passedElement.type){this.highlightPosition=0;var o=this.templates.dropdown(),s=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(e.appendChild(o),this.dropdown=o,s.length)s.forEach(function(e,n){var i=0===n;t.addGroup(e,n,i)});else{var a=Array.from(this.passedElement.options);a.forEach(function(e){t.addOption(e)})}}else"text"===this.passedElement.type&&this.presetItems.forEach(function(e){t.addItem(e)});this.containerOuter=e,this.containerInner=n,this.input=r,this.list=i}},{key:"render",value:function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?this.options.callbackOnRender:arguments[0],n=(this.options.classNames,this.getItemsFilteredByActive());"select-multiple"===this.passedElement.type&&!function(){var e=t.getOptionsFilteredByActive(),n=t.getGroupsFilteredByActive();t.dropdown.innerHTML="";var i=document.createDocumentFragment();if(n.length>=1?n.forEach(function(n,r){var o=e.filter(function(t){return t.groupId===n.id});o.length>=1&&!function(){var e=t.templates.optgroup(n);o.forEach(function(n,i){var r=t.templates.option(n);e.appendChild(r)}),i.appendChild(e)}()}):e.length>=1&&e.forEach(function(e,n){var r=t.templates.option(e);i.appendChild(r)}),t.dropdown.appendChild(i),""===t.dropdown.innerHTML){var r=t.templates.notice("No options to select");i.appendChild(r),t.dropdown.appendChild(i)}}(),n&&!function(){var e=t.getItemsReducedToValues();t.passedElement.value=e.join(t.options.delimiter),t.list.innerHTML="";var i=document.createDocumentFragment();n.forEach(function(e){var n=t.templates.item(e);i.appendChild(n)}),t.list.appendChild(i)}(),e&&((0,l.isType)("Function",e)?e(n):console.error("callbackOnRender: Callback is not a function"))}},{key:"addEventListeners",value:function(){document.addEventListener("keyup",this.onKeyUp),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("click",this.onClick),document.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("click",this.onClick),document.removeEventListener("paste",this.onPaste),this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("blur",this.onBlur)}},{key:"init",value:function(){var t=arguments.length<=0||void 0===arguments[0]?this.options.callbackOnInit:arguments[0];this.initialised=!0,this.generateInput(),this.store.subscribe(this.render),this.render(),this.addEventListeners(),t&&((0,l.isType)("Function",t)?t():console.error("callbackOnInit: Callback is not a function"))}},{key:"destroy",value:function(){this.passedElement=null,this.userOptions=null,this.options=null,this.initialised=null,this.store=null}}]),t}();window.Choices=t.exports=p},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0,e.compose=e.applyMiddleware=e.bindActionCreators=e.combineReducers=e.createStore=void 0;var r=n(3),o=i(r),s=n(8),a=i(s),c=n(10),u=i(c),l=n(11),d=i(l),h=n(12),p=i(h),f=n(9);i(f);e.createStore=o.default,e.combineReducers=a.default,e.bindActionCreators=u.default,e.applyMiddleware=d.default,e.compose=p.default},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function r(t,e,n){function i(){f===p&&(f=p.slice())}function o(){return h}function c(t){if("function"!=typeof t)throw new Error("Expected listener to be a function.");var e=!0;return i(),f.push(t),function(){if(e){e=!1,i();var n=f.indexOf(t);f.splice(n,1)}}}function u(t){if(!(0,s.default)(t))throw new Error("Actions must be plain objects. Use custom middleware for async actions.");if("undefined"==typeof t.type)throw new Error('Actions may not have an undefined "type" property. Have you misspelled a constant?');if(v)throw new Error("Reducers may not dispatch actions.");try{v=!0,h=d(h,t)}finally{v=!1}for(var e=p=f,n=0;nn;n++)e[n]=arguments[n];return function(t){return function(n,i,r){var s=t(n,i,r),c=s.dispatch,u=[],l={getState:s.getState,dispatch:function(t){return c(t)}};return u=e.map(function(t){return t(l)}),c=a.default.apply(void 0,u)(s.dispatch),o({},s,{dispatch:c})}}}var o=Object.assign||function(t){for(var e=1;en;n++)e[n]=arguments[n];return function(){if(0===e.length)return arguments.length<=0?void 0:arguments[0];var t=e[e.length-1],n=e.slice(0,-1);return n.reduceRight(function(t,e){return e(t)},t.apply(void 0,arguments))}}e.__esModule=!0,e.default=n},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=n(14),s=i(o),a=n(15),c=i(a),u=n(16),l=i(u),d=(0,r.combineReducers)({items:s.default,groups:c.default,options:l.default});e.default=d},function(t,e){"use strict";function n(t){if(Array.isArray(t)){for(var e=0,n=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 i=e.results.items,r=t.map(function(t,e){return t.active=i.some(function(t){return t.id===e}),t});return r;case"ACTIVATE_OPTIONS":return t.map(function(t){return t.active=e.active,t});default:return t}};e.default=i},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.addItem=function(t,e,n,i){return{type:"ADD_ITEM",value:t,label:e,id:n,optionId:i}},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,n,i,r){return{type:"ADD_OPTION",value:t,label:e,id:n,groupId:i,disabled:r}},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,n,i){return{type:"ADD_GROUP",value:t,id:e,active:n,disabled:i}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=(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 n=Object.prototype.toString.call(e).slice(8,-1);return void 0!==e&&null!==e&&n===t}),i=(e.extend=function o(){for(var t={},e=!1,i=arguments.length,r=function(i){for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e&&n("Object",i[r])?t[r]=o(!0,t[r],i[r]):t[r]=i[r])},s=0;i>s;s++){var a=arguments[s];n("Object",a)?r(a):console.error("Custom options must be an object")}return t},e.whichTransitionEvent=function(){var t,e=document.createElement("fakeelement"),n={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in n)if(void 0!==e.style[t])return n[t]},e.whichAnimationEvent=function(){var t,e=document.createElement("fakeelement"),n={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in n)if(void 0!==e.style[t])return n[t]}),r=(e.getParentsUntil=function(t,e,n){for(var i=[];t&&t!==document;t=t.parentNode){if(e){var r=e.charAt(0);if("."===r&&t.classList.contains(e.substr(1)))break;if("#"===r&&t.id===e.substr(1))break;if("["===r&&t.hasAttribute(e.substr(1,e.length-1)))break;if(t.tagName.toLowerCase()===e)break}if(n){var o=n.charAt(0);"."===o&&t.classList.contains(n.substr(1))&&i.push(t),"#"===o&&t.id===n.substr(1)&&i.push(t),"["===o&&t.hasAttribute(n.substr(1,n.length-1))&&i.push(t),t.tagName.toLowerCase()===n&&i.push(t)}else i.push(t)}return 0===i.length?null:i},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=[],n=t.parentNode.firstChild;n;n=n.nextSibling)1===n.nodeType&&n!==t&&e.push(n);return e},e.findAncestor=function(t,e){for(;(t=t.parentElement)&&!t.classList.contains(e););return t},e.debounce=function(t,e,n){var i;return function(){var r=this,o=arguments,s=function(){i=null,n||t.apply(r,o)},a=n&&!i;clearTimeout(i),i=setTimeout(s,e),a&&t.apply(r,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 n=e;return n>1&&(n=1),n>0&&(n=0),Math.max(t.offsetHeight*n)},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,n){return this.getScrollPosition(e)>this.getElemDistance(t)+this.getElementOffset(t,n)},e.stripHTML=function(t){var e=document.createElement("DIV");return e.innerHTML=t,e.textContent||e.innerText||""},e.addAnimation=function(t,e){var n=i(),r=function o(){t.classList.remove(e),t.removeEventListener(n,o,!1)};t.classList.add(e),t.addEventListener(n,r,!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 n;for(t.innerHTML=e,n=t.children[0];t.firstChild;)t.removeChild(t.firstChild);return n}}());e.getWidthOfInput=function(t){var e=arguments.length<=1||void 0===arguments[1]?20:arguments[1],n=t.value||t.placeholder,i=t.offsetWidth;if(n){var o=r(''+n+"");o.style.position="absolute",o.style.top="-9999px",o.style.left="-9999px",o.style.padding="0",o.style.width="auto",document.body.appendChild(o),o.offsetWidth>e&&o.offsetWidth!=t.offsetWidth&&(i=o.offsetWidth+e/4),document.body.removeChild(o)}return i+"px"}},function(t,e,n){var i,r;!function(o,s){i=s,r="function"==typeof i?i.call(e,n,e,t):i,!(void 0!==r&&(t.exports=r))}(this,function(){var t=function(t,e){this.items=t,this.settings=e||{diacritics:!0}};t.prototype.tokenize=function(t){if(t=i(String(t||"").toLowerCase()),!t||!t.length)return[];var e,n,o,a,c=[],u=t.split(/ +/);for(e=0,n=u.length;n>e;e++){if(o=r(u[e]),this.settings.diacritics)for(a in s)s.hasOwnProperty(a)&&(o=o.replace(new RegExp(a,"g"),s[a]));c.push({string:u[e],regex:new RegExp(o,"i")})}return c},t.prototype.iterator=function(t,e){var n;n=o(t)?Array.prototype.forEach||function(t){for(var e=0,n=this.length;n>e;e++)t(this[e],e,this)}:function(t){for(var e in this)this.hasOwnProperty(e)&&t(this[e],e,this)},n.apply(t,[e])},t.prototype.getScoreFunction=function(t,e){var n,i,r,o;n=this,t=n.prepareSearch(t,e),r=t.tokens,i=t.options.fields,o=r.length;var s=function(t,e){var n,i;return t?(t=String(t||""),i=t.search(e.regex),-1===i?0:(n=e.string.length/t.length,0===i&&(n+=.5),n)):0},a=function(){var t=i.length;return t?1===t?function(t,e){return s(e[i[0]],t)}:function(e,n){for(var r=0,o=0;t>r;r++)o+=s(n[i[r]],e);return o/t}:function(){return 0}}();return o?1===o?function(t){return a(r[0],t)}:"and"===t.options.conjunction?function(t){for(var e,n=0,i=0;o>n;n++){if(e=a(r[n],t),0>=e)return 0;i+=e}return i/o}:function(t){for(var e=0,n=0;o>e;e++)n+=a(r[e],t);return n/o}:function(){return 0}},t.prototype.getSortFunction=function(t,n){var i,r,o,s,a,c,u,l,d,h,p;if(o=this,t=o.prepareSearch(t,n),p=!t.query&&n.sort_empty||n.sort,d=function(t,e){return"$score"===t?e.score:o.items[e.id][t]},a=[],p)for(i=0,r=p.length;r>i;i++)(t.query||"$score"!==p[i].field)&&a.push(p[i]);if(t.query){for(h=!0,i=0,r=a.length;r>i;i++)if("$score"===a[i].field){h=!1;break}h&&a.unshift({field:"$score",direction:"desc"})}else for(i=0,r=a.length;r>i;i++)if("$score"===a[i].field){a.splice(i,1);break}for(l=[],i=0,r=a.length;r>i;i++)l.push("desc"===a[i].direction?-1:1);return c=a.length,c?1===c?(s=a[0].field,u=l[0],function(t,n){return u*e(d(s,t),d(s,n))}):function(t,n){var i,r,o;for(i=0;c>i;i++)if(o=a[i].field,r=l[i]*e(d(o,t),d(o,n)))return r;return 0}:null},t.prototype.prepareSearch=function(t,e){if("object"==typeof t)return t; -e=n({},e);var i=e.fields,r=e.sort,s=e.sort_empty;return i&&!o(i)&&(e.fields=[i]),r&&!o(r)&&(e.sort=[r]),s&&!o(s)&&(e.sort_empty=[s]),{options:e,query:String(t||"").toLowerCase(),tokens:this.tokenize(t),total:0,items:[]}},t.prototype.search=function(t,e){var n,i,r,o,s=this;return i=this.prepareSearch(t,e),e=i.options,t=i.query,o=e.score||s.getScoreFunction(i),t.length?s.iterator(s.items,function(t,r){n=o(t),(e.filter===!1||n>0)&&i.items.push({score:n,id:r})}):s.iterator(s.items,function(t,e){i.items.push({score:1,id:e})}),r=s.getSortFunction(i,e),r&&i.items.sort(r),i.total=i.items.length,"number"==typeof e.limit&&(i.items=i.items.slice(0,e.limit)),i};var e=function(t,e){return"number"==typeof t&&"number"==typeof e?t>e?1:e>t?-1:0:(t=a(String(t||"")),e=a(String(e||"")),t>e?1:e>t?-1:0)},n=function(t,e){var n,i,r,o;for(n=1,i=arguments.length;i>n;n++)if(o=arguments[n])for(r in o)o.hasOwnProperty(r)&&(t[r]=o[r]);return t},i=function(t){return(t+"").replace(/^\s+|\s+$|/g,"")},r=function(t){return(t+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},o=Array.isArray||"undefined"!=typeof $&&$.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},s={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎð]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},a=function(){var t,e,n,i,r="",o={};for(n in s)if(s.hasOwnProperty(n))for(i=s[n].substring(2,s[n].length-1),r+=i,t=0,e=i.length;e>t;t++)o[i.charAt(t)]=n;var a=new RegExp("["+r+"]","g");return function(t){return t.replace(a,function(t){return o[t]}).toLowerCase()}}();return t})}]); \ No newline at end of file +!function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="/assets/scripts/dist/",e(0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Choices=void 0;var o=function(){function t(t,e){for(var n=0;n1)for(var a=1;a')},containerInner:function(){return(0,l.strToEl)('
')},list:function(){return(0,l.strToEl)('
    ')},input:function(){return(0,l.strToEl)('')},dropdown:function(){return(0,l.strToEl)('
    ')},notice:function(t){return(0,l.strToEl)('
    '+t+"
    ")},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(t){return(0,l.strToEl)('\n
    \n '+t.label+"\n
    \n ")}},this.init()}return o(t,[{key:"handleEnter",value:function(t,e){var n=!0;if("text"===this.passedElement.type&&(this.options.addItems?this.options.maxItems&&this.options.maxItems<=this.list.children.length?n=!1:this.options.allowDuplicates===!1&&this.passedElement.value&&(n=!t.some(function(t){return t.value===e})):n=!1,n)){var i=!0;this.options.regexFilter&&(i=this.regexFilter(e)),i&&(this.addItem(e),this.clearInput(this.passedElement))}}},{key:"handleBackspaceKey",value:function(t){if(this.options.removeItems&&t){var e=t[t.length-1],n=t.some(function(t){return t.selected===!0});this.options.editItems&&!n&&e?(this.input.value=e.value,this.removeItem(e)):(this.selectItem(e),this.removeAllSelectedItems())}}},{key:"handleClick",value:function(t,e,n){var i=this;this.options.removeItems&&e&&!function(){var r=e.getAttribute("data-choice-id");t.forEach(function(t){t.id!==parseInt(r)||t.selected?n||i.deselectItem(t):i.selectItem(t)})}()}},{key:"onKeyDown",value:function(t){if(t.target===this.input){var e=t.ctrlKey||t.metaKey,n=46,i=8,r=13,o=65,s=27,a=38,c=40,u=this.getItemsFilteredByActive(),l=this.getOptionsFilteredByActive(),d=this.input===document.activeElement,h=this.dropdown&&this.dropdown.classList.contains(this.options.classNames.activeState),p=this.list&&this.list.children,f=String.fromCharCode(event.keyCode);switch(/[a-zA-Z0-9-_ ]/.test(f)&&this.dropdown&&!h&&this.toggleDropdown(),t.keyCode){case o:e&&p&&this.options.removeItems&&!this.input.value&&this.options.selectAll&&this.input===document.activeElement&&this.selectAll(this.list.children);break;case r:if(t.target.value&&"text"===this.passedElement.type){var v=this.input.value;this.handleEnter(u,v)}if("select-multiple"===this.passedElement.type&&h){var m=this.dropdown.querySelector("."+this.options.classNames.highlightedState);if(m){var y=m.getAttribute("data-choice-value"),g=m.innerHTML,b=m.getAttribute("data-choice-id");this.addItem(y,g,b),this.input.value=""}}break;case s:"select-multiple"===this.passedElement.type&&h&&this.toggleDropdown();break;case c:case a:if("select-multiple"===this.passedElement.type&&h){var I=l.filter(function(t){return!t.selected}),w=!0;if(t.keyCode===c?this.highlightPosition0?this.highlightPosition--:w=!1),w){var E=I[this.highlightPosition];if(E){var O=this.dropdown.querySelector("."+this.options.classNames.highlightedState),k=this.dropdown.querySelector('[data-choice-id="'+E.id+'"]');O&&O.classList.remove(this.options.classNames.highlightedState),k&&k.classList.add(this.options.classNames.highlightedState)}}}break;case n:case i:d&&!t.target.value&&(this.handleBackspaceKey(u),t.preventDefault())}}}},{key:"onKeyUp",value:function(t){var e=this;if(t.target===this.input&&"select-multiple"===this.passedElement.type&&this.options.allowSearch){var n=this.getOptions(),i=n.some(function(t){return t.active!==!0});if(this.input===document.activeElement)if(this.input.value){var r=(0,l.debounce)(function(){var t=e.getOptionsFiltedBySelectable(),n=new h.default(t),i=n.search(e.input.value,{fields:["label","value"],sort:[{field:"value",direction:"asc"}],limit:10});e.store.dispatch((0,u.filterOptions)(i))},100);r()}else i&&this.store.dispatch((0,u.activateOptions)())}}},{key:"onClick",value:function(t){var e=this,n=this.getItemsFilteredByActive(),i=!!t.shiftKey;if(this.dropdown&&this.toggleDropdown(),this.containerOuter.contains(t.target))this.input!==document.activeElement&&this.input.focus(),t.target.hasAttribute("data-choice-item")?this.handleClick(n,t.target,i):t.target.hasAttribute("data-choice-option")&&!function(){var n=e.getOptionsFilteredByActive(),i=t.target.getAttribute("data-choice-id"),r=n.find(function(t){return t.id===parseInt(i)});r.selected||e.addItem(r.value,r.label,r.id)}();else{var r=n.some(function(t){return t.selected===!0});r&&this.deselectAll(),"select-multiple"===this.passedElement.type&&this.dropdown.classList.contains(this.options.classNames.activeState)&&this.toggleDropdown()}}},{key:"onPaste",value:function(t){this.options.allowPaste||t.preventDefault()}},{key:"onFocus",value:function(t){this.containerOuter.classList.add(this.options.classNames.activeState)}},{key:"onBlur",value:function(t){this.containerOuter.classList.remove(this.options.classNames.activeState)}},{key:"clearInput",value:function(){this.input.value&&(this.input.value="")}},{key:"regexFilter",value:function(t){var e=new RegExp(this.options.regexFilter,"i"),n=e.test(t);return n}},{key:"getItemById",value:function(t){if(!t||!(0,l.isType)("Number",t))return void console.error("getItemById: An id was not given or was not a number");var e=this.getItems(),n=e.find(function(e){return e.id===parseInt(t)}),i=this.list.querySelector("[data-choice-id='"+n.id+"']");return i}},{key:"selectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,u.selectItem)(e,!0))}}},{key:"deselectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,u.selectItem)(e,!1))}}},{key:"selectAll",value:function(){var t=this,e=this.getItems();e.forEach(function(e){t.selectItem(e)})}},{key:"deselectAll",value:function(){var t=this,e=this.getItems();e.forEach(function(e){t.deselectItem(e)})}},{key:"addItem",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],i=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3];this.options.debug&&console.debug("Add item");var r=t.trim(),o=e||r,s=n||-1;this.options.prependValue&&(r=this.options.prependValue+r.toString()),this.options.appendValue&&(r+=this.options.appendValue.toString());var a=this.store.getState().items.length+1;this.store.dispatch((0,u.addItem)(r,o,a,s)),i&&((0,l.isType)("Function",i)?i(a,t):console.error("callbackOnAddItem: Callback is not a function"))}},{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 n=t.id,i=t.value,r=t.optionId;this.store.dispatch((0,u.removeItem)(n,r)),e&&((0,l.isType)("Function",e)?e(i):console.error("callbackOnRemoveItem: Callback is not a function"))}},{key:"removeItemsByValue",value:function(t){var e=this;t&&(0,l.isType)("String",t)||console.error("removeItemsByValue: No value was passed to be removed");var n=this.getItemsFilteredByActive();n.forEach(function(n){n.value===t&&e.removeItem(n)})}},{key:"removeAllItems",value:function(){var t=this,e=this.getItemsFilteredByActive();e.forEach(function(e){e.active&&t.removeItem(e)})}},{key:"removeAllSelectedItems",value:function(){var t=this,e=this.getItemsFilteredByActive();e.forEach(function(e){e.selected&&e.active&&t.removeItem(e)})}},{key:"showDropdown",value:function(){this.dropdown.classList.add(this.options.classNames.activeState);var t=this.dropdown.getBoundingClientRect(),e=t.top+t.height>=document.body.offsetHeight;e?this.dropdown.classList.add(this.options.classNames.flippedState):this.dropdown.classList.remove(this.options.classNames.flippedState)}},{key:"hideDropdown",value:function(){var t=this.dropdown.classList.contains(this.options.classNames.flippedState);this.dropdown.classList.remove(this.options.classNames.activeState),t&&this.dropdown.classList.remove(this.options.classNames.flippedState)}},{key:"toggleDropdown",value:function(){if(this.dropdown){var t=this.dropdown.classList.contains(this.options.classNames.activeState);t?this.hideDropdown():this.showDropdown()}}},{key:"addOption",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?-1:arguments[1],n=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],i=this.store.getState(),r=i.options.length+1,o=t.value,s=t.innerHTML,a=t.selected;this.store.dispatch((0,u.addOption)(o,s,r,e,n)),a&&this.addItem(o,s,r)}},{key:"addGroup",value:function(t,e,n){var i=this,r=Array.from(t.getElementsByTagName("OPTION")),o=e;r?(this.store.dispatch((0,u.addGroup)(t.label,o,!0,t.disabled)),r.forEach(function(e,n){t.disabled?i.addOption(e,o,!0):i.addOption(e,o)})):this.store.dispatch((0,u.addGroup)(t.label,t.id,!1,t.disabled))}},{key:"getItems",value:function(){var t=this.store.getState();return t.items}},{key:"getItemsFilteredByActive",value:function(){var t=this.getItems(),e=t.filter(function(t){return t.active===!0},[]);return e}},{key:"getItemsReducedToValues",value:function(){var t=this.getItems(),e=t.reduce(function(t,e){return t.push(e.value),t},[]);return e}},{key:"getOptions",value:function(){var t=this.store.getState();return t.options}},{key:"getOptionsFilteredByActive",value:function(){var t=this.getOptions(),e=t.filter(function(t){return t.active===!0&&t.disabled===!1&&t.selected!==!0},[]);return e}},{key:"getOptionsFiltedBySelectable",value:function(){var t=this.getOptions(),e=t.filter(function(t){return t.disabled===!1},[]);return e}},{key:"getGroups",value:function(){var t=this.store.getState();return t.groups}},{key:"getGroupsFilteredByActive",value:function(){var t=this.getGroups(),e=this.getOptions(),n=t.filter(function(t){var n=t.active===!0&&t.disabled===!1,i=e.some(function(t){return t.active===!0&&t.disabled===!1});return!(!n||!i)},[]);return n}},{key:"generateInput",value:function(){var t=this,e=this.templates.containerOuter(),n=this.templates.containerInner(),i=this.templates.list(),r=this.templates.input();if(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"),(0,l.wrap)(this.passedElement,n),(0,l.wrap)(n,e),this.options.placeholder&&this.options.placeholderValue&&(r.placeholder=this.options.placeholderValue,r.style.width=(0,l.getWidthOfInput)(r)),this.options.addItems||(r.disabled=!0,e.classList.add(this.options.classNames.disabledState)),e.appendChild(n),n.appendChild(i),n.appendChild(r),"select-multiple"===this.passedElement.type){this.highlightPosition=0;var o=this.templates.dropdown(),s=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(e.appendChild(o),this.dropdown=o,s.length)s.forEach(function(e,n){var i=0===n;t.addGroup(e,n,i)});else{var a=Array.from(this.passedElement.options);a.forEach(function(e){t.addOption(e)})}}else"text"===this.passedElement.type&&this.presetItems.forEach(function(e){t.addItem(e)});this.containerOuter=e,this.containerInner=n,this.input=r,this.list=i}},{key:"render",value:function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?this.options.callbackOnRender:arguments[0],n=(this.options.classNames,this.getItemsFilteredByActive());"select-multiple"===this.passedElement.type&&!function(){var e=t.getOptionsFilteredByActive(),n=t.getGroupsFilteredByActive();t.dropdown.innerHTML="";var i=document.createDocumentFragment();if(n.length>=1?n.forEach(function(n,r){var o=e.filter(function(t){return t.groupId===n.id});o.length>=1&&!function(){var e=t.templates.optgroup(n);o.forEach(function(n,i){var r=t.templates.option(n);e.appendChild(r)}),i.appendChild(e)}()}):e.length>=1&&e.forEach(function(e,n){var r=t.templates.option(e);i.appendChild(r)}),t.dropdown.appendChild(i),""===t.dropdown.innerHTML){var r=t.templates.notice("No options to select");i.appendChild(r),t.dropdown.appendChild(i)}}(),n&&!function(){var e=t.getItemsReducedToValues();t.passedElement.value=e.join(t.options.delimiter),t.list.innerHTML="";var i=document.createDocumentFragment();n.forEach(function(e){var n=t.templates.item(e);i.appendChild(n)}),t.list.appendChild(i)}(),e&&((0,l.isType)("Function",e)?e(n):console.error("callbackOnRender: Callback is not a function"))}},{key:"addEventListeners",value:function(){document.addEventListener("keyup",this.onKeyUp),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("click",this.onClick),document.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("click",this.onClick),document.removeEventListener("paste",this.onPaste),this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("blur",this.onBlur)}},{key:"init",value:function(){var t=arguments.length<=0||void 0===arguments[0]?this.options.callbackOnInit:arguments[0];this.initialised=!0,this.generateInput(),this.store.subscribe(this.render),this.render(),this.addEventListeners(),t&&((0,l.isType)("Function",t)?t():console.error("callbackOnInit: Callback is not a function"))}},{key:"destroy",value:function(){this.passedElement=null,this.userOptions=null,this.options=null,this.initialised=null,this.store=null}}]),t}();window.Choices=t.exports=p},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0,e.compose=e.applyMiddleware=e.bindActionCreators=e.combineReducers=e.createStore=void 0;var r=n(3),o=i(r),s=n(8),a=i(s),c=n(10),u=i(c),l=n(11),d=i(l),h=n(12),p=i(h),f=n(9);i(f);e.createStore=o.default,e.combineReducers=a.default,e.bindActionCreators=u.default,e.applyMiddleware=d.default,e.compose=p.default},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function r(t,e,n){function i(){f===p&&(f=p.slice())}function o(){return h}function c(t){if("function"!=typeof t)throw new Error("Expected listener to be a function.");var e=!0;return i(),f.push(t),function(){if(e){e=!1,i();var n=f.indexOf(t);f.splice(n,1)}}}function u(t){if(!(0,s.default)(t))throw new Error("Actions must be plain objects. Use custom middleware for async actions.");if("undefined"==typeof t.type)throw new Error('Actions may not have an undefined "type" property. Have you misspelled a constant?');if(v)throw new Error("Reducers may not dispatch actions.");try{v=!0,h=d(h,t)}finally{v=!1}for(var e=p=f,n=0;nn;n++)e[n]=arguments[n];return function(t){return function(n,i,r){var s=t(n,i,r),c=s.dispatch,u=[],l={getState:s.getState,dispatch:function(t){return c(t)}};return u=e.map(function(t){return t(l)}),c=a.default.apply(void 0,u)(s.dispatch),o({},s,{dispatch:c})}}}var o=Object.assign||function(t){for(var e=1;en;n++)e[n]=arguments[n];return function(){if(0===e.length)return arguments.length<=0?void 0:arguments[0];var t=e[e.length-1],n=e.slice(0,-1);return n.reduceRight(function(t,e){return e(t)},t.apply(void 0,arguments))}}e.__esModule=!0,e.default=n},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=n(14),s=i(o),a=n(15),c=i(a),u=n(16),l=i(u),d=(0,r.combineReducers)({items:s.default,groups:c.default,options:l.default});e.default=d},function(t,e){"use strict";function n(t){if(Array.isArray(t)){for(var e=0,n=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 i=e.results.items,r=t.map(function(t,e){return t.active=i.some(function(t){return t.id===e}),t});return r;case"ACTIVATE_OPTIONS":return t.map(function(t){return t.active=e.active,t});default:return t}};e.default=i},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.addItem=function(t,e,n,i){return{type:"ADD_ITEM",value:t,label:e,id:n,optionId:i}},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,n,i,r){return{type:"ADD_OPTION",value:t,label:e,id:n,groupId:i,disabled:r}},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,n,i){return{type:"ADD_GROUP",value:t,id:e,active:n,disabled:i}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=(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 n=Object.prototype.toString.call(e).slice(8,-1);return void 0!==e&&null!==e&&n===t}),i=(e.extend=function o(){for(var t={},e=!1,i=arguments.length,r=function(i){for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e&&n("Object",i[r])?t[r]=o(!0,t[r],i[r]):t[r]=i[r])},s=0;i>s;s++){var a=arguments[s];n("Object",a)?r(a):console.error("Custom options must be an object")}return t},e.whichTransitionEvent=function(){var t,e=document.createElement("fakeelement"),n={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in n)if(void 0!==e.style[t])return n[t]},e.whichAnimationEvent=function(){var t,e=document.createElement("fakeelement"),n={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in n)if(void 0!==e.style[t])return n[t]}),r=(e.getParentsUntil=function(t,e,n){for(var i=[];t&&t!==document;t=t.parentNode){if(e){var r=e.charAt(0);if("."===r&&t.classList.contains(e.substr(1)))break;if("#"===r&&t.id===e.substr(1))break;if("["===r&&t.hasAttribute(e.substr(1,e.length-1)))break;if(t.tagName.toLowerCase()===e)break}if(n){var o=n.charAt(0);"."===o&&t.classList.contains(n.substr(1))&&i.push(t),"#"===o&&t.id===n.substr(1)&&i.push(t),"["===o&&t.hasAttribute(n.substr(1,n.length-1))&&i.push(t),t.tagName.toLowerCase()===n&&i.push(t)}else i.push(t)}return 0===i.length?null:i},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=[],n=t.parentNode.firstChild;n;n=n.nextSibling)1===n.nodeType&&n!==t&&e.push(n);return e},e.findAncestor=function(t,e){for(;(t=t.parentElement)&&!t.classList.contains(e););return t},e.debounce=function(t,e,n){var i;return function(){var r=this,o=arguments,s=function(){i=null,n||t.apply(r,o)},a=n&&!i;clearTimeout(i),i=setTimeout(s,e),a&&t.apply(r,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 n=e;return n>1&&(n=1),n>0&&(n=0),Math.max(t.offsetHeight*n)},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,n){return this.getScrollPosition(e)>this.getElemDistance(t)+this.getElementOffset(t,n)},e.stripHTML=function(t){var e=document.createElement("DIV");return e.innerHTML=t,e.textContent||e.innerText||""},e.addAnimation=function(t,e){var n=i(),r=function o(){t.classList.remove(e),t.removeEventListener(n,o,!1)};t.classList.add(e),t.addEventListener(n,r,!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 n;for(t.innerHTML=e,n=t.children[0];t.firstChild;)t.removeChild(t.firstChild);return n}}());e.getWidthOfInput=function(t){var e=arguments.length<=1||void 0===arguments[1]?20:arguments[1],n=t.value||t.placeholder,i=t.offsetWidth;if(n){var o=r(''+n+"");o.style.position="absolute",o.style.top="-9999px",o.style.left="-9999px",o.style.padding="0",o.style.width="auto",document.body.appendChild(o),o.offsetWidth>e&&o.offsetWidth!=t.offsetWidth&&(i=o.offsetWidth+e/4),document.body.removeChild(o)}return i+"px"}},function(t,e,n){var i,r;!function(o,s){i=s,r="function"==typeof i?i.call(e,n,e,t):i,!(void 0!==r&&(t.exports=r))}(this,function(){var t=function(t,e){this.items=t,this.settings=e||{diacritics:!0}};t.prototype.tokenize=function(t){if(t=i(String(t||"").toLowerCase()),!t||!t.length)return[];var e,n,o,a,c=[],u=t.split(/ +/);for(e=0,n=u.length;n>e;e++){if(o=r(u[e]),this.settings.diacritics)for(a in s)s.hasOwnProperty(a)&&(o=o.replace(new RegExp(a,"g"),s[a]));c.push({string:u[e],regex:new RegExp(o,"i")})}return c},t.prototype.iterator=function(t,e){var n;n=o(t)?Array.prototype.forEach||function(t){for(var e=0,n=this.length;n>e;e++)t(this[e],e,this)}:function(t){for(var e in this)this.hasOwnProperty(e)&&t(this[e],e,this)},n.apply(t,[e])},t.prototype.getScoreFunction=function(t,e){var n,i,r,o;n=this,t=n.prepareSearch(t,e),r=t.tokens,i=t.options.fields,o=r.length;var s=function(t,e){var n,i;return t?(t=String(t||""),i=t.search(e.regex),-1===i?0:(n=e.string.length/t.length,0===i&&(n+=.5),n)):0},a=function(){var t=i.length;return t?1===t?function(t,e){return s(e[i[0]],t)}:function(e,n){for(var r=0,o=0;t>r;r++)o+=s(n[i[r]],e);return o/t}:function(){return 0}}();return o?1===o?function(t){return a(r[0],t)}:"and"===t.options.conjunction?function(t){for(var e,n=0,i=0;o>n;n++){if(e=a(r[n],t),0>=e)return 0;i+=e}return i/o}:function(t){for(var e=0,n=0;o>e;e++)n+=a(r[e],t);return n/o}:function(){return 0}},t.prototype.getSortFunction=function(t,n){var i,r,o,s,a,c,u,l,d,h,p;if(o=this,t=o.prepareSearch(t,n),p=!t.query&&n.sort_empty||n.sort,d=function(t,e){return"$score"===t?e.score:o.items[e.id][t]},a=[],p)for(i=0,r=p.length;r>i;i++)(t.query||"$score"!==p[i].field)&&a.push(p[i]);if(t.query){for(h=!0,i=0,r=a.length;r>i;i++)if("$score"===a[i].field){h=!1;break}h&&a.unshift({field:"$score",direction:"desc"})}else for(i=0,r=a.length;r>i;i++)if("$score"===a[i].field){a.splice(i,1);break}for(l=[],i=0,r=a.length;r>i;i++)l.push("desc"===a[i].direction?-1:1);return c=a.length,c?1===c?(s=a[0].field,u=l[0],function(t,n){return u*e(d(s,t),d(s,n))}):function(t,n){var i,r,o;for(i=0;c>i;i++)if(o=a[i].field, +r=l[i]*e(d(o,t),d(o,n)))return r;return 0}:null},t.prototype.prepareSearch=function(t,e){if("object"==typeof t)return t;e=n({},e);var i=e.fields,r=e.sort,s=e.sort_empty;return i&&!o(i)&&(e.fields=[i]),r&&!o(r)&&(e.sort=[r]),s&&!o(s)&&(e.sort_empty=[s]),{options:e,query:String(t||"").toLowerCase(),tokens:this.tokenize(t),total:0,items:[]}},t.prototype.search=function(t,e){var n,i,r,o,s=this;return i=this.prepareSearch(t,e),e=i.options,t=i.query,o=e.score||s.getScoreFunction(i),t.length?s.iterator(s.items,function(t,r){n=o(t),(e.filter===!1||n>0)&&i.items.push({score:n,id:r})}):s.iterator(s.items,function(t,e){i.items.push({score:1,id:e})}),r=s.getSortFunction(i,e),r&&i.items.sort(r),i.total=i.items.length,"number"==typeof e.limit&&(i.items=i.items.slice(0,e.limit)),i};var e=function(t,e){return"number"==typeof t&&"number"==typeof e?t>e?1:e>t?-1:0:(t=a(String(t||"")),e=a(String(e||"")),t>e?1:e>t?-1:0)},n=function(t,e){var n,i,r,o;for(n=1,i=arguments.length;i>n;n++)if(o=arguments[n])for(r in o)o.hasOwnProperty(r)&&(t[r]=o[r]);return t},i=function(t){return(t+"").replace(/^\s+|\s+$|/g,"")},r=function(t){return(t+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},o=Array.isArray||"undefined"!=typeof $&&$.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},s={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎð]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},a=function(){var t,e,n,i,r="",o={};for(n in s)if(s.hasOwnProperty(n))for(i=s[n].substring(2,s[n].length-1),r+=i,t=0,e=i.length;e>t;t++)o[i.charAt(t)]=n;var a=new RegExp("["+r+"]","g");return function(t){return t.replace(a,function(t){return o[t]}).toLowerCase()}}();return t})}]); \ No newline at end of file diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index cb8c185..448fe7b 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -10,7 +10,6 @@ import Sifter from 'sifter'; * Choices * * To do: - * - Dispatch events * - Remove item by clicking a target * - Set input width based on the size of the contents * - Single select input support @@ -20,9 +19,8 @@ export class Choices { constructor(element = '[data-choice]', userOptions = {}) { // Cutting the mustard - const fakeEl = document.createElement("fakeel"); - const cuttingTheMustard = 'querySelector' in document && 'addEventListener' in document && 'classList' in fakeEl; - if (!cuttingTheMustard) console.error('init: Your browser doesn\'nt support Choices'); + const cuttingTheMustard = 'querySelector' in document && 'addEventListener' in document && 'classList' in document.createElement("div"); + if (!cuttingTheMustard) console.error('init: Your browser doesn\'t support Choices'); // If there are multiple elements, create a new instance // for each element besides the first one (as that already has an instance) @@ -104,7 +102,8 @@ export class Choices { this.init = this.init.bind(this); this.render = this.render.bind(this); this.destroy = this.destroy.bind(this); - + + // Bind event handlers this.onFocus = this.onFocus.bind(this); this.onBlur = this.onBlur.bind(this); this.onKeyUp = this.onKeyUp.bind(this); @@ -113,7 +112,6 @@ export class Choices { this.onPaste = this.onPaste.bind(this); const classNames = this.options.classNames; - this.templates = { containerOuter: () => { return strToEl(`
    `); @@ -258,9 +256,8 @@ export class Choices { * @return */ onKeyDown(e) { - const activeItems = this.getItemsFilteredByActive(); - const activeOptions = this.getOptionsFilteredByActive(); - const inputIsFocussed = this.input === document.activeElement; + if(e.target !== this.input) return; + const ctrlDownKey = e.ctrlKey || e.metaKey; const backKey = 46; const deleteKey = 8; @@ -269,89 +266,95 @@ export class Choices { const escapeKey = 27; const upKey = 38; const downKey = 40; - const hasActiveDropDown = this.dropdown && this.dropdown.classList.contains(this.options.classNames.activeState); + + const activeItems = this.getItemsFilteredByActive(); + const activeOptions = this.getOptionsFilteredByActive(); + const hasFocussedInput = this.input === document.activeElement; + const hasActiveDropdown = this.dropdown && this.dropdown.classList.contains(this.options.classNames.activeState); const hasItems = this.list && this.list.children; + const keyString = String.fromCharCode(event.keyCode); - // If we are typing in the input - if(e.target === this.input) { - // this.input.style.width = getWidthOfInput(this.input); - switch (e.keyCode) { - case aKey: - // If CTRL + A or CMD + A have been pressed and there are items to select - if(ctrlDownKey && hasItems) { - if(this.options.removeItems && !this.input.value && this.options.selectAll && this.input === document.activeElement) { - this.selectAll(this.list.children); - } + // If a user is typing and the dropdown is not active + if(/[a-zA-Z0-9-_ ]/.test(keyString) && this.dropdown && !hasActiveDropdown) { + this.toggleDropdown(); + } + + switch (e.keyCode) { + case aKey: + // If CTRL + A or CMD + A have been pressed and there are items to select + if(ctrlDownKey && hasItems) { + if(this.options.removeItems && !this.input.value && this.options.selectAll && this.input === document.activeElement) { + this.selectAll(this.list.children); } - break; - case enterKey: - // If enter key is pressed and the input has a value - if(e.target.value && this.passedElement.type === 'text') { - const value = this.input.value; - this.handleEnter(activeItems, value); + } + break; + case enterKey: + // If enter key is pressed and the input has a value + if(e.target.value && this.passedElement.type === 'text') { + const value = this.input.value; + this.handleEnter(activeItems, value); + } + + if(this.passedElement.type === 'select-multiple' && hasActiveDropdown) { + const highlighted = this.dropdown.querySelector(`.${this.options.classNames.highlightedState}`); + + if(highlighted) { + const value = highlighted.getAttribute('data-choice-value'); + const label = highlighted.innerHTML; + const id = highlighted.getAttribute('data-choice-id'); + this.addItem(value, label, id); + this.input.value = ""; + } + } + break; + case escapeKey: + if(this.passedElement.type === 'select-multiple' && hasActiveDropdown) { + this.toggleDropdown(); + } + break; + case downKey: + case upKey: + // If up or down key is pressed, traverse through options + if(this.passedElement.type === 'select-multiple' && hasActiveDropdown) { + const selectableOptions = activeOptions.filter((option) => { + return !option.selected; + }); + + let canHighlight = true; + + if(e.keyCode === downKey) { + this.highlightPosition < (selectableOptions.length - 1) ? this.highlightPosition++ : canHighlight = false; + } else if(e.keyCode === upKey) { + this.highlightPosition > 0 ? this.highlightPosition-- : canHighlight = false; } - if(this.passedElement.type === 'select-multiple' && hasActiveDropDown) { - const highlighted = this.dropdown.querySelector(`.${this.options.classNames.highlightedState}`); - - if(highlighted) { - const value = highlighted.getAttribute('data-choice-value'); - const label = highlighted.innerHTML; - const id = highlighted.getAttribute('data-choice-id'); - this.addItem(value, label, id); - this.input.value = ""; - } - } - break; - case escapeKey: - if(this.passedElement.type === 'select-multiple' && hasActiveDropDown) { - this.toggleDropdown(); - } - break; - case downKey: - case upKey: - // If up or down key is pressed, traverse through options - if(this.passedElement.type === 'select-multiple' && hasActiveDropDown) { - const selectableOptions = activeOptions.filter((option) => { - return !option.selected; - }); + if(canHighlight) { + const option = selectableOptions[this.highlightPosition]; + if(option) { + const previousElement = this.dropdown.querySelector(`.${this.options.classNames.highlightedState}`); + const currentElement = this.dropdown.querySelector(`[data-choice-id="${option.id}"]`); - let canHighlight = true; + if(previousElement) { + previousElement.classList.remove(this.options.classNames.highlightedState); + } - if(e.keyCode === downKey) { - this.highlightPosition < (selectableOptions.length - 1) ? this.highlightPosition++ : canHighlight = false; - } else if(e.keyCode === upKey) { - this.highlightPosition > 0 ? this.highlightPosition-- : canHighlight = false; - } - - if(canHighlight) { - const option = selectableOptions[this.highlightPosition]; - if(option) { - const previousElement = this.dropdown.querySelector(`.${this.options.classNames.highlightedState}`); - const currentElement = this.dropdown.querySelector(`[data-choice-id="${option.id}"]`); - - if(previousElement) { - previousElement.classList.remove(this.options.classNames.highlightedState); - } - - if(currentElement) { - currentElement.classList.add(this.options.classNames.highlightedState); - } + if(currentElement) { + currentElement.classList.add(this.options.classNames.highlightedState); } } } - break - case backKey: - case deleteKey: - // If backspace or delete key is pressed and the input has no value - if(inputIsFocussed && !e.target.value) { - this.handleBackspaceKey(activeItems); - e.preventDefault(); - } - break; - default: - break; - } + } + break + case backKey: + case deleteKey: + // If backspace or delete key is pressed and the input has no value + if(hasFocussedInput && !e.target.value) { + this.handleBackspaceKey(activeItems); + e.preventDefault(); + } + break; + default: + break; } } @@ -361,31 +364,35 @@ export class Choices { * @return */ onKeyUp(e) { - if(e.target === this.input) { - if(this.passedElement.type === 'select-multiple' && this.options.allowSearch) { - const charStr = String.fromCharCode(e.keyCode); - if(this.input === document.activeElement && /[a-z0-9]/i.test(charStr)) { - if(this.input.value) { - // If we have a value, filter options based on it - const handleFilter = debounce(() => { - const options = this.getOptionsFiltedBySelectable(); - const sifter = new Sifter(options); - const results = sifter.search(this.input.value, { - fields: ['label', 'value'], - sort: [{field: 'value', direction: 'asc'}], - limit: 10 - }); - this.store.dispatch(filterOptions(results)); - }, 100) - - handleFilter(); - } else { - // Otherwise reset options to active - this.store.dispatch(activateOptions()); - } + if(e.target !== this.input) return; + + if(this.passedElement.type === 'select-multiple' && this.options.allowSearch) { + const options = this.getOptions(); + const hasUnactiveOptions = options.some((option) => { + return option.active !== true; + }); + + if(this.input === document.activeElement) { + if(this.input.value) { + // If we have a value, filter options based on it + const handleFilter = debounce(() => { + const options = this.getOptionsFiltedBySelectable(); + const sifter = new Sifter(options); + const results = sifter.search(this.input.value, { + fields: ['label', 'value'], + sort: [{field: 'value', direction: 'asc'}], + limit: 10 + }); + this.store.dispatch(filterOptions(results)); + }, 100) + + handleFilter(); + } else if(hasUnactiveOptions) { + // Otherwise reset options to active + this.store.dispatch(activateOptions()); } - } - } + } + } }