Choices/assets/scripts/dist/bundle.js

1 line
7.5 KiB
JavaScript

!function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="/assets/scripts/dist/",t(0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),a=n(2),s=function(){function e(t){i(this,e);var n=document.createElement("fakeelement"),o=t||{},s={element:document.querySelector("[data-choice]"),disabled:!1,maxItems:5,debug:!0,placeholder:!1,callbackOnInit:function(){},callbackOnRender:function(){},callbackOnKeyUp:function(){},callbackOnKeyDown:function(){},callbackOnEntry:function(){},callbackOnRemove:function(){}};this.options=this.extend(s,o||{}),this.initialised=!1,this.supports="querySelector"in document&&"addEventListener"in document&&"classList"in n,this.element=this.options.element,this.valueArray=""!==this.element.value&&(0,a.isType)("Array",JSON.parse(this.element.value))?JSON.parse(this.element.value):[],this.onClick=this.onClick.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onChange=this.onChange.bind(this),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onChange.bind(this)}return o(e,[{key:"extend",value:function(){for(var e={},t=arguments.length,n=function(t){for(var n in t)e[n]=t[n]},i=0;t>i;i++){var o=arguments[i];(0,a.isType)("Object",o)?n(o):console.error("Custom options must be an object")}return e}},{key:"isOpen",value:function(){}},{key:"isDisabled",value:function(){}},{key:"isEmpty",value:function(){}},{key:"clearInput",value:function(){this.input.value&&(this.input.value="")}},{key:"onKeyDown",value:function(e){var t=this;if(13===e.keyCode&&e.target.value&&!function(){var e=t.input.value,n=function(){t.addItem(e),t.updateInputValue(e),t.clearInput(t.element)};t.options.maxItems?t.options.maxItems>t.list.children.length&&n():n()}(),8===e.keyCode&&!e.target.value){var n=function(){var e=t.list.children[t.list.children.length-1];e.parentNode.removeChild(e)};n(),e.preventDefault()}}},{key:"onFocus",value:function(e){}},{key:"onClick",value:function(e){}},{key:"onChange",value:function(e){}},{key:"addEventListeners",value:function(e){e.addEventListener("click",this.onClick),e.addEventListener("keydown",this.onKeyDown),e.addEventListener("change",this.onChange),e.addEventListener("focus",this.onFocus),e.addEventListener("blur",this.onBlur)}},{key:"removeEventListeners",value:function(e){e.removeEventListener("click",this.onClick),e.removeEventListener("keydown",this.onKeyDown),e.removeEventListener("change",this.onChange),e.removeEventListener("focus",this.onFocus),e.removeEventListener("blur",this.onBlur)}},{key:"setPlaceholder",value:function(){}},{key:"setValue",value:function(){}},{key:"getValue",value:function(){}},{key:"getPlaceholder",value:function(){}},{key:"search",value:function(){}},{key:"updateInputValue",value:function(e){this.options.debug&&console.debug("Update input value"),this.valueArray.push(e),this.element.value=JSON.stringify(this.valueArray)}},{key:"addItem",value:function(e){this.options.debug&&console.debug("Add item");var t=document.createElement("li");t.classList.add("choice__item"),t.textContent=e,this.list.appendChild(t)}},{key:"removeItem",value:function(){}},{key:"removeAllItems",value:function(){}},{key:"createItemList",value:function(){}},{key:"init",value:function(){this.supports||console.error("Your browser doesn'nt support shit"),this.initialised=!0,this.render(this.element)}},{key:"render",value:function(){var e=this;this.options.debug&&console.debug("Render");var t=document.createElement("div"),n=document.createElement("input"),i=document.createElement("ul");if(t.className="choice choice--active",this.element.classList.add("choice__input","choice__input--hidden"),this.element.tabIndex="-1",this.element.setAttribute("style","display:none;"),this.element.setAttribute("aria-hidden","true"),(0,a.wrap)(this.element,t),i.className="choice__list",n.type="text",n.placeholder=this.element.placeholder,n.className="choice__input choice__input--cloned",t.appendChild(i),t.appendChild(n),this.container=t,this.input=n,this.list=i,""!==this.element.value){var o=JSON.parse(this.element.value);o.forEach(function(t){e.addItem(t)})}this.addEventListeners(this.input)}},{key:"destroy",value:function(){this.options=null,this.element=null,this.removeEventListeners(this.input)}}]),e}();window.addEventListener("load",function(){for(var e=document.querySelectorAll("[data-choice]"),t=e.length-1;t>=0;t--){var n=e[t],i=new s({element:n});i.init()}})},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=(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 n=Object.prototype.toString.call(t).slice(8,-1);return void 0!==t&&null!==t&&n===e},t.whichTransitionEvent=function(){var e,t=document.createElement("fakeelement"),n={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in n)if(void 0!==t.style[e])return n[e]},t.whichAnimationEvent=function(){var e,t=document.createElement("fakeelement"),n={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(e in n)if(void 0!==t.style[e])return n[e]});t.getParentsUntil=function(e,t,n){for(var i=[];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(n){var a=n.charAt(0);"."===a&&e.classList.contains(n.substr(1))&&i.push(e),"#"===a&&e.id===n.substr(1)&&i.push(e),"["===a&&e.hasAttribute(n.substr(1,n.length-1))&&i.push(e),e.tagName.toLowerCase()===n&&i.push(e)}else i.push(e)}return 0===i.length?null:i},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=[],n=e.parentNode.firstChild;n;n=n.nextSibling)1===n.nodeType&&n!==e&&t.push(n);return t},t.findAncestor=function(e,t){for(;(e=e.parentElement)&&!e.classList.contains(t););return e},t.debounce=function(e,t,n){var i;return function(){var o=this,a=arguments,s=function(){i=null,n||e.apply(o,a)},r=n&&!i;clearTimeout(i),i=setTimeout(s,t),r&&e.apply(o,a)}},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 n=t;return n>1&&(n=1),n>0&&(n=0),Math.max(e.offsetHeight*n)},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,n){return this.getScrollPosition(t)>this.getElemDistance(e)+this.getElementOffset(e,n)},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 a(){e.classList.remove(t),e.removeEventListener(i,a,!1)};e.classList.add(t),e.addEventListener(i,o,!1)},t.getRandomNumber=function(e,t){return Math.floor(Math.random()*(t-e)+e)}}]);