diff --git a/assets/scripts/dist/bundle.js b/assets/scripts/dist/bundle.js index 2b3678a..fed92bc 100644 --- a/assets/scripts/dist/bundle.js +++ b/assets/scripts/dist/bundle.js @@ -1,2 +1,2 @@ -!function(t){function e(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="/assets/scripts/dist/",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(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 s=function(){function t(t,e){for(var i=0;i1)for(var a=1;a=1){var t=e.getOptionsFiltedBySelectable(),i=new h.default(t,{keys:["label","value"],shouldSort:!0,include:"score"}),n=i.search(e.input.value);e.isSearching=!0,e.store.dispatch((0,c.filterOptions)(n))}},500);o()}else n&&(this.isSearching=!1,this.store.dispatch((0,c.activateOptions)()))}}},{key:"onClick",value:function(t){var e=this,i=this.getItemsFilteredByActive(),n=!!t.shiftKey;if("select-multiple"!==this.passedElement.type||this.dropdown.classList.contains(this.options.classNames.activeState)||this.toggleDropdown(),this.containerOuter.contains(t.target))this.input!==document.activeElement&&this.input.focus(),t.target.hasAttribute("data-item")?this.handleClick(i,t.target,n):t.target.hasAttribute("data-option")&&!function(){var i=e.getOptionsFilteredByActive(),n=t.target.getAttribute("data-id"),o=i.find(function(t){return t.id===parseInt(n)});o.selected||o.disabled||e.addItem(o.value,o.label,o.id)}();else{var o=i.some(function(t){return t.selected===!0});o&&this.deselectAll(),this.containerOuter.classList.remove(this.options.classNames.activeState),"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:"onMouseOver",value:function(t){this.dropdown&&(t.target===this.dropdown||(0,u.findAncestor)(t.target,this.options.classNames.listDropdown))&&t.target.hasAttribute("data-option")&&this.highlightOption(t.target)}},{key:"onFocus",value:function(t){this.containerOuter.classList.contains(this.options.classNames.activeState)||this.containerOuter.classList.add(this.options.classNames.activeState)}},{key:"onBlur",value:function(t){var e=this.dropdown&&this.dropdown.classList.contains(this.options.classNames.activeState);e||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"),i=e.test(t);return i}},{key:"scrollToOption",value:function(t,e){var i=this;if(t){var n=this.dropdown.offsetHeight,o=t.offsetHeight,s=t.offsetTop+o,r=this.dropdown.scrollTop+n,a=void 0,l=function c(t,e,n){var o=!1,s=void 0,r=void 0,a=4;n>0?(s=(e-i.dropdown.scrollTop)/a,r=s>1?s:1,i.dropdown.scrollTop=i.dropdown.scrollTop+r,i.dropdown.scrollTop1?s:1,i.dropdown.scrollTop=i.dropdown.scrollTop-r,i.dropdown.scrollTop>e&&(o=!0)),o&&requestAnimationFrame(function(t){c(t,e,n)})};e>0?(a=this.dropdown.scrollTop+s-r,requestAnimationFrame(function(t){l(t,a,1)})):(a=t.offsetTop,requestAnimationFrame(function(t){l(t,a,-1)}))}}},{key:"highlightOption",value:function(t){var e=this,i=Array.from(this.dropdown.querySelectorAll("[data-option-selectable]"));if(i.length){var n=Array.from(this.dropdown.querySelectorAll("."+this.options.classNames.highlightedState));if(n.forEach(function(t){t.classList.remove(e.options.classNames.highlightedState)}),t)t.classList.add(this.options.classNames.highlightedState),this.highlightPosition=i.indexOf(t);else{var o=void 0;o=i.length>this.highlightPosition?i[this.highlightPosition]:i[i.length-1],o||(o=i[0]),o.classList.add(this.options.classNames.highlightedState)}}}},{key:"selectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,c.selectItem)(e,!0))}}},{key:"deselectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,c.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 i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3],o=t.trim(),s=e||o,r=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,c.addItem)(o,s,a,r)),n&&((0,u.isType)("Function",n)?n(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,u.isType)("Object",t))return void console.error("removeItem: No item object was passed to be removed");var i=t.id,n=t.value,o=t.optionId;this.store.dispatch((0,c.removeItem)(i,o)),e&&((0,u.isType)("Function",e)?e(n):console.error("callbackOnRemoveItem: Callback is not a function"))}},{key:"removeItemsByValue",value:function(t){var e=this;t&&(0,u.isType)("String",t)||console.error("removeItemsByValue: No value was passed to be removed");var i=this.getItemsFilteredByActive();i.forEach(function(i){i.value===t&&e.removeItem(i)})}},{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],i=this.store.getState(),n=i.options.length+1,o=t.value,s=t.innerHTML,r=t.disabled||t.parentNode.disabled;this.store.dispatch((0,c.addOption)(o,s,n,e,r)),t.selected&&!r&&this.addItem(o,s,n)}},{key:"addGroup",value:function(t,e,i){var n=this,o=Array.from(t.getElementsByTagName("OPTION")),s=e;o?(this.store.dispatch((0,c.addGroup)(t.label,s,!0,t.disabled)),o.forEach(function(t,e){n.addOption(t,s)})):this.store.dispatch((0,c.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.selected!==!0},[]);return e}},{key:"getOptionsFiltedBySelectable",value:function(){var t=this.getOptions(),e=t.filter(function(t){return t.selected===!1&&t.disabled!==!0},[]);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(),i=t.filter(function(t){var i=t.active===!0&&t.disabled===!1,n=e.some(function(t){return t.active===!0&&t.disabled===!1});return!(!i||!n)},[]);return i}},{key:"generateInput",value:function(){var t=this,e=this.getTemplate("containerOuter"),i=this.getTemplate("containerInner"),n=this.getTemplate("list"),o=this.getTemplate("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,u.wrap)(this.passedElement,i),(0,u.wrap)(i,e),this.options.placeholder&&this.options.placeholderValue&&(o.placeholder=this.options.placeholderValue,o.style.width=(0,u.getWidthOfInput)(o)),this.options.addItems||(o.disabled=!0,e.classList.add(this.options.classNames.disabledState)),e.appendChild(i),i.appendChild(n),i.appendChild(o),"select-multiple"===this.passedElement.type){this.highlightPosition=0;var s=this.getTemplate("dropdown"),r=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(e.appendChild(s),this.dropdown=s,this.isSearching=!1,r.length)r.forEach(function(e,i){var n=0===i;t.addGroup(e,i,n)});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=i,this.input=o,this.list=n}},{key:"render",value:function(){var t=this,e=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 e=t.getOptionsFilteredByActive(),i=t.getGroupsFilteredByActive(),n=document.createDocumentFragment();if(i.length>=1&&t.isSearching!==!0?i.forEach(function(i,o){var s=e.filter(function(t){return t.groupId===i.id});s.length>=1&&!function(){var e=t.getTemplate("optgroup",i);s.forEach(function(i,n){var o=t.getTemplate("option",i);e.appendChild(o)}),n.appendChild(e)}()}):e.length>=1&&e.forEach(function(e,i){var o=t.getTemplate("option",e);n.appendChild(o)}),t.dropdown.innerHTML="",n.children.length)t.dropdown.appendChild(n),t.highlightOption();else{var o=t.getTemplate("notice","No options to select");t.dropdown.appendChild(o)}}(),i&&!function(){var e=t.getItemsReducedToValues();t.passedElement.value=e.join(t.options.delimiter),t.list.innerHTML="";var n=document.createDocumentFragment();i.forEach(function(e){var i=t.getTemplate("item",e);n.appendChild(i)}),t.list.appendChild(n)}(),e&&((0,u.isType)("Function",e)?e(i):console.error("callbackOnRender: Callback is not a function"))}},{key:"getTemplate",value:function(t){if(t){for(var e=this.options.templates,i=arguments.length,n=Array(i>1?i-1:0),o=1;i>o;o++)n[o-1]=arguments[o];return e[t].apply(e,n)}}},{key:"createTemplates",value:function(){var t=this.options.classNames,e={containerOuter:function(){return(0,u.strToEl)('
')},containerInner:function(){return(0,u.strToEl)('
')},list:function(){return(0,u.strToEl)('
    ')},input:function(){return(0,u.strToEl)('')},dropdown:function(){return(0,u.strToEl)('
    ')},notice:function(e){return(0,u.strToEl)('
    '+e+"
    ")},option:function(e){return(0,u.strToEl)('\n
    \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 ")}};this.options.templates=(0,u.extend)(this.options.templates,e)}},{key:"addEventListeners",value:function(){document.addEventListener("keyup",this.onKeyUp),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("click",this.onClick),document.addEventListener("paste",this.onPaste),document.addEventListener("mouseover",this.onMouseOver),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),document.removeEventListener("mouseover",this.onMouseOver),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.createTemplates(),this.generateInput(),this.store.subscribe(this.render),this.render(),this.addEventListeners(),t&&((0,u.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,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0,e.compose=e.applyMiddleware=e.bindActionCreators=e.combineReducers=e.createStore=void 0;var o=i(3),s=n(o),r=i(8),a=n(r),l=i(10),c=n(l),u=i(11),d=n(u),h=i(12),p=n(h),f=i(9);n(f);e.createStore=s.default,e.combineReducers=a.default,e.bindActionCreators=c.default,e.applyMiddleware=d.default,e.compose=p.default},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e,i){function n(){f===p&&(f=p.slice())}function s(){return h}function l(t){if("function"!=typeof t)throw new Error("Expected listener to be a function.");var e=!0;return n(),f.push(t),function(){if(e){e=!1,n();var i=f.indexOf(t);f.splice(i,1)}}}function c(t){if(!(0,r.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,i=0;ii;i++)e[i]=arguments[i];return function(t){return function(i,n,o){var r=t(i,n,o),l=r.dispatch,c=[],u={getState:r.getState,dispatch:function(t){return l(t)}};return c=e.map(function(t){return t(u)}),l=a.default.apply(void 0,c)(r.dispatch),s({},r,{dispatch:l})}}}var s=Object.assign||function(t){for(var e=1;ei;i++)e[i]=arguments[i];return function(){if(0===e.length)return arguments.length<=0?void 0:arguments[0];var t=e[e.length-1],i=e.slice(0,-1);return i.reduceRight(function(t,e){return e(t)},t.apply(void 0,arguments))}}e.__esModule=!0,e.default=i},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var o=i(2),s=i(14),r=n(s),a=i(15),l=n(a),c=i(16),u=n(c),d=(0,o.combineReducers)({items:r.default,groups:l.default,options:u.default});e.default=d},function(t,e){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e-1?t.map(function(t){return t.id===parseInt(e.optionId)&&(t.selected=!0),t}):t;case"REMOVE_ITEM":return e.optionId>-1?t.map(function(t){return t.id===parseInt(e.optionId)&&(t.selected=!1),t}):t;case"FILTER_OPTIONS":var n=e.results,o=t.map(function(t,e){return t.active=n.some(function(e){return e.item.id===t.id?(t.score=e.score,!0):void 0}),t}).sort(function(t,e){return t.score-e.score});return o;case"ACTIVATE_OPTIONS":return t.map(function(t){return t.active=e.active,t});default:return t}};e.default=n},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.addItem=function(t,e,i,n){return{type:"ADD_ITEM",value:t,label:e,id:i,optionId:n}},e.removeItem=function(t,e){return{type:"REMOVE_ITEM",id:t,optionId:e}},e.selectItem=function(t,e){return{type:"SELECT_ITEM",id:t,selected:e}},e.addOption=function(t,e,i,n,o){return{type:"ADD_OPTION",value:t,label:e,id:i,groupId:n,disabled:o}},e.filterOptions=function(t){return{type:"FILTER_OPTIONS",results:t}},e.activateOptions=function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];return{type:"ACTIVATE_OPTIONS",active:t}},e.addGroup=function(t,e,i,n){return{type:"ADD_GROUP",value:t,id:e,active:i,disabled:n}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=(e.hasClass=function(t,e){return new RegExp(" "+e+" ").test(" "+t.className+" ")},e.capitalise=function(t){return t.replace(/\w\S*/g,function(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()})},e.isType=function(t,e){var i=Object.prototype.toString.call(e).slice(8,-1);return void 0!==e&&null!==e&&i===t}),n=(e.extend=function s(){for(var t={},e=!1,n=arguments.length,o=function(n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e&&i("Object",n[o])?t[o]=s(!0,t[o],n[o]):t[o]=n[o])},r=0;n>r;r++){var a=arguments[r];i("Object",a)?o(a):console.error("Custom options must be an object")}return t},e.whichTransitionEvent=function(){var t,e=document.createElement("fakeelement"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in i)if(void 0!==e.style[t])return i[t]},e.whichAnimationEvent=function(){var t,e=document.createElement("fakeelement"),i={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in i)if(void 0!==e.style[t])return i[t]}),o=(e.getParentsUntil=function(t,e,i){for(var n=[];t&&t!==document;t=t.parentNode){if(e){var o=e.charAt(0);if("."===o&&t.classList.contains(e.substr(1)))break;if("#"===o&&t.id===e.substr(1))break;if("["===o&&t.hasAttribute(e.substr(1,e.length-1)))break;if(t.tagName.toLowerCase()===e)break}if(i){var s=i.charAt(0);"."===s&&t.classList.contains(i.substr(1))&&n.push(t),"#"===s&&t.id===i.substr(1)&&n.push(t),"["===s&&t.hasAttribute(i.substr(1,i.length-1))&&n.push(t),t.tagName.toLowerCase()===i&&n.push(t)}else n.push(t)}return 0===n.length?null:n},e.wrap=function(t,e){return e=e||document.createElement("div"),t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e),e.appendChild(t)},e.getSiblings=function(t){for(var e=[],i=t.parentNode.firstChild;i;i=i.nextSibling)1===i.nodeType&&i!==t&&e.push(i);return e},e.findAncestor=function(t,e){for(;(t=t.parentElement)&&!t.classList.contains(e););return t},e.debounce=function(t,e,i){var n;return function(){var o=this,s=arguments,r=function(){n=null,i||t.apply(o,s)},a=i&&!n;clearTimeout(n),n=setTimeout(r,e),a&&t.apply(o,s)}},e.getElemDistance=function(t){var e=0;if(t.offsetParent)do e+=t.offsetTop,t=t.offsetParent;while(t);return e>=0?e:0},e.getElementOffset=function(t,e){var i=e;return i>1&&(i=1),i>0&&(i=0),Math.max(t.offsetHeight*i)},e.getAdjacentEl=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t&&e){var n=t.parentNode.parentNode,o=Array.from(n.querySelectorAll(e)),s=o.indexOf(t),r=i>0?1:-1;return o[s+r]}},e.getScrollPosition=function(t){return"bottom"===t?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},e.isInView=function(t,e,i){return this.getScrollPosition(e)>this.getElemDistance(t)+this.getElementOffset(t,i)},e.isScrolledIntoView=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t){var n=void 0;return n=i>0?e.scrollTop+e.offsetHeight>=t.offsetTop+t.offsetHeight:t.offsetTop>=e.scrollTop}},e.stripHTML=function(t){var e=document.createElement("DIV");return e.innerHTML=t,e.textContent||e.innerText||""},e.addAnimation=function(t,e){var i=n(),o=function s(){t.classList.remove(e),t.removeEventListener(i,s,!1)};t.classList.add(e),t.addEventListener(i,o,!1)},e.getRandomNumber=function(t,e){return Math.floor(Math.random()*(e-t)+t)},e.strToEl=function(){var t=document.createElement("div");return function(e){var i;for(t.innerHTML=e,i=t.children[0];t.firstChild;)t.removeChild(t.firstChild);return i}}());e.getWidthOfInput=function(t){var e=arguments.length<=1||void 0===arguments[1]?20:arguments[1],i=t.value||t.placeholder,n=t.offsetWidth;if(i){var s=o(''+i+"");s.style.position="absolute",s.style.top="-9999px",s.style.left="-9999px", -s.style.padding="0",s.style.width="auto",document.body.appendChild(s),s.offsetWidth>e&&s.offsetWidth!=t.offsetWidth&&(n=s.offsetWidth+e/4),document.body.removeChild(s)}return n+"px"}},function(t,e,i){!function(e){"use strict";function i(){console.log.apply(console,arguments)}function n(t,e){var i,n,o,s;for(this.list=t,this.options=e=e||{},i=0,s=["sort","shouldSort","verbose","tokenize"],n=s.length;n>i;i++)o=s[i],this.options[o]=o in e?e[o]:l[o];for(i=0,s=["searchFn","sortFn","keys","getFn","include"],n=s.length;n>i;i++)o=s[i],this.options[o]=e[o]||l[o]}function o(t,e,i){var n,r,a,l,c,u;if(e){if(a=e.indexOf("."),-1!==a?(n=e.slice(0,a),r=e.slice(a+1)):n=e,l=t[n],null!==l&&void 0!==l)if(r||"string"!=typeof l&&"number"!=typeof l)if(s(l))for(c=0,u=l.length;u>c;c++)o(l[c],r,i);else r&&o(l,r,i);else i.push(l)}else i.push(t);return i}function s(t){return"[object Array]"===Object.prototype.toString.call(t)}function r(t,e){e=e||{},this.options=e,this.options.location=e.location||r.defaultOptions.location,this.options.distance="distance"in e?e.distance:r.defaultOptions.distance,this.options.threshold="threshold"in e?e.threshold:r.defaultOptions.threshold,this.options.maxPatternLength=e.maxPatternLength||r.defaultOptions.maxPatternLength,this.pattern=e.caseSensitive?t:t.toLowerCase(),this.patternLen=t.length,this.patternLen<=this.options.maxPatternLength&&(this.matchmask=1<o;o++)this.tokenSearchers.push(new i(n[o],t));this.fullSeacher=new i(e,t)},n.prototype._startSearch=function(){var t,e,i,n,o=this.options,s=o.getFn,r=this.list,a=r.length,l=this.options.keys,c=l.length,u=null;if("string"==typeof r[0])for(i=0;a>i;i++)this._analyze("",r[i],i,i);else for(this._keyMap={},i=0;a>i;i++)for(u=r[i],n=0;c>n;n++){if(t=l[n],"string"!=typeof t){if(e=1-t.weight||1,this._keyMap[t.name]={weight:e},t.weight<=0||t.weight>1)throw new Error("Key weight has to be > 0 and <= 1");t=t.name}else this._keyMap[t]={weight:1};this._analyze(t,s(u,t,[]),u,i)}},n.prototype._analyze=function(t,e,n,o){var r,l,c,u,d,h,p,f,v,m,g,y,b,w,I,E=this.options,O=!1;if(void 0!==e&&null!==e)if(l=[],"string"==typeof e){if(r=e.split(a),E.verbose&&i("---------\nKey:",t),E.verbose&&i("Record:",r),this.options.tokenize){for(c=this.tokenSearchers,u=c.length,w=0;ww;w++)h+=l[w];h/=f,E.verbose&&i("Token score average:",h)}v=this.fullSeacher.search(e),E.verbose&&i("Full text score:",v.score),p=v.score,void 0!==h&&(p=(p+h)/2),E.verbose&&i("Score average:",p),(O||v.isMatch)&&(d=this.resultMap[o],d?d.output.push({key:t,score:p,matchedIndices:v.matchedIndices}):(this.resultMap[o]={item:n,output:[{key:t,score:p,matchedIndices:v.matchedIndices}]},this.results.push(this.resultMap[o])))}else if(s(e))for(w=0;we;e++)r=o[e].score,a=u?u[o[e].key].weight:1,c=r*a,1!==a?l=Math.min(l,c):(n+=c,o[e].nScore=c);1===l?d[t].score=n/s:d[t].score=l,this.options.verbose&&i(d[t])}},n.prototype._sort=function(){var t=this.options;t.shouldSort&&(t.verbose&&i("\n\nSorting...."),this.results.sort(t.sortFn))},n.prototype._format=function(){var t,e,n,o,s,r=this.options,a=r.getFn,l=[],c=this.results,u=r.include;for(r.verbose&&i("\n\nOutput:\n\n",c),o=r.id?function(t){c[t].item=a(c[t].item,r.id,[])[0]}:function(){},s=function(t){var e,i,n,o,s,r=c[t];if(u.length>0){if(e={item:r.item},-1!==u.indexOf("matches"))for(n=r.output,e.matches=[],i=0;ie;e++)o(e),t=s(e),l.push(t);return l},r.defaultOptions={location:0,distance:100,threshold:.6,maxPatternLength:32},r.prototype._calculatePatternAlphabet=function(){var t={},e=0;for(e=0;ek.maxPatternLength){if(y=t.match(new RegExp(this.pattern.replace(a,"|"))),b=!!y)for(I=[],e=0,E=y.length;E>e;e++)O=y[e],I.push([t.indexOf(O),O.length-1]);return{isMatch:b,score:b?.5:1,matchedIndices:I}}for(o=k.location,n=t.length,s=k.threshold,r=t.indexOf(this.pattern,o),w=[],e=0;n>e;e++)w[e]=0;for(-1!=r&&(s=Math.min(this._bitapScore(0,r),s),r=t.lastIndexOf(this.pattern,o+this.patternLen),-1!=r&&(s=Math.min(this._bitapScore(0,r),s))),r=-1,m=1,g=[],u=this.patternLen+n,e=0;el;)this._bitapScore(e,o+c)<=s?l=c:u=c,c=Math.floor((u-l)/2+l);for(u=c,d=Math.max(1,o-c+1),h=Math.min(o+c,n)+this.patternLen,p=Array(h+2),p[h+1]=(1<=d;i--)if(v=this.patternAlphabet[t.charAt(i-1)],v&&(w[i-1]=1),0===e?p[i]=(p[i+1]<<1|1)&v:p[i]=(p[i+1]<<1|1)&v|((f[i+1]|f[i])<<1|1)|f[i+1],p[i]&this.matchmask&&(m=this._bitapScore(e,i-1),s>=m)){if(s=m,r=i-1,g.push(r),!(r>o))break;d=Math.max(1,2*o-r)}if(this._bitapScore(e+1,o)>s)break;f=p}return I=this._getMatchedIndices(w),{isMatch:r>=0,score:0===m?.001:m,matchedIndices:I}},r.prototype._getMatchedIndices=function(t){for(var e,i=[],n=-1,o=-1,s=0,r=r=t.length;r>s;s++)e=t[s],e&&-1===n?n=s:e||-1===n||(o=s-1,i.push([n,o]),n=-1);return t[s-1]&&i.push([n,s-1]),i},t.exports=n}(this)}]); \ No newline at end of file +!function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var i={};return e.m=t,e.c=i,e.p="/assets/scripts/dist/",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t,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 i=0;i1)for(var r=1;r=1){var t=e.store.getOptionsFiltedBySelectable(),i=e.input.value,n=new c.default(t,{keys:["label","value"],shouldSort:!0,include:"score"}),s=n.search(i);e.isSearching=!0,e.store.dispatch((0,r.filterOptions)(s))}},500);s()}else n&&(this.isSearching=!1,this.store.dispatch((0,r.activateOptions)()))}}},{key:"onClick",value:function(t){var e=this,i=this.store.getItemsFilteredByActive(),n=!!t.shiftKey;if("select-multiple"!==this.passedElement.type||this.dropdown.classList.contains(this.options.classNames.activeState)||this.toggleDropdown(),this.containerOuter.contains(t.target))this.input!==document.activeElement&&this.input.focus(),t.target.hasAttribute("data-item")?this.handleClick(i,t.target,n):t.target.hasAttribute("data-option")&&!function(){var i=e.store.getOptionsFilteredByActive(),n=t.target.getAttribute("data-id"),s=i.find(function(t){return t.id===parseInt(n)});s.selected||s.disabled||e.addItem(s.value,s.label,s.id)}();else{var s=i.some(function(t){return t.selected===!0});s&&this.deselectAll(),this.containerOuter.classList.remove(this.options.classNames.activeState),"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:"onMouseOver",value:function(t){this.dropdown&&(t.target===this.dropdown||(0,a.findAncestor)(t.target,this.options.classNames.listDropdown))&&t.target.hasAttribute("data-option")&&this.highlightOption(t.target)}},{key:"onFocus",value:function(t){this.containerOuter.classList.contains(this.options.classNames.activeState)||this.containerOuter.classList.add(this.options.classNames.activeState)}},{key:"onBlur",value:function(t){var e=this.dropdown&&this.dropdown.classList.contains(this.options.classNames.activeState);e||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"),i=e.test(t);return i}},{key:"scrollToOption",value:function(t,e){var i=this;if(t){var n=this.dropdown.offsetHeight,s=t.offsetHeight,o=t.offsetTop+s,r=this.dropdown.scrollTop+n,a=void 0,l=function c(t,e,n){var s=!1,o=void 0,r=void 0,a=4;n>0?(o=(e-i.dropdown.scrollTop)/a,r=o>1?o:1,i.dropdown.scrollTop=i.dropdown.scrollTop+r,i.dropdown.scrollTop1?o:1,i.dropdown.scrollTop=i.dropdown.scrollTop-r,i.dropdown.scrollTop>e&&(s=!0)),s&&requestAnimationFrame(function(t){c(t,e,n)})};e>0?(a=this.dropdown.scrollTop+o-r,requestAnimationFrame(function(t){l(t,a,1)})):(a=t.offsetTop,requestAnimationFrame(function(t){l(t,a,-1)}))}}},{key:"highlightOption",value:function(t){var e=this,i=Array.from(this.dropdown.querySelectorAll("[data-option-selectable]"));if(i.length){var n=Array.from(this.dropdown.querySelectorAll("."+this.options.classNames.highlightedState));if(n.forEach(function(t){t.classList.remove(e.options.classNames.highlightedState)}),t)t.classList.add(this.options.classNames.highlightedState),this.highlightPosition=i.indexOf(t);else{var s=void 0;s=i.length>this.highlightPosition?i[this.highlightPosition]:i[i.length-1],s||(s=i[0]),s.classList.add(this.options.classNames.highlightedState)}}}},{key:"selectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,r.selectItem)(e,!0))}}},{key:"deselectItem",value:function(t){if(t){var e=t.id;this.store.dispatch((0,r.selectItem)(e,!1))}}},{key:"selectAll",value:function(){var t=this,e=this.store.getItems();e.forEach(function(e){t.selectItem(e)})}},{key:"deselectAll",value:function(){var t=this,e=this.store.getItems();e.forEach(function(e){t.deselectItem(e)})}},{key:"addItem",value:function(t,e){var i=arguments.length<=2||void 0===arguments[2]?-1:arguments[2],n=arguments.length<=3||void 0===arguments[3]?this.options.callbackOnAddItem:arguments[3],s=this.store.getItems(),o=t.trim(),l=e||o,c=i||-1;this.options.prependValue&&(o=this.options.prependValue+o.toString()),this.options.appendValue&&(o+=this.options.appendValue.toString());var u=s?s.length+1:1;this.store.dispatch((0,r.addItem)(o,l,u,c)),n&&((0,a.isType)("Function",n)?n(u,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,a.isType)("Object",t))return void console.error("removeItem: No item object was passed to be removed");var i=t.id,n=(t.value,t.optionId);return this.store.dispatch((0,r.removeItem)(i,n)),e?void((0,a.isType)("Function",e)||console.error("callbackOnRemoveItem: Callback is not a function")):void 0}},{key:"removeItemsByValue",value:function(t){return void(t&&(0,a.isType)("String",t)||console.error("removeItemsByValue: No value was passed to be removed"))}},{key:"removeAllItems",value:function(){var t=this,e=this.store.getItemsFilteredByActive();e.forEach(function(e){e.active&&t.removeItem(e)})}},{key:"removeAllSelectedItems",value:function(){var t=this,e=this.store.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],i=this.store.getOptions(),n=i.length+1,s=t.value,o=t.innerHTML,a=t.disabled||t.parentNode.disabled;this.store.dispatch((0,r.addOption)(s,o,n,e,a)),t.selected&&!a&&this.addItem(s,o,n)}},{key:"addGroup",value:function(t,e,i){var n=this,s=Array.from(t.getElementsByTagName("OPTION")),o=e;s?(this.store.dispatch((0,r.addGroup)(t.label,o,!0,t.disabled)),s.forEach(function(t,e){n.addOption(t,o)})):this.store.dispatch((0,r.addGroup)(t.label,t.id,!1,t.disabled))}},{key:"getTemplate",value:function(t){if(t){for(var e=this.options.templates,i=arguments.length,n=Array(i>1?i-1:0),s=1;i>s;s++)n[s-1]=arguments[s];return e[t].apply(e,n)}}},{key:"createTemplates",value:function(){var t=this.options.classNames,e={containerOuter:function(){return(0,a.strToEl)('
    ')},containerInner:function(){return(0,a.strToEl)('
    ')},list:function(){return(0,a.strToEl)('
      ')},input:function(){return(0,a.strToEl)('')},dropdown:function(){return(0,a.strToEl)('
      ')},notice:function(e){return(0,a.strToEl)('
      '+e+"
      ")},option:function(e){return(0,a.strToEl)('\n
      \n '+e.label+"\n
      \n ")},optgroup:function(e){return(0,a.strToEl)('\n
      \n
      '+e.value+"
      \n
      \n ")},item:function(e){return(0,a.strToEl)('\n
      \n '+e.label+"\n
      \n ")}};this.options.templates=(0,a.extend)(this.options.templates,e)}},{key:"generateInput",value:function(){var t=this,e=this.getTemplate("containerOuter"),i=this.getTemplate("containerInner"),n=this.getTemplate("list"),s=this.getTemplate("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,a.wrap)(this.passedElement,i),(0,a.wrap)(i,e),this.options.placeholder&&this.options.placeholderValue&&(s.placeholder=this.options.placeholderValue,s.style.width=(0,a.getWidthOfInput)(s)),this.options.addItems||(s.disabled=!0,e.classList.add(this.options.classNames.disabledState)),e.appendChild(i),i.appendChild(n),i.appendChild(s),"select-multiple"===this.passedElement.type){this.highlightPosition=0;var o=this.getTemplate("dropdown"),r=Array.from(this.passedElement.getElementsByTagName("OPTGROUP"));if(e.appendChild(o),this.dropdown=o,this.isSearching=!1,r.length)r.forEach(function(e,i){var n=0===i;t.addGroup(e,i,n)});else{var l=Array.from(this.passedElement.options);l.forEach(function(e){t.addOption(e)})}}else"text"===this.passedElement.type&&this.presetItems.forEach(function(e){t.addItem(e)});this.containerOuter=e,this.containerInner=i,this.input=s,this.list=n}},{key:"renderGroups",value:function(t,e,i){var n=this;t.forEach(function(t,s){var o=e.filter(function(e){return e.groupId===t.id});o.length>=1&&!function(){var e=n.getTemplate("optgroup",t);o.forEach(function(t,i){var s=n.getTemplate("option",t);e.appendChild(s)}),i.appendChild(e)}()})}},{key:"renderOptions",value:function(t,e){var i=this;t.forEach(function(t,n){var s=i.getTemplate("option",t);e.appendChild(s)})}},{key:"renderItems",value:function(t,e){var i=this,n=this.store.getItemsReducedToValues();this.passedElement.value=n.join(this.options.delimiter),this.list.innerHTML="",t.forEach(function(t){var n=i.getTemplate("item",t);e.appendChild(n)}),this.list.appendChild(e)}},{key:"render",value:function(){if(this.currentState=this.store.getState(),this.currentState!==this.prevState){if((this.currentState.options!==this.prevState.options||this.currentState.groups!==this.prevState.groups)&&"select-multiple"===this.passedElement.type){var t=this.store.getGroupsFilteredByActive(),e=this.store.getOptionsFilteredByActive(),i=document.createDocumentFragment();if(this.dropdown.innerHTML="",t.length>=1&&this.isSearching!==!0?this.renderGroups(t,e,i):e.length>=1&&this.renderOptions(e,i),i.children.length)this.dropdown.appendChild(i),this.highlightOption();else{var n=this.getTemplate("notice","No options to select");this.dropdown.appendChild(n)}}if(this.currentState.items!==this.prevState.items){var s=this.store.getItemsFilteredByActive();if(s){var o=document.createDocumentFragment();this.renderItems(s,o)}}this.prevState=this.currentState}}},{key:"addEventListeners",value:function(){document.addEventListener("keyup",this.onKeyUp),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("click",this.onClick),document.addEventListener("paste",this.onPaste),document.addEventListener("mouseover",this.onMouseOver),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),document.removeEventListener("mouseover",this.onMouseOver),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.createTemplates(),this.generateInput(),this.store.subscribe(this.render),this.render(),this.addEventListeners(),t&&((0,a.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=h},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.addItem=function(t,e,i,n){return{type:"ADD_ITEM",value:t,label:e,id:i,optionId:n}},e.removeItem=function(t,e){return{type:"REMOVE_ITEM",id:t,optionId:e}},e.selectItem=function(t,e){return{type:"SELECT_ITEM",id:t,selected:e}},e.addOption=function(t,e,i,n,s){return{type:"ADD_OPTION",value:t,label:e,id:i,groupId:n,disabled:s}},e.filterOptions=function(t){return{type:"FILTER_OPTIONS",results:t}},e.activateOptions=function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];return{type:"ACTIVATE_OPTIONS",active:t}},e.addGroup=function(t,e,i,n){return{type:"ADD_GROUP",value:t,id:e,active:i,disabled:n}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=(e.hasClass=function(t,e){return new RegExp(" "+e+" ").test(" "+t.className+" ")},e.capitalise=function(t){return t.replace(/\w\S*/g,function(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()})},e.isType=function(t,e){var i=Object.prototype.toString.call(e).slice(8,-1);return void 0!==e&&null!==e&&i===t}),n=(e.extend=function o(){for(var t={},e=!1,n=arguments.length,s=function(n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e&&i("Object",n[s])?t[s]=o(!0,t[s],n[s]):t[s]=n[s])},r=0;n>r;r++){var a=arguments[r];i("Object",a)?s(a):console.error("Custom options must be an object")}return t},e.whichTransitionEvent=function(){var t,e=document.createElement("fakeelement"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in i)if(void 0!==e.style[t])return i[t]},e.whichAnimationEvent=function(){var t,e=document.createElement("fakeelement"),i={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in i)if(void 0!==e.style[t])return i[t]}),s=(e.getParentsUntil=function(t,e,i){for(var n=[];t&&t!==document;t=t.parentNode){if(e){var s=e.charAt(0);if("."===s&&t.classList.contains(e.substr(1)))break;if("#"===s&&t.id===e.substr(1))break;if("["===s&&t.hasAttribute(e.substr(1,e.length-1)))break;if(t.tagName.toLowerCase()===e)break}if(i){var o=i.charAt(0);"."===o&&t.classList.contains(i.substr(1))&&n.push(t),"#"===o&&t.id===i.substr(1)&&n.push(t),"["===o&&t.hasAttribute(i.substr(1,i.length-1))&&n.push(t),t.tagName.toLowerCase()===i&&n.push(t)}else n.push(t)}return 0===n.length?null:n},e.wrap=function(t,e){return e=e||document.createElement("div"),t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e),e.appendChild(t)},e.getSiblings=function(t){for(var e=[],i=t.parentNode.firstChild;i;i=i.nextSibling)1===i.nodeType&&i!==t&&e.push(i);return e},e.findAncestor=function(t,e){for(;(t=t.parentElement)&&!t.classList.contains(e););return t},e.debounce=function(t,e,i){var n;return function(){var s=this,o=arguments,r=function(){n=null,i||t.apply(s,o)},a=i&&!n;clearTimeout(n),n=setTimeout(r,e),a&&t.apply(s,o)}},e.getElemDistance=function(t){var e=0;if(t.offsetParent)do e+=t.offsetTop,t=t.offsetParent;while(t);return e>=0?e:0},e.getElementOffset=function(t,e){var i=e;return i>1&&(i=1),i>0&&(i=0),Math.max(t.offsetHeight*i)},e.getAdjacentEl=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t&&e){var n=t.parentNode.parentNode,s=Array.from(n.querySelectorAll(e)),o=s.indexOf(t),r=i>0?1:-1;return s[o+r]}},e.getScrollPosition=function(t){return"bottom"===t?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},e.isInView=function(t,e,i){return this.getScrollPosition(e)>this.getElemDistance(t)+this.getElementOffset(t,i)},e.isScrolledIntoView=function(t,e){var i=arguments.length<=2||void 0===arguments[2]?1:arguments[2];if(t){var n=void 0;return n=i>0?e.scrollTop+e.offsetHeight>=t.offsetTop+t.offsetHeight:t.offsetTop>=e.scrollTop}},e.stripHTML=function(t){var e=document.createElement("DIV");return e.innerHTML=t,e.textContent||e.innerText||""},e.addAnimation=function(t,e){var i=n(),s=function o(){t.classList.remove(e),t.removeEventListener(i,o,!1)};t.classList.add(e),t.addEventListener(i,s,!1)},e.getRandomNumber=function(t,e){return Math.floor(Math.random()*(e-t)+t)},e.strToEl=function(){var t=document.createElement("div");return function(e){var i;for(t.innerHTML=e,i=t.children[0];t.firstChild;)t.removeChild(t.firstChild);return i}}());e.getWidthOfInput=function(t){var e=arguments.length<=1||void 0===arguments[1]?20:arguments[1],i=t.value||t.placeholder,n=t.offsetWidth;if(i){var o=s(''+i+"");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&&(n=o.offsetWidth+e/4),document.body.removeChild(o)}return n+"px"}},function(t,e,i){!function(e){"use strict";function i(){console.log.apply(console,arguments)}function n(t,e){var i,n,s,o;for(this.list=t,this.options=e=e||{},i=0,o=["sort","shouldSort","verbose","tokenize"],n=o.length;n>i;i++)s=o[i],this.options[s]=s in e?e[s]:l[s];for(i=0,o=["searchFn","sortFn","keys","getFn","include"],n=o.length;n>i;i++)s=o[i],this.options[s]=e[s]||l[s]}function s(t,e,i){var n,r,a,l,c,u;if(e){if(a=e.indexOf("."),-1!==a?(n=e.slice(0,a),r=e.slice(a+1)):n=e,l=t[n],null!==l&&void 0!==l)if(r||"string"!=typeof l&&"number"!=typeof l)if(o(l))for(c=0,u=l.length;u>c;c++)s(l[c],r,i);else r&&s(l,r,i);else i.push(l)}else i.push(t);return i}function o(t){return"[object Array]"===Object.prototype.toString.call(t)}function r(t,e){e=e||{},this.options=e,this.options.location=e.location||r.defaultOptions.location,this.options.distance="distance"in e?e.distance:r.defaultOptions.distance,this.options.threshold="threshold"in e?e.threshold:r.defaultOptions.threshold,this.options.maxPatternLength=e.maxPatternLength||r.defaultOptions.maxPatternLength,this.pattern=e.caseSensitive?t:t.toLowerCase(),this.patternLen=t.length,this.patternLen<=this.options.maxPatternLength&&(this.matchmask=1<s;s++)this.tokenSearchers.push(new i(n[s],t));this.fullSeacher=new i(e,t)},n.prototype._startSearch=function(){var t,e,i,n,s=this.options,o=s.getFn,r=this.list,a=r.length,l=this.options.keys,c=l.length,u=null;if("string"==typeof r[0])for(i=0;a>i;i++)this._analyze("",r[i],i,i);else for(this._keyMap={},i=0;a>i;i++)for(u=r[i],n=0;c>n;n++){if(t=l[n],"string"!=typeof t){if(e=1-t.weight||1,this._keyMap[t.name]={weight:e},t.weight<=0||t.weight>1)throw new Error("Key weight has to be > 0 and <= 1");t=t.name}else this._keyMap[t]={weight:1};this._analyze(t,o(u,t,[]),u,i)}},n.prototype._analyze=function(t,e,n,s){var r,l,c,u,d,h,p,f,v,m,g,y,b,w,I,E=this.options,O=!1;if(void 0!==e&&null!==e)if(l=[],"string"==typeof e){if(r=e.split(a),E.verbose&&i("---------\nKey:",t),E.verbose&&i("Record:",r),this.options.tokenize){for(c=this.tokenSearchers,u=c.length,w=0;ww;w++)h+=l[w];h/=f,E.verbose&&i("Token score average:",h)}v=this.fullSeacher.search(e),E.verbose&&i("Full text score:",v.score),p=v.score,void 0!==h&&(p=(p+h)/2),E.verbose&&i("Score average:",p),(O||v.isMatch)&&(d=this.resultMap[s],d?d.output.push({key:t,score:p,matchedIndices:v.matchedIndices}):(this.resultMap[s]={item:n,output:[{key:t,score:p,matchedIndices:v.matchedIndices}]},this.results.push(this.resultMap[s])))}else if(o(e))for(w=0;we;e++)r=s[e].score,a=u?u[s[e].key].weight:1,c=r*a,1!==a?l=Math.min(l,c):(n+=c,s[e].nScore=c);1===l?d[t].score=n/o:d[t].score=l,this.options.verbose&&i(d[t])}},n.prototype._sort=function(){var t=this.options;t.shouldSort&&(t.verbose&&i("\n\nSorting...."),this.results.sort(t.sortFn))},n.prototype._format=function(){var t,e,n,s,o,r=this.options,a=r.getFn,l=[],c=this.results,u=r.include;for(r.verbose&&i("\n\nOutput:\n\n",c),s=r.id?function(t){c[t].item=a(c[t].item,r.id,[])[0]}:function(){},o=function(t){var e,i,n,s,o,r=c[t];if(u.length>0){if(e={item:r.item},-1!==u.indexOf("matches"))for(n=r.output,e.matches=[],i=0;ie;e++)s(e),t=o(e),l.push(t);return l},r.defaultOptions={location:0,distance:100,threshold:.6,maxPatternLength:32},r.prototype._calculatePatternAlphabet=function(){var t={},e=0;for(e=0;eS.maxPatternLength){if(y=t.match(new RegExp(this.pattern.replace(a,"|"))),b=!!y)for(I=[],e=0,E=y.length;E>e;e++)O=y[e],I.push([t.indexOf(O),O.length-1]);return{isMatch:b,score:b?.5:1,matchedIndices:I}}for(s=S.location,n=t.length,o=S.threshold,r=t.indexOf(this.pattern,s),w=[],e=0;n>e;e++)w[e]=0;for(-1!=r&&(o=Math.min(this._bitapScore(0,r),o),r=t.lastIndexOf(this.pattern,s+this.patternLen),-1!=r&&(o=Math.min(this._bitapScore(0,r),o))),r=-1,m=1,g=[],u=this.patternLen+n,e=0;el;)this._bitapScore(e,s+c)<=o?l=c:u=c,c=Math.floor((u-l)/2+l);for(u=c,d=Math.max(1,s-c+1),h=Math.min(s+c,n)+this.patternLen,p=Array(h+2),p[h+1]=(1<=d;i--)if(v=this.patternAlphabet[t.charAt(i-1)],v&&(w[i-1]=1),0===e?p[i]=(p[i+1]<<1|1)&v:p[i]=(p[i+1]<<1|1)&v|((f[i+1]|f[i])<<1|1)|f[i+1],p[i]&this.matchmask&&(m=this._bitapScore(e,i-1),o>=m)){if(o=m,r=i-1,g.push(r),!(r>s))break;d=Math.max(1,2*s-r)}if(this._bitapScore(e+1,s)>o)break;f=p}return I=this._getMatchedIndices(w),{isMatch:r>=0,score:0===m?.001:m,matchedIndices:I}},r.prototype._getMatchedIndices=function(t){for(var e,i=[],n=-1,s=-1,o=0,r=r=t.length;r>o;o++)e=t[o],e&&-1===n?n=o:e||-1===n||(s=o-1,i.push([n,s]),n=-1);return t[o-1]&&i.push([n,o-1]),i},t.exports=n}(this)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Store=void 0;var o=function(){function t(t,e){for(var i=0;ii;i++)e[i]=arguments[i];return function(t){return function(i,n,s){var r=t(i,n,s),l=r.dispatch,c=[],u={getState:r.getState,dispatch:function(t){return l(t)}};return c=e.map(function(t){return t(u)}),l=a.default.apply(void 0,c)(r.dispatch),o({},r,{dispatch:l})}}}var o=Object.assign||function(t){for(var e=1;ei;i++)e[i]=arguments[i];return function(){if(0===e.length)return arguments.length<=0?void 0:arguments[0];var t=e[e.length-1],i=e.slice(0,-1);return i.reduceRight(function(t,e){return e(t)},t.apply(void 0,arguments))}}e.__esModule=!0,e.default=i},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var s=i(6),o=i(18),r=n(o),a=i(19),l=n(a),c=i(20),u=n(c),d=(0,s.combineReducers)({items:r.default,groups:l.default,options:u.default});e.default=d},function(t,e){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e-1?t.map(function(t){return t.id===parseInt(e.optionId)&&(t.selected=!0),t}):t;case"REMOVE_ITEM":return e.optionId>-1?t.map(function(t){return t.id===parseInt(e.optionId)&&(t.selected=!1),t}):t;case"FILTER_OPTIONS":var n=e.results,s=t.map(function(t,e){return t.active=n.some(function(e){return e.item.id===t.id?(t.score=e.score,!0):void 0}),t}).sort(function(t,e){return t.score-e.score});return s;case"ACTIVATE_OPTIONS":return t.map(function(t){return t.active=e.active,t});default:return t}};e.default=n}]); \ No newline at end of file diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index c4159cb..0833900 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -1,10 +1,9 @@ 'use strict'; -import { createStore } from 'redux'; -import rootReducer from './reducers/index.js'; import { addItem, removeItem, selectItem, addOption, filterOptions, activateOptions, addGroup } from './actions/index'; import { isScrolledIntoView, getAdjacentEl, findAncestor, wrap, isType, strToEl, extend, getWidthOfInput, debounce } from './lib/utils.js'; import Fuse from 'fuse.js'; +import Store from './store.js'; /** * Choices @@ -78,14 +77,15 @@ export class Choices { callbackOnAddItem: function() {} }; - // Initial instance state - this.initialised = false; - // Merge options with user options this.options = extend(defaultOptions, userOptions); // Create data store - this.store = createStore(rootReducer); + this.store = new Store(this.render); + + // State tracking + this.currentState = {}; + this.prevState = {}; // Retrieve triggering element (i.e. element with 'data-choice' trigger) this.passedElement = isType('String', element) ? document.querySelector(element) : element; @@ -227,8 +227,8 @@ export class Choices { const upKey = 38; const downKey = 40; - const activeItems = this.getItemsFilteredByActive(); - const activeOptions = this.getOptionsFilteredByActive(); + const activeItems = this.store.getItemsFilteredByActive(); + const activeOptions = this.store.getOptionsFilteredByActive(); const hasFocussedInput = this.input === document.activeElement; const hasActiveDropdown = this.dropdown && this.dropdown.classList.contains(this.options.classNames.activeState); @@ -326,23 +326,27 @@ export class Choices { if(this.passedElement.type === 'select-multiple' && this.options.allowSearch) { if(this.input === document.activeElement) { - const options = this.getOptions(); + const options = this.store.getOptions(); const hasUnactiveOptions = options.some((option) => { return option.active !== true; }); // Check that have a value to search - if(this.input.value) { + if(this.input.value && options.length) { const handleFilter = debounce(() => { // Ensure value *still* has a value after 500 delay if(this.input.value && this.input.value.length >= 1) { - const options = this.getOptionsFiltedBySelectable(); - const fuse = new Fuse(options, { + const haystack = this.store.getOptionsFiltedBySelectable(); + const needle = this.input.value; + + const fuse = new Fuse(haystack, { keys: ['label', 'value'], shouldSort: true, include: 'score', }); - const results = fuse.search(this.input.value); + + const results = fuse.search(needle); + this.isSearching = true; this.store.dispatch(filterOptions(results)); } @@ -355,7 +359,7 @@ export class Choices { } } } - } q + } /** @@ -364,7 +368,7 @@ export class Choices { * @return */ onClick(e) { - const activeItems = this.getItemsFilteredByActive(); + const activeItems = this.store.getItemsFilteredByActive(); const hasShiftKey = e.shiftKey ? true : false; if(this.passedElement.type === 'select-multiple' && !this.dropdown.classList.contains(this.options.classNames.activeState)) { @@ -383,7 +387,7 @@ export class Choices { this.handleClick(activeItems, e.target, hasShiftKey); } else if(e.target.hasAttribute('data-option')) { // If we are clicking on an option - const options = this.getOptionsFilteredByActive(); + const options = this.store.getOptionsFilteredByActive(); const id = e.target.getAttribute('data-id'); const option = options.find((option) => { return option.id === parseInt(id); @@ -611,7 +615,7 @@ export class Choices { * @return */ selectAll() { - const items = this.getItems(); + const items = this.store.getItems(); items.forEach((item) => { this.selectItem(item); }); @@ -622,7 +626,7 @@ export class Choices { * @return */ deselectAll() { - const items = this.getItems(); + const items = this.store.getItems(); items.forEach((item) => { this.deselectItem(item); }); @@ -633,6 +637,7 @@ export class Choices { * @param {String} value Value to add to store */ addItem(value, label, optionId = -1, callback = this.options.callbackOnAddItem) { + const items = this.store.getItems(); let passedValue = value.trim(); let passedLabel = label || passedValue; let passedOptionId = optionId || -1; @@ -648,7 +653,7 @@ export class Choices { } // Generate unique id - const id = this.store.getState().items.length + 1; + const id = items ? items.length + 1 : 1; this.store.dispatch(addItem(passedValue, passedLabel, id, passedOptionId)); @@ -680,11 +685,8 @@ export class Choices { // Run callback if(callback){ - if(isType('Function', callback)) { - callback(value); - } else { - console.error('callbackOnRemoveItem: Callback is not a function'); - } + if(!isType('Function', callback)) console.error('callbackOnRemoveItem: Callback is not a function'); return; + callback(value); } } @@ -694,11 +696,9 @@ export class Choices { * @return */ removeItemsByValue(value) { - if(!value || !isType('String', value)) { - console.error('removeItemsByValue: No value was passed to be removed'); - } + if(!value || !isType('String', value)) console.error('removeItemsByValue: No value was passed to be removed'); return; - const items = this.getItemsFilteredByActive(); + const items = this.store.getItemsFilteredByActive(); items.forEach((item) => { if(item.value === value) { @@ -714,7 +714,7 @@ export class Choices { * @return */ removeAllItems() { - const items = this.getItemsFilteredByActive(); + const items = this.store.getItemsFilteredByActive(); items.forEach((item) => { if(item.active) { @@ -729,7 +729,7 @@ export class Choices { * @return */ removeAllSelectedItems() { - const items = this.getItemsFilteredByActive(); + const items = this.store.getItemsFilteredByActive(); items.forEach((item) => { if(item.selected && item.active) { @@ -793,8 +793,8 @@ export class Choices { */ addOption(option, groupId = -1) { // Generate unique id - const state = this.store.getState(); - const id = state.options.length + 1; + const options = this.store.getOptions(); + const id = options.length + 1; const value = option.value; const label = option.innerHTML; const isDisabled = option.disabled || option.parentNode.disabled; @@ -828,105 +828,63 @@ export class Choices { } } - /** - * Get items from store - * @return {Array} Item objects - */ - getItems() { - const state = this.store.getState(); - return state.items; + getTemplate(template, ...args) { + if(!template) return; + const templates = this.options.templates; + return templates[template](...args); } /** - * Get active items from store - * @return {Array} Item objects + * Create HTML element based on type and arguments + * @param {String} template Template to create + * @param {...} args Data + * @return {HTMLElement} */ - getItemsFilteredByActive() { - const items = this.getItems(); + createTemplates() { + const classNames = this.options.classNames; + const 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(` +
        + ${ data.label } +
        + `); + }, + optgroup: (data) => { + return strToEl(` +
        +
        ${ data.value }
        +
        + `); + }, + item: (data) => { + return strToEl(` +
        + ${ data.label } +
        + `); + }, + }; - const valueArray = items.filter((item) => { - return item.active === true; - }, []); - - return valueArray; - } - - /** - * Get items from store reduced to just their values - * @return {Array} Item objects - */ - getItemsReducedToValues() { - const items = this.getItems(); - - const valueArray = items.reduce((prev, current) => { - prev.push(current.value); - return prev; - }, []); - - return valueArray; - } - - /** - * 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) => { - return option.active === true && option.selected !== true; - },[]); - - return valueArray; - } - - /** - * Get selectable options from store - * @return {Array} Option objects - */ - getOptionsFiltedBySelectable() { - const options = this.getOptions(); - const valueArray = options.filter((option) => { - return option.selected === false && option.disabled !== true; - },[]); - - 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(); - - const valueArray = groups.filter((group) => { - const isActive = group.active === true && group.disabled === false; - const hasActiveOptions = options.some((option) => { - return option.active === true && option.disabled === false; - }); - return isActive && hasActiveOptions ? true : false; - },[]); - - return valueArray; + this.options.templates = extend(this.options.templates, templates); } /** @@ -1000,156 +958,107 @@ export class Choices { this.list = list; } + renderGroups(groups, options, fragment) { + groups.forEach((group, i) => { + // Grab options that are children of this group + const groupOptions = options.filter((option) => { + return option.groupId === group.id; + }); + + if(groupOptions.length >= 1) { + const dropdownGroup = this.getTemplate('optgroup', group); + + groupOptions.forEach((option, j) => { + const dropdownItem = this.getTemplate('option', option); + dropdownGroup.appendChild(dropdownItem); + }); + + fragment.appendChild(dropdownGroup); + } + }); + } + + renderOptions(options, fragment) { + options.forEach((option, i) => { + const dropdownItem = this.getTemplate('option', option); + fragment.appendChild(dropdownItem); + }); + } + + renderItems(items, fragment) { + // Simplify store data to just values + const itemsFiltered = this.store.getItemsReducedToValues(); + + // Assign hidden input array of values + this.passedElement.value = itemsFiltered.join(this.options.delimiter); + + // Clear list + this.list.innerHTML = ''; + + // Add each list item to list + items.forEach((item) => { + // Create new list element + const listItem = this.getTemplate('item', item); + + // Append it to list + fragment.appendChild(listItem); + }); + + this.list.appendChild(fragment); + } + /** * Render DOM with values * @return */ - render(callback = this.options.callbackOnRender) { - const classNames = this.options.classNames; - const activeItems = this.getItemsFilteredByActive(); + render() { + this.currentState = this.store.getState(); + + if(this.currentState !== this.prevState) { + // OPTIONS + if((this.currentState.options !== this.prevState.options || this.currentState.groups !== this.prevState.groups) && this.passedElement.type === 'select-multiple') { + // Get active groups/options + const activeGroups = this.store.getGroupsFilteredByActive(); + const activeOptions = this.store.getOptionsFilteredByActive(); - // OPTIONS - if(this.passedElement.type === 'select-multiple') { - const activeOptions = this.getOptionsFilteredByActive(); - const activeGroups = this.getGroupsFilteredByActive(); + // Create a fragment to store our list items (so we don't have to update the DOM for each item) + const optionListFragment = document.createDocumentFragment(); - // Create a fragment to store our list items (so we don't have to update the DOM for each item) - const optionListFragment = document.createDocumentFragment(); + // Clear options + this.dropdown.innerHTML = ''; - // If we have grouped options - if(activeGroups.length >= 1 && this.isSearching !== true) { - activeGroups.forEach((group, i) => { - // Grab options that are children of this group - const groupOptions = activeOptions.filter((option) => { - return option.groupId === group.id; - }); + // If we have grouped options + if(activeGroups.length >= 1 && this.isSearching !== true) { + this.renderGroups(activeGroups, activeOptions, optionListFragment); + } else if(activeOptions.length >= 1) { + this.renderOptions(activeOptions, optionListFragment); + } - if(groupOptions.length >= 1) { - const dropdownGroup = this.getTemplate('optgroup', group); - - groupOptions.forEach((option, j) => { - const dropdownItem = this.getTemplate('option', option); - dropdownGroup.appendChild(dropdownItem); - }); - - optionListFragment.appendChild(dropdownGroup); - } - }); - } else if(activeOptions.length >= 1) { - activeOptions.forEach((option, i) => { - const dropdownItem = this.getTemplate('option', option); - optionListFragment.appendChild(dropdownItem); - }); + // If we actually have anything to add to our dropdown + if(optionListFragment.children.length) { + this.dropdown.appendChild(optionListFragment); + this.highlightOption(); + } else { + // If dropdown is empty, show a no content notice + const dropdownItem = this.getTemplate('notice', 'No options to select'); + this.dropdown.appendChild(dropdownItem); + } } - - // Clear options - this.dropdown.innerHTML = ''; - - if(optionListFragment.children.length) { - this.dropdown.appendChild(optionListFragment); - this.highlightOption(); - } else { - // If dropdown is empty, show a no content notice - const dropdownItem = this.getTemplate('notice', 'No options to select'); - this.dropdown.appendChild(dropdownItem); - } - } - - // ITEMS - if(activeItems) { - // Simplify store data to just values - const itemsFiltered = this.getItemsReducedToValues(); - - // Assign hidden input array of values - this.passedElement.value = itemsFiltered.join(this.options.delimiter); - - // Clear list - this.list.innerHTML = ''; - - // Create a fragment to store our list items (so we don't have to update the DOM for each item) - const itemListFragment = document.createDocumentFragment(); - // Add each list item to list - activeItems.forEach((item) => { - // Create new list element - const listItem = this.getTemplate('item', item); - - // Append it to list - itemListFragment.appendChild(listItem); - }); - - this.list.appendChild(itemListFragment); - } - - // Run callback if it is a function - if(callback){ - if(isType('Function', callback)) { - callback(activeItems); - } else { - console.error('callbackOnRender: Callback is not a function'); + // ITEMS + if(this.currentState.items !== this.prevState.items) { + const activeItems = this.store.getItemsFilteredByActive(); + if(activeItems) { + // Create a fragment to store our list items (so we don't have to update the DOM for each item) + const itemListFragment = document.createDocumentFragment(); + this.renderItems(activeItems, itemListFragment); + } } + + this.prevState = this.currentState; } } - getTemplate(template, ...args) { - if(!template) return; - const templates = this.options.templates; - return templates[template](...args); - } - - /** - * Create HTML element based on type and arguments - * @param {String} template Template to create - * @param {...} args Data - * @return {HTMLElement} - */ - createTemplates() { - const classNames = this.options.classNames; - const 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(` -
          - ${ data.label } -
          - `); - }, - optgroup: (data) => { - return strToEl(` -
          -
          ${ data.value }
          -
          - `); - }, - item: (data) => { - return strToEl(` -
          - ${ data.label } -
          - `); - }, - }; - - this.options.templates = extend(this.options.templates, templates); - } - /** * Trigger event listeners * @return @@ -1185,15 +1094,12 @@ export class Choices { * @return */ init(callback = this.options.callbackOnInit) { - this.initialised = true; - // Create required elements this.createTemplates(); // Generate input markup this.generateInput(); - // Subscribe to store this.store.subscribe(this.render); // Render any items diff --git a/assets/scripts/src/store.js b/assets/scripts/src/store.js new file mode 100644 index 0000000..a8b397d --- /dev/null +++ b/assets/scripts/src/store.js @@ -0,0 +1,143 @@ +'use strict'; + +import { createStore } from 'redux'; +import rootReducer from './reducers/index.js'; + + +export class Store { + constructor() { + this.store = createStore( + rootReducer, + window.devToolsExtension ? window.devToolsExtension() : undefined + ); + } + + /** + * Get store object (wrapping Redux method) + * @return {Object} State + */ + getState() { + return this.store.getState(); + } + + /** + * Dispatch event to store (wrapped Redux method) + * @param {Function} action Action function to trigger + * @return + */ + dispatch(action) { + this.store.dispatch(action); + } + + /** + * Subscribe store to function call (wrapped Redux method) + * @param {Function} onChange Function to trigger when state changes + * @return + */ + subscribe(onChange) { + this.store.subscribe(onChange); + } + + /** + * Get items from store + * @return {Array} Item objects + */ + getItems() { + const state = this.store.getState(); + return state.items; + } + + /** + * Get active items from store + * @return {Array} Item objects + */ + getItemsFilteredByActive() { + const items = this.getItems(); + + const values = items.filter((item) => { + return item.active === true; + }, []); + + return values; + } + + /** + * Get items from store reduced to just their values + * @return {Array} Item objects + */ + getItemsReducedToValues() { + const items = this.getItems(); + + const values = items.reduce((prev, current) => { + prev.push(current.value); + return prev; + }, []); + + return values; + } + + /** + * 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 values = options.filter((option) => { + return option.active === true && option.selected !== true; + },[]); + + return values; + } + + /** + * Get selectable options from store + * @return {Array} Option objects + */ + getOptionsFiltedBySelectable() { + const options = this.getOptions(); + const values = options.filter((option) => { + return option.selected === false && option.disabled !== true; + },[]); + + return values; + } + + /** + * 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(); + + const values = groups.filter((group) => { + const isActive = group.active === true && group.disabled === false; + const hasActiveOptions = options.some((option) => { + return option.active === true && option.disabled === false; + }); + return isActive && hasActiveOptions ? true : false; + },[]); + + return values; + } +}; + +module.exports = Store; \ No newline at end of file diff --git a/assets/styles/css/choices.css b/assets/styles/css/choices.css index 05d9a0d..60bd122 100644 --- a/assets/styles/css/choices.css +++ b/assets/styles/css/choices.css @@ -98,24 +98,15 @@ h1, h2, h3, h4, h5, h6 { opacity: .5; } .choices__list--dropdown .choices__item.is-selected:hover { background-color: #FFFFFF; } - .choices__list--dropdown .choices__item--selectable { - -webkit-transition: background-color .15s ease-in-out; - transition: background-color .15s ease-in-out; } - .choices__list--dropdown .choices__item--selectable:after { - content: "Press to select"; - font-size: 12px; - opacity: 0; - float: right; - -webkit-transition: opacity .15s ease-in-out; - transition: opacity .15s ease-in-out; } - .choices__list--dropdown .choices__item--selectable.is-highlighted { - background-color: #f2f2f2; - -webkit-transition: background-color .15s ease-in-out; - transition: background-color .15s ease-in-out; } - .choices__list--dropdown .choices__item--selectable.is-highlighted:after { - opacity: .5; - -webkit-transition: opacity .15s ease-in-out; - transition: opacity .15s ease-in-out; } + .choices__list--dropdown .choices__item--selectable:after { + content: "Press to select"; + font-size: 12px; + opacity: 0; + float: right; } + .choices__list--dropdown .choices__item--selectable.is-highlighted { + background-color: #f2f2f2; } + .choices__list--dropdown .choices__item--selectable.is-highlighted:after { + opacity: .5; } .choices__list--dropdown.is-active { display: block; } .choices__list--dropdown.is-flipped { diff --git a/assets/styles/css/choices.min.css b/assets/styles/css/choices.min.css index 5de7a01..9569c89 100644 --- a/assets/styles/css/choices.min.css +++ b/assets/styles/css/choices.min.css @@ -1 +1 @@ -*,:after,:before{box-sizing:border-box}body,html{margin:0;height:100%;widows:100%}html{font-size:62.5%}body{background-color:#333;font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:1.6rem;color:#fff}label{display:block;margin-bottom:.8rem;font-size:1.4rem;font-weight:500}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:1.2rem;font-weight:500}.container{display:block;margin:auto;max-width:35em;padding:2.4rem}.section{background-color:#fff;padding:2.4rem;color:#333}.choices{margin-bottom:2.4rem;position:relative}.choices__inner{background-color:#f9f9f9;padding:.75rem .75rem .375rem;border:1px solid #ddd;border-radius:.25rem;font-size:1.4rem;cursor:text}.is-active .choices__inner{border-color:#b7b7b7}.choices__inner:focus{outline:1px solid #00bcd4;outline-offset:-1px}.choices__list{margin:0;padding-left:0;list-style-type:none}.choices__list--items{display:inline}.choices__list--items .choices__item{display:inline-block;border-radius:2rem;padding:.4rem 1rem;font-size:1.2rem;margin-right:.375rem;margin-bottom:.375rem;background-color:#00bcd4;border:1px solid #00b1c7;color:#fff;word-break:break-all}.choices__list--items .choices__item.is-selected{background-color:#00a5bb}.choices__list--dropdown{display:none;z-index:1;position:absolute;width:100%;background-color:#fff;border:1px solid #ddd;top:100%;margin-top:-1px;border-bottom-left-radius:.25rem;border-bottom-right-radius:.25rem;max-height:300px;overflow:auto;will-change:scroll-position}.is-active .choices__list--dropdown{border-color:#b7b7b7}.choices__list--dropdown .choices__item{padding:1rem;font-size:1.4rem}.choices__list--dropdown .choices__item.is-selected{opacity:.5}.choices__list--dropdown .choices__item.is-selected:hover{background-color:#fff}.choices__list--dropdown .choices__item--selectable,.choices__list--dropdown .choices__item--selectable.is-highlighted{-webkit-transition:background-color .15s ease-in-out;transition:background-color .15s ease-in-out}.choices__list--dropdown .choices__item--selectable:after{content:"Press to select";font-size:12px;opacity:0;float:right;-webkit-transition:opacity .15s ease-in-out;transition:opacity .15s ease-in-out}.choices__list--dropdown .choices__item--selectable.is-highlighted{background-color:#f2f2f2}.choices__list--dropdown .choices__item--selectable.is-highlighted:after{opacity:.5;-webkit-transition:opacity .15s ease-in-out;transition:opacity .15s ease-in-out}.choices__list--dropdown.is-active{display:block}.choices__list--dropdown.is-flipped{top:auto;bottom:100%;margin-top:0;margin-bottom:-1px;border-bottom-left-radius:0;border-bottom-right-radius:0;border-top-left-radius:.25rem;border-top-right-radius:.25rem}.choices__item{cursor:default}.choices__item--selectable{cursor:pointer}.choices__item--disabled{cursor:not-allowed;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:.5}.choices__group .choices__heading{font-weight:600;font-size:1.2rem;padding:1rem;border-bottom:1px solid #eaeaea;color:gray}.choices__input{background-color:#f9f9f9;font-size:1.4rem;padding:0;margin-bottom:.5rem;display:inline-block;vertical-align:baseline;border:0;border-radius:0;max-width:100%;padding:.4rem 0 .4rem .2rem}.choices__input:focus{outline:0} \ No newline at end of file +*,:after,:before{box-sizing:border-box}body,html{margin:0;height:100%;widows:100%}html{font-size:62.5%}body{background-color:#333;font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:1.6rem;color:#fff}label{display:block;margin-bottom:.8rem;font-size:1.4rem;font-weight:500}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:1.2rem;font-weight:500}.container{display:block;margin:auto;max-width:35em;padding:2.4rem}.section{background-color:#fff;padding:2.4rem;color:#333}.choices{margin-bottom:2.4rem;position:relative}.choices__inner{background-color:#f9f9f9;padding:.75rem .75rem .375rem;border:1px solid #ddd;border-radius:.25rem;font-size:1.4rem;cursor:text}.is-active .choices__inner{border-color:#b7b7b7}.choices__inner:focus{outline:1px solid #00bcd4;outline-offset:-1px}.choices__list{margin:0;padding-left:0;list-style-type:none}.choices__list--items{display:inline}.choices__list--items .choices__item{display:inline-block;border-radius:2rem;padding:.4rem 1rem;font-size:1.2rem;margin-right:.375rem;margin-bottom:.375rem;background-color:#00bcd4;border:1px solid #00b1c7;color:#fff;word-break:break-all}.choices__list--items .choices__item.is-selected{background-color:#00a5bb}.choices__list--dropdown{display:none;z-index:1;position:absolute;width:100%;background-color:#fff;border:1px solid #ddd;top:100%;margin-top:-1px;border-bottom-left-radius:.25rem;border-bottom-right-radius:.25rem;max-height:300px;overflow:auto;will-change:scroll-position}.is-active .choices__list--dropdown{border-color:#b7b7b7}.choices__list--dropdown .choices__item{padding:1rem;font-size:1.4rem}.choices__list--dropdown .choices__item--selectable.is-highlighted:after,.choices__list--dropdown .choices__item.is-selected{opacity:.5}.choices__list--dropdown .choices__item.is-selected:hover{background-color:#fff}.choices__list--dropdown .choices__item--selectable:after{content:"Press to select";font-size:12px;opacity:0;float:right}.choices__list--dropdown .choices__item--selectable.is-highlighted{background-color:#f2f2f2}.choices__list--dropdown.is-active{display:block}.choices__list--dropdown.is-flipped{top:auto;bottom:100%;margin-top:0;margin-bottom:-1px;border-bottom-left-radius:0;border-bottom-right-radius:0;border-top-left-radius:.25rem;border-top-right-radius:.25rem}.choices__item{cursor:default}.choices__item--selectable{cursor:pointer}.choices__item--disabled{cursor:not-allowed;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:.5}.choices__group .choices__heading{font-weight:600;font-size:1.2rem;padding:1rem;border-bottom:1px solid #eaeaea;color:gray}.choices__input{background-color:#f9f9f9;font-size:1.4rem;padding:0;margin-bottom:.5rem;display:inline-block;vertical-align:baseline;border:0;border-radius:0;max-width:100%;padding:.4rem 0 .4rem .2rem}.choices__input:focus{outline:0} \ No newline at end of file diff --git a/assets/styles/scss/choices.scss b/assets/styles/scss/choices.scss index 75255bd..989d8bb 100644 --- a/assets/styles/scss/choices.scss +++ b/assets/styles/scss/choices.scss @@ -115,21 +115,15 @@ h1, h2, h3, h4, h5, h6 { } } .choices__item--selectable { - transition: background-color .15s ease-in-out; &:after { content: "Press to select"; font-size: 12px; opacity: 0; float: right; - transition: opacity .15s ease-in-out; } &.is-highlighted { background-color: mix(#000000, #FFFFFF, 5%); - transition: background-color .15s ease-in-out; - &:after { - opacity: .5; - transition: opacity .15s ease-in-out; - } + &:after { opacity: .5; } } }