diff --git a/assets/scripts/dist/bundle.js b/assets/scripts/dist/bundle.js index 3512636..933650d 100644 --- a/assets/scripts/dist/bundle.js +++ b/assets/scripts/dist/bundle.js @@ -1 +1 @@ -!function(e){function n(i){if(t[i])return t[i].exports;var o=t[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=e,n.c=t,n.p="/assets/scripts/dist/",n(0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){function i(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var o,r=function(){function e(e,n){for(var t=0;t=0;n--){var t=e[n];this.render(t)}}},{key:"render",value:function(e){console.log("Render");var n=document.createElement("div"),t=document.createElement("input"),i=document.createElement("ul");n.classList.add("choice","choice--active"),e.classList.add("choice__input","choice__input--original"),e.tabIndex="-1",e.setAttribute("style","display:none;"),(0,s.wrap)(e,n),i.classList.add("choice__list"),t.type="text",t.classList.add("choice__input","choice__input--cloned"),n.appendChild(i),n.appendChild(t),this.addEventListeners(t)}},{key:"destroy",value:function(){this.options=null,this.elements=null;for(var e=this.elements,n=e.length-1;n>=0;n--){var t=e[n];this.removeEventListeners(t)}}}]),e}(),t=new n;t.init(),console.log(t)})},function(e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var t=(n.capitalise=function(e){return e.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})},n.isType=function(e,n){var t=Object.prototype.toString.call(n).slice(8,-1);return void 0!==n&&null!==n&&t===e},n.whichTransitionEvent=function(){var e,n=document.createElement("fakeelement"),t={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in t)if(void 0!==n.style[e])return t[e]},n.whichAnimationEvent=function(){var e,n=document.createElement("fakeelement"),t={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(e in t)if(void 0!==n.style[e])return t[e]});n.getParentsUntil=function(e,n,t){for(var i=[];e&&e!==document;e=e.parentNode){if(n){var o=n.charAt(0);if("."===o&&e.classList.contains(n.substr(1)))break;if("#"===o&&e.id===n.substr(1))break;if("["===o&&e.hasAttribute(n.substr(1,n.length-1)))break;if(e.tagName.toLowerCase()===n)break}if(t){var r=t.charAt(0);"."===r&&e.classList.contains(t.substr(1))&&i.push(e),"#"===r&&e.id===t.substr(1)&&i.push(e),"["===r&&e.hasAttribute(t.substr(1,t.length-1))&&i.push(e),e.tagName.toLowerCase()===t&&i.push(e)}else i.push(e)}return 0===i.length?null:i},n.wrap=function(e,n){return n=n||document.createElement("div"),e.nextSibling?e.parentNode.insertBefore(n,e.nextSibling):e.parentNode.appendChild(n),n.appendChild(e)},n.getSiblings=function(e){for(var n=[],t=e.parentNode.firstChild;t;t=t.nextSibling)1===t.nodeType&&t!==e&&n.push(t);return n},n.findAncestor=function(e,n){for(;(e=e.parentElement)&&!e.classList.contains(n););return e},n.debounce=function(e,n,t){var i;return function(){var o=this,r=arguments,s=function(){i=null,t||e.apply(o,r)},a=t&&!i;clearTimeout(i),i=setTimeout(s,n),a&&e.apply(o,r)}},n.getElemDistance=function(e){var n=0;if(e.offsetParent)do n+=e.offsetTop,e=e.offsetParent;while(e);return n>=0?n:0},n.getElementOffset=function(e,n){var t=n;return t>1&&(t=1),t>0&&(t=0),Math.max(e.offsetHeight*t)},n.getScrollPosition=function(e){return"bottom"===e?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},n.isInView=function(e,n,t){return this.getScrollPosition(n)>this.getElemDistance(e)+this.getElementOffset(e,t)},n.stripHTML=function(e){var n=document.createElement("DIV");return n.innerHTML=e,n.textContent||n.innerText||""},n.addAnimation=function(e,n){var i=t(),o=function r(){e.classList.remove(n),e.removeEventListener(i,r,!1)};e.classList.add(n),e.addEventListener(i,o,!1)},n.getRandomNumber=function(e,n){return Math.floor(Math.random()*(n-e)+e)}}]); \ No newline at end of file +!function(e){function n(i){if(t[i])return t[i].exports;var o=t[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=e,n.c=t,n.p="/assets/scripts/dist/",n(0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){function i(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var o,r=function(){function e(e,n){for(var t=0;t=0;n--){var t=e[n];this.render(t)}}},{key:"render",value:function(e){console.log("Render");var n=document.createElement("div"),t=document.createElement("input"),i=document.createElement("ul");n.classList.add("choice","choice--active"),e.classList.add("choice__input","choice__input--original"),e.tabIndex="-1",e.setAttribute("style","display:none;"),e.setAttribute("aria-hidden","true"),(0,s.wrap)(e,n),i.classList.add("choice__list"),t.type="text",t.classList.add("choice__input","choice__input--cloned"),n.appendChild(i),n.appendChild(t),this.addEventListeners(t)}},{key:"destroy",value:function(){this.options=null,this.elements=null;for(var e=this.elements,n=e.length-1;n>=0;n--){var t=e[n];this.removeEventListeners(t)}}}]),e}(),t=new n;t.init(),console.log(t)})},function(e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var t=(n.capitalise=function(e){return e.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})},n.isType=function(e,n){var t=Object.prototype.toString.call(n).slice(8,-1);return void 0!==n&&null!==n&&t===e},n.whichTransitionEvent=function(){var e,n=document.createElement("fakeelement"),t={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in t)if(void 0!==n.style[e])return t[e]},n.whichAnimationEvent=function(){var e,n=document.createElement("fakeelement"),t={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(e in t)if(void 0!==n.style[e])return t[e]});n.getParentsUntil=function(e,n,t){for(var i=[];e&&e!==document;e=e.parentNode){if(n){var o=n.charAt(0);if("."===o&&e.classList.contains(n.substr(1)))break;if("#"===o&&e.id===n.substr(1))break;if("["===o&&e.hasAttribute(n.substr(1,n.length-1)))break;if(e.tagName.toLowerCase()===n)break}if(t){var r=t.charAt(0);"."===r&&e.classList.contains(t.substr(1))&&i.push(e),"#"===r&&e.id===t.substr(1)&&i.push(e),"["===r&&e.hasAttribute(t.substr(1,t.length-1))&&i.push(e),e.tagName.toLowerCase()===t&&i.push(e)}else i.push(e)}return 0===i.length?null:i},n.wrap=function(e,n){return n=n||document.createElement("div"),e.nextSibling?e.parentNode.insertBefore(n,e.nextSibling):e.parentNode.appendChild(n),n.appendChild(e)},n.getSiblings=function(e){for(var n=[],t=e.parentNode.firstChild;t;t=t.nextSibling)1===t.nodeType&&t!==e&&n.push(t);return n},n.findAncestor=function(e,n){for(;(e=e.parentElement)&&!e.classList.contains(n););return e},n.debounce=function(e,n,t){var i;return function(){var o=this,r=arguments,s=function(){i=null,t||e.apply(o,r)},a=t&&!i;clearTimeout(i),i=setTimeout(s,n),a&&e.apply(o,r)}},n.getElemDistance=function(e){var n=0;if(e.offsetParent)do n+=e.offsetTop,e=e.offsetParent;while(e);return n>=0?n:0},n.getElementOffset=function(e,n){var t=n;return t>1&&(t=1),t>0&&(t=0),Math.max(e.offsetHeight*t)},n.getScrollPosition=function(e){return"bottom"===e?Math.max((window.scrollY||window.pageYOffset)+(window.innerHeight||document.documentElement.clientHeight)):window.scrollY||window.pageYOffset},n.isInView=function(e,n,t){return this.getScrollPosition(n)>this.getElemDistance(e)+this.getElementOffset(e,t)},n.stripHTML=function(e){var n=document.createElement("DIV");return n.innerHTML=e,n.textContent||n.innerText||""},n.addAnimation=function(e,n){var i=t(),o=function r(){e.classList.remove(n),e.removeEventListener(i,r,!1)};e.classList.add(n),e.addEventListener(i,o,!1)},n.getRandomNumber=function(e,n){return Math.floor(Math.random()*(n-e)+e)}}]); \ No newline at end of file diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 41b893a..a6d6948 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -128,12 +128,26 @@ import { wrap, getSiblings } from './lib/utils.js'; addItem(el, value) { console.log('Add item'); let wrapper = el.parentNode; + let valueInput = wrapper.querySelector('.choice__input--original'); + let list = wrapper.querySelector('.choice__list'); let item = document.createElement('li'); item.classList.add('choice__item'); item.textContent = value; + if(valueInput.value === '') { + valueInput.value = JSON.stringify([]); + } + + let valueInputArray = JSON.parse(valueInput.value); + + valueInputArray.push(value); + + valueInput.value = JSON.stringify(valueInputArray); + + console.log(valueInput.value); + wrapper.appendChild(item); } @@ -172,6 +186,7 @@ import { wrap, getSiblings } from './lib/utils.js'; el.classList.add('choice__input', 'choice__input--original'); el.tabIndex = '-1'; el.setAttribute('style', 'display:none;'); + el.setAttribute('aria-hidden', 'true'); wrap(el, wrapper);