diff --git a/assets/scripts/dist/bundle.js b/assets/scripts/dist/bundle.js index 98bba8a1..e2e312b2 100644 --- a/assets/scripts/dist/bundle.js +++ b/assets/scripts/dist/bundle.js @@ -1,2 +1,2 @@ -!function(e){function t(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.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 o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.Choices=void 0;var r=function(){function e(e,t){for(var i=0;i1)for(var d=1;d\n '+e.label+"\n \n ")},optgroup:function(e){return(0,u.strToEl)('\n
\n
'+e.value+"
\n
\n ")},item:function(e){return(0,u.strToEl)('\n
\n '+e.label+"\n
\n ")},notice:function(e){return(0,u.strToEl)('\n
\n '+e+"\n
\n ")}},this.init()}return r(e,[{key:"isDisabled",value:function(){return!!this.input.disabled}},{key:"isEmpty",value:function(){return 0===this.store.getState().items.length}},{key:"hasSelectedItems",value:function(){var e=this.getItems();return e.some(function(e){return e.selected===!0})}},{key:"handleSelectAll",value:function(){this.options.removeItems&&!this.input.value&&this.options.selectAll&&this.input===document.activeElement&&this.selectAll(this.list.children)}},{key:"handleEnter",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=!0;if("text"===this.passedElement.type&&(this.options.addItems?this.options.maxItems&&this.options.maxItems<=this.list.children.length?i=!1:this.options.allowDuplicates===!1&&this.passedElement.value&&(i=!e.some(function(e){return e.value===t})):i=!1),i){if("text"===this.passedElement.type){var n=!0;this.options.regexFilter&&(n=this.regexFilter(t)),n&&(this.addItem(t),this.clearInput(this.passedElement))}"select-multiple"===this.passedElement.type&&console.log("hit")}}},{key:"handleBackspaceKey",value:function(e){if(this.options.removeItems&&e){var t=e[e.length-1],i=e.some(function(e){return e.selected===!0});this.options.editItems&&!i&&t?(this.input.value=t.value,this.removeItem(t)):(this.selectItem(t),this.removeAllSelectedItems())}}},{key:"handleClick",value:function(e,t,i){var n=this;this.options.removeItems&&t&&!function(){var o=t.getAttribute("data-choice-id");e.forEach(function(e){e.id!==parseInt(o)||e.selected?i||n.deselectItem(e):n.selectItem(e)})}()}},{key:"onKeyDown",value:function(e){var t=this.getItemsFilteredByActive(),i=this.getOptionsFilteredByActive(),n=this.input===document.activeElement,o=e.ctrlKey||e.metaKey,r=46,s=8,a=13,c=65,l=27,u=38,d=40,h=this.dropdown&&this.dropdown.classList.contains(this.options.classNames.activeState),p=this.list&&this.list.children;if(e.target===this.input)switch(e.keyCode){case c:o&&p&&this.handleSelectAll();break;case a:if(e.target.value&&"text"===this.passedElement.type){var f=this.input.value;this.handleEnter(t,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 l:"select-multiple"===this.passedElement.type&&h&&this.toggleDropdown();break;case d:case u:if("select-multiple"===this.passedElement.type&&h){var b=i.filter(function(e){return!e.selected}),I=!0;if(e.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 r:case s:n&&!e.target.value&&(this.handleBackspaceKey(t),e.preventDefault())}}},{key:"onKeyUp",value:function(e){var t=this;if(e.target===this.input&&"select-multiple"===this.passedElement.type&&this.options.allowSearch){var i=String.fromCharCode(e.keyCode);if(this.input===document.activeElement&&/[a-z0-9]/i.test(i))if(this.input.value){var n=(0,u.debounce)(function(){var e=t.getOptionsFiltedBySelectable(),i=new h.default(e),n=i.search(t.input.value,{fields:["label","value"],sort:[{field:"value",direction:"asc"}],limit:10});t.store.dispatch((0,l.filterOptions)(n))},100);n()}else this.store.dispatch((0,l.activateOptions)())}}},{key:"onClick",value:function(e){var t=this,i=e.shiftKey;if(this.dropdown&&this.toggleDropdown(),this.containerOuter.contains(e.target))if(this.input!==document.activeElement&&this.input.focus(),e.target.hasAttribute("data-choice-item")){var n=this.getItemsFilteredByActive(),o=e.target;this.handleClick(n,o,i)}else e.target.hasAttribute("data-choice-option")&&!function(){var i=t.getOptionsFilteredByActive(),n=e.target.getAttribute("data-choice-id"),o=i.find(function(e){return e.id===parseInt(n)});o.selected||t.addItem(o.value,o.label,o.id)}();else this.hasSelectedItems()&&this.deselectAll(),"select-multiple"===this.passedElement.type&&this.dropdown.classList.contains(this.options.classNames.activeState)&&this.toggleDropdown()}},{key:"onPaste",value:function(e){this.options.allowPaste||e.preventDefault()}},{key:"onFocus",value:function(e){this.containerOuter.classList.add(this.options.classNames.activeState)}},{key:"onBlur",value:function(e){this.containerOuter.classList.remove(this.options.classNames.activeState)}},{key:"clearInput",value:function(){this.input.value&&(this.input.value="")}},{key:"regexFilter",value:function(e){var t=new RegExp(this.options.regexFilter,"i"),i=t.test(e);return i}},{key:"getItemById",value:function(e){if(!e||!(0,u.isType)("Number",e))return void console.error("getItemById: An id was not given or was not a number");var t=this.getItems(),i=t.find(function(t){return t.id===parseInt(e)}),n=this.list.querySelector("[data-choice-id='"+i.id+"']");return n}},{key:"selectItem",value:function(e){if(e){var t=e.id;this.store.dispatch((0,l.selectItem)(t,!0))}}},{key:"deselectItem",value:function(e){if(e){var t=e.id;this.store.dispatch((0,l.selectItem)(t,!1))}}},{key:"selectAll",value:function(){var e=this,t=this.getItems();t.forEach(function(t){e.selectItem(t)})}},{key:"deselectAll",value:function(){var e=this,t=this.getItems();t.forEach(function(t){e.deselectItem(t)})}},{key:"addItem",value:function(e,t){var i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3];this.options.debug&&console.debug("Add item");var o=e.trim(),r=t||o,s=i||-1;this.options.prependValue&&(o=this.options.prependValue+o.toString()),this.options.appendValue&&(o+=this.options.appendValue.toString());var a=this.store.getState().items.length+1;this.store.dispatch((0,l.addItem)(o,r,a,s)),n&&((0,u.isType)("Function",n)?n(a,e):console.error("callbackOnAddItem: Callback is not a function"))}},{key:"removeItem",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this.options.callbackOnRemoveItem:arguments[1];if(!e||!(0,u.isType)("Object",e))return void console.error("removeItem: No item object was passed to be removed");var i=e.id,n=e.value,o=e.optionId;this.store.dispatch((0,l.removeItem)(i,o)),t&&((0,u.isType)("Function",t)?t(n):console.error("callbackOnRemoveItem: Callback is not a function"))}},{key:"removeItemsByValue",value:function(e){var t=this;e&&(0,u.isType)("String",e)||console.error("removeItemsByValue: No value was passed to be removed");var i=this.getItemsFilteredByActive();i.forEach(function(i){i.value===e&&t.removeItem(i)})}},{key:"removeAllItems",value:function(){var e=this,t=this.getItemsFilteredByActive();t.forEach(function(t){t.active&&e.removeItem(t)})}},{key:"removeAllSelectedItems",value:function(){var e=this,t=this.getItemsFilteredByActive();t.forEach(function(t){t.selected&&t.active&&e.removeItem(t)})}},{key:"showDropdown",value:function(){this.dropdown.classList.add(this.options.classNames.activeState);var e=this.dropdown.getBoundingClientRect();e.top+e.height>=document.body.offsetHeight?this.dropdown.classList.add(this.options.classNames.flippedState):this.dropdown.classList.remove(this.options.classNames.flippedState)}},{key:"hideDropdown",value:function(){var e=this.dropdown.classList.contains(this.options.classNames.flippedState);this.dropdown.classList.remove(this.options.classNames.activeState),e&&this.dropdown.classList.remove(this.options.classNames.flippedState)}},{key:"toggleDropdown",value:function(){if(this.dropdown){var e=this.dropdown.classList.contains(this.options.classNames.activeState);e?this.hideDropdown():this.showDropdown()}}},{key:"addOption",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?-1:arguments[1],i=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],n=this.store.getState(),o=n.options.length+1,r=e.value,s=e.innerHTML,a=e.selected;this.store.dispatch((0,l.addOption)(r,s,o,t,i)),a&&this.addItem(r,s,o)}},{key:"addGroup",value:function(e,t,i,n){this.store.dispatch((0,l.addGroup)(e,t,i,n))}},{key:"getItems",value:function(){var e=this.store.getState();return e.items}},{key:"getItemsFilteredByActive",value:function(){var e=this.getItems(),t=e.filter(function(e){return e.active===!0},[]);return t}},{key:"getItemsReducedToValues",value:function(){var e=this.getItems(),t=e.reduce(function(e,t){return e.push(t.value),e},[]);return t}},{key:"getOptions",value:function(){var e=this.store.getState();return e.options}},{key:"getOptionsFilteredByActive",value:function(){var e=this.getOptions(),t=e.filter(function(e){return e.active===!0&&e.disabled===!1&&e.selected!==!0},[]);return t}},{key:"getOptionsFiltedBySelectable",value:function(){var e=this.getOptions(),t=e.filter(function(e){return e.disabled===!1},[]);return t}},{key:"getGroups",value:function(){var e=this.store.getState();return e.groups}},{key:"getGroupsFilteredByActive",value:function(){var e=this.getGroups(),t=this.getOptions(),i=e.filter(function(e){var i=e.active===!0&&e.disabled===!1,n=t.some(function(e){return e.active===!0&&e.disabled===!1});return!(!i||!n)},[]);return i}},{key:"generateInput",value:function(){var e=this,t=(0,u.strToEl)('
'),i=(0,u.strToEl)('
');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,u.wrap)(this.passedElement,i),(0,u.wrap)(i,t);var n=(0,u.strToEl)('
    '),o=(0,u.strToEl)('');if(this.options.placeholder&&this.options.placeholderValue&&(o.placeholder=this.options.placeholderValue,o.style.width=(0,u.getWidthOfInput)(o)),this.options.addItems||(o.disabled=!0,t.classList.add(this.options.classNames.disabledState)),t.appendChild(i),i.appendChild(n),i.appendChild(o),"select-multiple"===this.passedElement.type){this.highlightPosition=0;var r=(0,u.strToEl)('
    '),s=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(t.appendChild(r),this.dropdown=r,s.length)s.forEach(function(t,i){var n=Array.from(t.getElementsByTagName("OPTION")),o=i;n?(e.addGroup(t.label,o,!0,t.disabled),n.forEach(function(i,n){t.disabled?e.addOption(i,o,!0):e.addOption(i,o)})):e.addGroup(t.label,o,!1,t.disabled)});else{var a=Array.from(this.passedElement.options);a.forEach(function(t){e.addOption(t)})}}else"text"===this.passedElement.type&&this.presetItems.forEach(function(t){e.addItem(t)});this.containerOuter=t,this.containerInner=i,this.input=o,this.list=n}},{key:"render",value:function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?this.options.callbackOnRender:arguments[0],i=(this.options.classNames,this.getItemsFilteredByActive());"select-multiple"===this.passedElement.type&&!function(){var t=e.getOptionsFilteredByActive(),i=e.getGroupsFilteredByActive();e.dropdown.innerHTML="";var n=document.createDocumentFragment();if(i.length>=1?i.forEach(function(i,o){var r=t.filter(function(e){return e.groupId===i.id});r.length>=1&&!function(){var t=e.templates.optgroup(i);r.forEach(function(i,n){var o=e.templates.option(i);t.appendChild(o)}),n.appendChild(t)}()}):t.length>=1&&t.forEach(function(t,i){var o=e.templates.option(t);n.appendChild(o)}),e.dropdown.appendChild(n),""===e.dropdown.innerHTML){var o=e.templates.notice("No options to select");n.appendChild(o),e.dropdown.appendChild(n)}}(),i&&!function(){var t=e.getItemsReducedToValues();e.passedElement.value=t.join(e.options.delimiter),e.list.innerHTML="";var n=document.createDocumentFragment();i.forEach(function(t){var i=e.templates.item(t);n.appendChild(i)}),e.list.appendChild(n)}(),t&&((0,u.isType)("Function",t)?t(i):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 e=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(),e&&((0,u.isType)("Function",e)?e():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}}]),e}();window.Choices=e.exports=p},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0,t.compose=t.applyMiddleware=t.bindActionCreators=t.combineReducers=t.createStore=void 0;var o=i(3),r=n(o),s=i(8),a=n(s),c=i(10),l=n(c),u=i(11),d=n(u),h=i(12),p=n(h),f=i(9);n(f);t.createStore=r.default,t.combineReducers=a.default,t.bindActionCreators=l.default,t.applyMiddleware=d.default,t.compose=p.default},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t,i){function n(){f===p&&(f=p.slice())}function r(){return h}function c(e){if("function"!=typeof e)throw new Error("Expected listener to be a function.");var t=!0;return n(),f.push(e),function(){if(t){t=!1,n();var i=f.indexOf(e);f.splice(i,1)}}}function l(e){if(!(0,s.default)(e))throw new Error("Actions must be plain objects. Use custom middleware for async actions.");if("undefined"==typeof e.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,e)}finally{v=!1}for(var t=p=f,i=0;ii;i++)t[i]=arguments[i];return function(e){return function(i,n,o){var s=e(i,n,o),c=s.dispatch,l=[],u={getState:s.getState,dispatch:function(e){return c(e)}};return l=t.map(function(e){return e(u)}),c=a.default.apply(void 0,l)(s.dispatch),r({},s,{dispatch:c})}}}var r=Object.assign||function(e){for(var t=1;ti;i++)t[i]=arguments[i];return function(){if(0===t.length)return arguments.length<=0?void 0:arguments[0];var e=t[t.length-1],i=t.slice(0,-1);return i.reduceRight(function(e,t){return t(e)},e.apply(void 0,arguments))}}t.__esModule=!0,t.default=i},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=i(2),r=i(14),s=n(r),a=i(15),c=n(a),l=i(16),u=n(l),d=(0,o.combineReducers)({items:s.default,groups:c.default,options:u.default});t.default=d},function(e,t){"use strict";function i(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t-1?e.map(function(e){return e.id===parseInt(t.optionId)&&(e.selected=!0),e}):e;case"REMOVE_ITEM":return t.optionId>-1?e.map(function(e){return e.id===parseInt(t.optionId)&&(e.selected=!1),e}):e;case"FILTER_OPTIONS":var n=t.results.items,o=e.map(function(e,t){return e.active=n.some(function(e){return e.id===t}),e});return o;case"ACTIVATE_OPTIONS":return e.map(function(e){return e.active=t.active,e});default:return e}};t.default=n},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.addItem=function(e,t,i,n){return{type:"ADD_ITEM",value:e,label:t,id:i,optionId:n}},t.removeItem=function(e,t){return{type:"REMOVE_ITEM",id:e,optionId:t}},t.selectItem=function(e,t){return{type:"SELECT_ITEM",id:e,selected:t}},t.addOption=function(e,t,i,n,o){return{type:"ADD_OPTION",value:e,label:t,id:i,groupId:n,disabled:o}},t.filterOptions=function(e){return{type:"FILTER_OPTIONS",results:e}},t.activateOptions=function(){var e=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];return{type:"ACTIVATE_OPTIONS",active:e}},t.addGroup=function(e,t,i,n){return{type:"ADD_GROUP",value:e,id:t,active:i,disabled:n}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=(t.hasClass=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},t.capitalise=function(e){return e.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})},t.isType=function(e,t){var i=Object.prototype.toString.call(t).slice(8,-1);return void 0!==t&&null!==t&&i===e}),n=(t.extend=function r(){for(var e={},t=!1,n=arguments.length,o=function(n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t&&i("Object",n[o])?e[o]=r(!0,e[o],n[o]):e[o]=n[o])},s=0;n>s;s++){var a=arguments[s];i("Object",a)?o(a):console.error("Custom options must be an object")}return e},t.whichTransitionEvent=function(){var e,t=document.createElement("fakeelement"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in i)if(void 0!==t.style[e])return i[e]},t.whichAnimationEvent=function(){var e,t=document.createElement("fakeelement"),i={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(e in i)if(void 0!==t.style[e])return i[e]}),o=(t.getParentsUntil=function(e,t,i){for(var n=[];e&&e!==document;e=e.parentNode){if(t){var o=t.charAt(0);if("."===o&&e.classList.contains(t.substr(1)))break;if("#"===o&&e.id===t.substr(1))break;if("["===o&&e.hasAttribute(t.substr(1,t.length-1)))break;if(e.tagName.toLowerCase()===t)break}if(i){var r=i.charAt(0);"."===r&&e.classList.contains(i.substr(1))&&n.push(e),"#"===r&&e.id===i.substr(1)&&n.push(e),"["===r&&e.hasAttribute(i.substr(1,i.length-1))&&n.push(e),e.tagName.toLowerCase()===i&&n.push(e)}else n.push(e)}return 0===n.length?null:n},t.wrap=function(e,t){return t=t||document.createElement("div"),e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t),t.appendChild(e)},t.getSiblings=function(e){for(var t=[],i=e.parentNode.firstChild;i;i=i.nextSibling)1===i.nodeType&&i!==e&&t.push(i);return t},t.findAncestor=function(e,t){for(;(e=e.parentElement)&&!e.classList.contains(t););return e},t.debounce=function(e,t,i){var n;return function(){var o=this,r=arguments,s=function(){n=null,i||e.apply(o,r)},a=i&&!n;clearTimeout(n),n=setTimeout(s,t),a&&e.apply(o,r)}},t.getElemDistance=function(e){var t=0;if(e.offsetParent)do t+=e.offsetTop,e=e.offsetParent;while(e);return t>=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.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.stripHTML=function(e){var t=document.createElement("DIV");return t.innerHTML=e,t.textContent||t.innerText||""},t.addAnimation=function(e,t){var i=n(),o=function r(){e.classList.remove(t),e.removeEventListener(i,r,!1)};e.classList.add(t),e.addEventListener(i,o,!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=arguments.length<=1||void 0===arguments[1]?20:arguments[1],i=e.value||e.placeholder,n=e.offsetWidth;if(i){var r=o(''+i+"");r.style.position="absolute",r.style.top="-9999px",r.style.left="-9999px",r.style.padding="0",r.style.width="auto",document.body.appendChild(r),r.offsetWidth>t&&r.offsetWidth!=e.offsetWidth&&(n=r.offsetWidth+t/4),document.body.removeChild(r)}return n+"px"}},function(e,t,i){var n,o;!function(r,s){n=s,o="function"==typeof n?n.call(t,i,t,e):n,!(void 0!==o&&(e.exports=o))}(this,function(){var e=function(e,t){this.items=e,this.settings=t||{diacritics:!0}};e.prototype.tokenize=function(e){if(e=n(String(e||"").toLowerCase()),!e||!e.length)return[];var t,i,r,a,c=[],l=e.split(/ +/);for(t=0,i=l.length;i>t;t++){if(r=o(l[t]),this.settings.diacritics)for(a in s)s.hasOwnProperty(a)&&(r=r.replace(new RegExp(a,"g"),s[a]));c.push({string:l[t],regex:new RegExp(r,"i")})}return c},e.prototype.iterator=function(e,t){var i;i=r(e)?Array.prototype.forEach||function(e){for(var t=0,i=this.length;i>t;t++)e(this[t],t,this)}:function(e){for(var t in this)this.hasOwnProperty(t)&&e(this[t],t,this)},i.apply(e,[t])},e.prototype.getScoreFunction=function(e,t){var i,n,o,r;i=this,e=i.prepareSearch(e,t),o=e.tokens,n=e.options.fields,r=o.length;var s=function(e,t){var i,n;return e?(e=String(e||""),n=e.search(t.regex),-1===n?0:(i=t.string.length/e.length,0===n&&(i+=.5),i)):0},a=function(){var e=n.length;return e?1===e?function(e,t){return s(t[n[0]],e)}:function(t,i){for(var o=0,r=0;e>o;o++)r+=s(i[n[o]],t);return r/e}:function(){return 0}}();return r?1===r?function(e){return a(o[0],e)}:"and"===e.options.conjunction?function(e){for(var t,i=0,n=0;r>i;i++){if(t=a(o[i],e),0>=t)return 0;n+=t}return n/r}:function(e){for(var t=0,i=0;r>t;t++)i+=a(o[t],e);return i/r}:function(){return 0}},e.prototype.getSortFunction=function(e,i){var n,o,r,s,a,c,l,u,d,h,p;if(r=this,e=r.prepareSearch(e,i),p=!e.query&&i.sort_empty||i.sort,d=function(e,t){return"$score"===e?t.score:r.items[t.id][e]},a=[],p)for(n=0,o=p.length;o>n;n++)(e.query||"$score"!==p[n].field)&&a.push(p[n]);if(e.query){for(h=!0,n=0,o=a.length;o>n;n++)if("$score"===a[n].field){h=!1;break}h&&a.unshift({field:"$score", -direction:"desc"})}else for(n=0,o=a.length;o>n;n++)if("$score"===a[n].field){a.splice(n,1);break}for(u=[],n=0,o=a.length;o>n;n++)u.push("desc"===a[n].direction?-1:1);return c=a.length,c?1===c?(s=a[0].field,l=u[0],function(e,i){return l*t(d(s,e),d(s,i))}):function(e,i){var n,o,r;for(n=0;c>n;n++)if(r=a[n].field,o=u[n]*t(d(r,e),d(r,i)))return o;return 0}:null},e.prototype.prepareSearch=function(e,t){if("object"==typeof e)return e;t=i({},t);var n=t.fields,o=t.sort,s=t.sort_empty;return n&&!r(n)&&(t.fields=[n]),o&&!r(o)&&(t.sort=[o]),s&&!r(s)&&(t.sort_empty=[s]),{options:t,query:String(e||"").toLowerCase(),tokens:this.tokenize(e),total:0,items:[]}},e.prototype.search=function(e,t){var i,n,o,r,s=this;return n=this.prepareSearch(e,t),t=n.options,e=n.query,r=t.score||s.getScoreFunction(n),e.length?s.iterator(s.items,function(e,o){i=r(e),(t.filter===!1||i>0)&&n.items.push({score:i,id:o})}):s.iterator(s.items,function(e,t){n.items.push({score:1,id:t})}),o=s.getSortFunction(n,t),o&&n.items.sort(o),n.total=n.items.length,"number"==typeof t.limit&&(n.items=n.items.slice(0,t.limit)),n};var t=function(e,t){return"number"==typeof e&&"number"==typeof t?e>t?1:t>e?-1:0:(e=a(String(e||"")),t=a(String(t||"")),e>t?1:t>e?-1:0)},i=function(e,t){var i,n,o,r;for(i=1,n=arguments.length;n>i;i++)if(r=arguments[i])for(o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);return e},n=function(e){return(e+"").replace(/^\s+|\s+$|/g,"")},o=function(e){return(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},r=Array.isArray||"undefined"!=typeof $&&$.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},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 e,t,i,n,o="",r={};for(i in s)if(s.hasOwnProperty(i))for(n=s[i].substring(2,s[i].length-1),o+=n,e=0,t=n.length;t>e;e++)r[n.charAt(e)]=i;var a=new RegExp("["+o+"]","g");return function(e){return e.replace(a,function(e){return r[e]}).toLowerCase()}}();return e})}]); \ 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 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 diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 64df5b2d..cb8c1856 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -17,15 +17,13 @@ import Sifter from 'sifter'; * - Populate options by function */ export class Choices { - constructor(element = '[data-choice]', options) { + 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 userOptions = options || {}; - // If there are multiple elements, create a new instance // for each element besides the first one (as that already has an instance) if(isType('String', element)) { @@ -86,7 +84,7 @@ export class Choices { this.initialised = false; // Merge options with user options - this.options = extend(defaultOptions, userOptions || {}); + this.options = extend(defaultOptions, userOptions); // Create data store this.store = createStore(rootReducer); @@ -117,6 +115,24 @@ export class Choices { const classNames = this.options.classNames; this.templates = { + containerOuter: () => { + return strToEl(`
      `); + }, + containerInner: () => { + return strToEl(`
      `); + }, + list: () => { + return strToEl(`
        `); + }, + input: () => { + return strToEl(``); + }, + dropdown: () => { + return strToEl(`
        `); + }, + notice: (label) => { + return strToEl(`
        ${ label }
        `); + }, option: (data) => { return strToEl(`
        @@ -133,57 +149,23 @@ export class Choices { }, item: (data) => { return strToEl(` -
        +
        ${ data.label }
        `); }, - notice: (label) => { - return strToEl(` -
        - ${ label } -
        - `); - }, }; // Let's have it large this.init(); } - - /* State tests */ - - /** - * Whether input is disabled - * @return {Boolean} - */ - isDisabled() { - return (this.input.disabled) ? true : false; - } - - /** - * Whether there are no values - * @return {Boolean} - */ - isEmpty() { - return (this.store.getState().items.length === 0) ? true : false; - } - - hasSelectedItems() { - const items = this.getItems(); - return items.some((item) => { - return item.selected === true; - }); - } - - /* Event handling */ - handleSelectAll() { - if(this.options.removeItems && !this.input.value && this.options.selectAll && this.input === document.activeElement) { - this.selectAll(this.list.children); - } - }; - handleEnter(activeItems, value = null) { + /** + * Process enter key event + * @param {Array} activeItems Items that are currently active + * @return + */ + handleEnter(activeItems, value) { let canUpdate = true; if(this.passedElement.type === 'text') { @@ -202,11 +184,8 @@ export class Choices { } else { canUpdate = false; } - } - // All is good, update - if (canUpdate) { - if(this.passedElement.type === 'text') { + if (canUpdate) { let canAddItem = true; // If a user has supplied a regular expression filter @@ -222,13 +201,14 @@ export class Choices { this.clearInput(this.passedElement); } } - - if(this.passedElement.type === 'select-multiple') { - console.log('hit'); - } } }; + /** + * Process back space event + * @param {Array} Active items + * @return + */ handleBackspaceKey(activeItems) { if(this.options.removeItems && activeItems) { const lastItem = activeItems[activeItems.length - 1]; @@ -248,7 +228,14 @@ export class Choices { } }; - handleClick(activeItems, target, shiftKey) { + /** + * Handle what happens on a click event + * @param {Array} activeItems Items that are active + * @param {HTMLElement} target What triggered the click + * @param {Boolean} hasShiftKey Whether shift key is active + * @return + */ + handleClick(activeItems, target, hasShiftKey) { if(this.options.removeItems && target) { const passedId = target.getAttribute('data-choice-id'); @@ -258,15 +245,15 @@ export class Choices { activeItems.forEach((item) => { if(item.id === parseInt(passedId) && !item.selected) { this.selectItem(item); - } else if(!shiftKey) { + } else if(!hasShiftKey) { this.deselectItem(item); } }); } } - /** - * Handle keydown event + /** + * Key down event * @param {Object} e Event * @return */ @@ -292,7 +279,9 @@ export class Choices { case aKey: // If CTRL + A or CMD + A have been pressed and there are items to select if(ctrlDownKey && hasItems) { - this.handleSelectAll(); + if(this.options.removeItems && !this.input.value && this.options.selectAll && this.input === document.activeElement) { + this.selectAll(this.list.children); + } } break; case enterKey: @@ -366,6 +355,11 @@ export class Choices { } } + /** + * Key up event + * @param {Object} e Event + * @return + */ onKeyUp(e) { if(e.target === this.input) { if(this.passedElement.type === 'select-multiple' && this.options.allowSearch) { @@ -395,13 +389,14 @@ export class Choices { } - /** - * Handle click event + /** + * Click event * @param {Object} e Event * @return */ onClick(e) { - const shiftKey = e.shiftKey; + const activeItems = this.getItemsFilteredByActive(); + const hasShiftKey = e.shiftKey ? true : false; if(this.dropdown) { this.toggleDropdown(); @@ -415,11 +410,7 @@ export class Choices { if(e.target.hasAttribute('data-choice-item')) { // If we are clicking on an item - const activeItems = this.getItemsFilteredByActive(); - const target = e.target; - - this.handleClick(activeItems, target, shiftKey); - + this.handleClick(activeItems, e.target, hasShiftKey); } else if(e.target.hasAttribute('data-choice-option')) { // If we are clicking on an option const options = this.getOptionsFilteredByActive(); @@ -435,9 +426,14 @@ export class Choices { } else { // Click is outside of our element so close dropdown and de-select items - if(this.hasSelectedItems()) { + const hasSelectedItems = activeItems.some((item) => { + return item.selected === true; + }); + + if(hasSelectedItems) { this.deselectAll(); } + // If there is a dropdown and it is active if(this.passedElement.type === 'select-multiple' && this.dropdown.classList.contains(this.options.classNames.activeState)) { this.toggleDropdown(); @@ -445,6 +441,12 @@ export class Choices { } } + + /** + * Paste event + * @param {Object} e Event + * @return + */ onPaste(e) { // Disable pasting into the input if option has been set if(!this.options.allowPaste) { @@ -452,16 +454,24 @@ export class Choices { } } + /** + * Focus event + * @param {Object} e Event + * @return + */ onFocus(e) { this.containerOuter.classList.add(this.options.classNames.activeState); } + /** + * Blur event + * @param {Object} e Event + * @return + */ onBlur(e) { this.containerOuter.classList.remove(this.options.classNames.activeState); } - /* Methods */ - /** * Set value of input to blank * @return @@ -607,6 +617,11 @@ export class Choices { } } + /** + * Remove an item from the store by its value + * @param {String} value Value to search for + * @return + */ removeItemsByValue(value) { if(!value || !isType('String', value)) { console.error('removeItemsByValue: No value was passed to be removed'); @@ -622,7 +637,8 @@ export class Choices { } /** - * Remove all items from array + * Remove all items from store array + * Note: removed items are soft deleted * @param {Boolean} selectedOnly Optionally remove only selected items * @return */ @@ -636,6 +652,11 @@ export class Choices { }); } + /** + * Remove all selected items from store + * Note: removed items are soft deleted + * @return + */ removeAllSelectedItems() { const items = this.getItemsFilteredByActive(); @@ -646,17 +667,27 @@ export class Choices { }); } + /** + * Show dropdown to user by adding active state class + * @return + */ showDropdown() { this.dropdown.classList.add(this.options.classNames.activeState); - const dimensions = this.dropdown.getBoundingClientRect(); - if(dimensions.top + dimensions.height >= document.body.offsetHeight) { + const shouldFlip = dimensions.top + dimensions.height >= document.body.offsetHeight; + + // Whether or not the dropdown should appear above or below input + if(shouldFlip) { this.dropdown.classList.add(this.options.classNames.flippedState); } else { this.dropdown.classList.remove(this.options.classNames.flippedState); } } + /** + * Hide dropdown from user + * @return {[type]} [description] + */ hideDropdown() { // A dropdown flips if it does not have space below the input const isFlipped = this.dropdown.classList.contains(this.options.classNames.flippedState); @@ -668,6 +699,10 @@ export class Choices { } } + /** + * Determine whether to hide or show dropdown based on its current state + * @return + */ toggleDropdown() { if(!this.dropdown) return; const isActive = this.dropdown.classList.contains(this.options.classNames.activeState); @@ -679,6 +714,13 @@ export class Choices { } } + /** + * Add option to dropdown + * @param {Object} option Option to add + * @param {Number} groupId ID of the options group + * @param {Boolean} disabled Whether the option is disabled + * @return + */ addOption(option, groupId = -1, disabled = false) { // Generate unique id const state = this.store.getState(); @@ -694,15 +736,37 @@ export class Choices { } } - addGroup(value, id, active, disabled) { - this.store.dispatch(addGroup(value, id, active, disabled)); + /** + * Add group to dropdown + * @param {Object} group Group to add + * @param {Number} index Whether this is the first group to add + */ + addGroup(group, id, isFirst) { + const groupOptions = Array.from(group.getElementsByTagName('OPTION')); + const groupId = id; + + if(groupOptions) { + this.store.dispatch(addGroup(group.label, groupId, true, group.disabled)); + + groupOptions.forEach((option, optionIndex) => { + // We want to pre-highlight the first option + const highlighted = isFirst && optionIndex === 0 ? true : false; + + // If group is disabled, disable all of its children + if(group.disabled) { + this.addOption(option, groupId, true); + } else { + this.addOption(option, groupId); + } + }); + } else { + this.store.dispatch(addGroup(group.label, group.id, false, group.disabled)); + } } - /* Getters */ - /** - * Get items in state - * @return {Array} Array of item objects + * Get items from store + * @return {Array} Item objects */ getItems() { const state = this.store.getState(); @@ -710,8 +774,8 @@ export class Choices { } /** - * Get items in state if they are active - * @return {Array} Array of item objects + * Get active items from store + * @return {Array} Item objects */ getItemsFilteredByActive() { const items = this.getItems(); @@ -724,8 +788,8 @@ export class Choices { } /** - * Get items in state reduced to just their values - * @return {Array} Array of items + * Get items from store reduced to just their values + * @return {Array} Item objects */ getItemsReducedToValues() { const items = this.getItems(); @@ -739,14 +803,18 @@ export class Choices { } /** - * Get options in state - * @return {Array} Array of item options + * Get options from store + * @return {Array} Option objects */ getOptions() { const state = this.store.getState(); return state.options; } + /** + * Get active options from store + * @return {Array} Option objects + */ getOptionsFilteredByActive() { const options = this.getOptions(); const valueArray = options.filter((option) => { @@ -756,6 +824,10 @@ export class Choices { return valueArray; } + /** + * Get selectable options from store + * @return {Array} Option objects + */ getOptionsFiltedBySelectable() { const options = this.getOptions(); const valueArray = options.filter((option) => { @@ -765,11 +837,19 @@ export class Choices { return valueArray; } + /** + * Get groups from store + * @return {Array} Group objects + */ getGroups() { const state = this.store.getState(); return state.groups; } + /** + * Get active groups from store + * @return {Array} Group objects + */ getGroupsFilteredByActive() { const groups = this.getGroups(); const options = this.getOptions(); @@ -784,16 +864,16 @@ export class Choices { return valueArray; } - - /* Rendering */ /** * Create DOM structure around passed select element * @return */ generateInput() { - const containerOuter = strToEl(`
        `); - const containerInner = strToEl(`
        `); + const containerOuter = this.templates['containerOuter'](); + const containerInner = this.templates['containerInner'](); + const list = this.templates['list'](); + const input = this.templates['input'](); // Hide passed input this.passedElement.classList.add(this.options.classNames.input, this.options.classNames.hiddenState); @@ -806,11 +886,7 @@ export class Choices { // Wrapper inner container with outer container wrap(containerInner, containerOuter); - - const list = strToEl(`
          `); - const input = strToEl(``); - // If placeholder has been enabled and we have a value if (this.options.placeholder && this.options.placeholderValue) { input.placeholder = this.options.placeholderValue; @@ -823,13 +899,12 @@ export class Choices { } containerOuter.appendChild(containerInner); - containerInner.appendChild(list); containerInner.appendChild(input); if(this.passedElement.type === 'select-multiple') { this.highlightPosition = 0; - const dropdown = strToEl(`
          `); + const dropdown = this.templates['dropdown'](); const passedGroups = Array.from(this.passedElement.getElementsByTagName('OPTGROUP')); containerOuter.appendChild(dropdown); @@ -838,26 +913,8 @@ export class Choices { if(passedGroups.length) { passedGroups.forEach((group, index) => { - const groupOptions = Array.from(group.getElementsByTagName('OPTION')); - const groupId = index; - - if(groupOptions) { - this.addGroup(group.label, groupId, true, group.disabled); - groupOptions.forEach((option, optionIndex) => { - // We want to pre-highlight the first option - const highlighted = index === 0 && optionIndex === 0 ? true : false; - - // If group is disabled, disable all of its children - if(group.disabled) { - this.addOption(option, groupId, true); - } else { - this.addOption(option, groupId); - } - }); - } else { - this.addGroup(group.label, groupId, false, group.disabled); - } - + const isFirst = index === 0 ? true : false; + this.addGroup(group, index, isFirst); }); } else { const passedOptions = Array.from(this.passedElement.options); @@ -877,7 +934,6 @@ export class Choices { this.containerInner = containerInner; this.input = input; this.list = list; - } /** @@ -976,6 +1032,7 @@ export class Choices { /** * Trigger event listeners + * @return */ addEventListeners() { document.addEventListener('keyup', this.onKeyUp); @@ -989,6 +1046,7 @@ export class Choices { /** * Destroy event listeners + * @return */ removeEventListeners() { document.removeEventListener('keyup', this.onKeyUp);