Choices/assets/scripts/dist/bundle.js

1 line
17 KiB
JavaScript
Raw Normal View History

2016-04-04 23:52:49 +02:00
!function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return e[i].call(r.exports,r,r.exports,t),r.loaded=!0,r.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){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.Choices=void 0;var 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}}(),s=n(2),a=n(13),c=i(a),u=n(14),l=n(15),d=t.Choices=function(){function e(t){r(this,e);var n=document.createElement("fakeel"),i=t||{},o={element:document.querySelector("[data-choice]"),disabled:!1,addItems:!0,removeItems:!0,editItems:!1,maxItems:!1,delimiter:",",allowDuplicates:!0,regexFilter:!1,debug:!1,placeholder:!1,prependValue:!1,appendValue:!1,selectAll:!0,callbackOnInit:function(){},callbackOnRender:function(){},callbackOnRemoveItem:function(){},callbackOnAddItem:function(){}};this.initialised=!1,this.options=(0,l.extend)(o,i||{}),this.store=(0,s.createStore)(c.default),this.supports="querySelector"in document&&"addEventListener"in document&&"classList"in n,this.element=this.options.element,this.onKeyDown=this.onKeyDown.bind(this),this.onClick=this.onClick.bind(this),this.render=this.render.bind(this),this.init()}return o(e,[{key:"isDisabled",value:function(){return!!this.input.disabled}},{key:"isEmpty",value:function(){return 0===this.store.getState().length}},{key:"onKeyDown",value:function(e){var t=this,n=this.store.getState(),i=e.ctrlKey||e.metaKey,r=8,o=13,s=65;if(e.target===this.input){if(i&&e.keyCode===s&&this.list&&this.list.children){var a=function(){t.options.removeItems&&!t.input.value&&t.options.selectAll&&t.selectAll(t.list.children)};a()}e.keyCode===o&&e.target.value&&!function(){var e=t.input.value,i=function(){var i=!0;if(t.options.maxItems&&t.options.maxItems<=t.list.children.length&&(i=!1),t.options.allowDuplicates===!1&&t.element.value&&(i=!n.some(function(t){return t.value===e})),i&&"text"===t.element.type){var r=!0;t.options.regexFilter&&(r=t.regexFilter(e)),r&&(t.addItem(e),t.clearInput(t.element))}};i()}()}if(e.keyCode===r&&!e.target.value){var c=function(){if(t.options.removeItems){var e=t.list.querySelectorAll(".choices__item"),n=t.list.querySelectorAll(".is-selected"),i=e[e.length-1];i&&!t.options.editItems&&t.selectItem(i),t.options.editItems&&i&&0===n.length?(t.input.value=i.innerHTML,t.removeItem(i)):t.removeAll(e)}};c(),e.preventDefault()}}},{key:"onClick",value:function(e){var t=this;if("LI"===e.target.tagName){var n=e.target,i=function(e){for(var n=e.getAttribute("data-choice-id"),i=t.list.children,r=0;r<i.length;r++){var o=i[r],s=o.getAttribute("data-choice-id");s!==n||o.classList.contains("is-selected")?t.deselectItem(o):t.selectItem(o)}};i(n)}}},{key:"clearInput",value:function(){this.input.value&&(this.input.value="")}},{key:"regexFilter",value:function(e){var t=new RegExp(this.options.regexFilter,"i"),n=t.test(e);return n}},{key:"selectItem",value:function(e){var t=e.getAttribute("data-choice-id");this.store.dispatch((0,u.selectItemFromStore)(t,!0))}},{key:"deselectItem",value:function(e){var t=e.getAttribute("data-choice-id");this.store.dispatch((0,u.selectItemFromStore)(t,!1))}},{key:"selectAll",value:function(e){for(var t=0;t<e.length;t++){var n=e[t];this.selectItem(n)}}},{key:"addItem",value:function(e){this.options.debug&&console.debug("Add item");var t=e;this.options.prependValue&&(t=this.options.prependValue+t.toString()),this.options.appendValue&&(t+=this.options.appendValue.toString());var n=this.store.getState().length+1;this.options.callbackOnAddItem&&((0,l.isType)("Function",this.options.callbackOnAddItem)?this.options.callbackOnAddItem(n,e):console.error("callbackOnAddItem: Callback is not a function")),this.store.dispatch((0,u.addItemT