Choices/assets/scripts/dist/bundle.js

2 lines
34 KiB
JavaScript
Raw Normal View History

!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){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.Choices=void 0;var r=function(){function e(e,t){for(var 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(17),l=n(18),d=n(19),p=i(d),h=t.Choices=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?"[data-choice]":arguments[0],n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];o(this,e);var i="querySelector"in document&&"addEventListener"in document&&"classList"in document.createElement("div");if(i||console.error("init: Your browser doesn't support Choices"),(0,l.isType)("String",t)){var r=document.querySelectorAll(t);if(r.length>1)for(var a=1;a<r.length;a++){var u=r[a];new e(u,options)}}var d={items:[],addItems:!0,removeItems:!0,editItems:!1,maxItems:!1,delimiter:",",allowDuplicates:!0,allowPaste:!0,allowSearch:!0,regexFilter:!1,debug:!1,placeholder:!0,placeholderValue:"",prependValue:!1,appendValue:!1,selectAll:!0,classNames:{containerOuter:"choices",containerInner:"choices__inner",input:"choices__input",inputCloned:"choices__input--cloned",list:"choices__list",listItems:"choices__list--items",listDropdown:"choices__list--dropdown",item:"choices__item",itemSelectable:"choices__item--selectable",itemDisabled:"choices__item--disabled",itemOption:"choices__item--option",group:"choices__group",groupHeading:"choices__heading",activeState:"is-active",disabledState:"is-disabled",highlightedState:"is-highlighted",hiddenState:"is-hidden",flippedState:"is-flipped",selectedState:"is-selected"},callbackOnInit:function(){},callbackOnRender:function(){},callbackOnRemoveItem:function(){},callbackOnAddItem:function(){}};this.initialised=!1,this.options=(0,l.extend)(d,n),this.store=(0,s.createStore)(c.default),this.passedElement=(0,l.isType)("String",t)?document.querySelector(t):t,this.presetItems=[],this.options.items.length?this.presetItems=this.options.items:""!==this.passedElement.value&&(this.presetItems=this.passedElement.value.split(this.options.delimiter)),this.init=this.init.bind(this),this.render=this.render.bind(this),this.destroy=this.destroy.bind(this),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onBlur.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onClick=this.onClick.bind(this),this.onPaste=this.onPaste.bind(this),this.onMouseOver=this.onMouseOver.bind(this),this.init()}return r(e,[{key:"handleEnter",value:function(e,t){var n=!0;if("text"===this.passedElement.type&&(this.options.addItems?this.options.maxItems&&this.options.maxItems<=this.list.children.length?n=!1:this.options.allowDuplicates===!1&&this.passedElement.value&&(n=!e.some(function(e){return e.value===t})):n=!1,n)){var i=!0;this.options.regexFilter&&(i=this.regexFilter(t)),i&&(this.addItem(t),this.clearInput(this.passedElement))}}},{key:"handleBackspaceKey",value:function(e){if(this.options.removeItems&&e){var t=e[e.length-1],n=e.some(function(e){return e.selected===!0});this.options.editItems&&!n&&t?(this.input.value=t.value,this.removeItem(t)):(this.selectItem(t),this.removeAllSelectedItems())}}},{key:"handleClick",value:function(e,t,n){var i=this;this.options.removeItems&&t&&!function(){var o=t.getAttribute("data-choice-id");e.forEach(function(e){e.id!==parseInt(o)||e.selected?n||i.deselectItem(e):i.selectItem(e)})}()}},{key:"onKeyDown",value:function(e){if(e.target===this.input){var t=e.ctrlKey||e.metaKey,n=46,i=8,o=13,r=65,s=27,a=38,c=40,u=this.getItemsFilteredByActive(),d=(this.getOptionsFilteredByActive(),this.input
}:function(t,n){for(var o=0,r=0;e>o;o++)r+=s(n[i[o]],t);return r/e}:function(){return 0}}();return r?1===r?function(e){return a(o[0],e)}:"and"===e.options.conjunction?function(e){for(var t,n=0,i=0;r>n;n++){if(t=a(o[n],e),0>=t)return 0;i+=t}return i/r}:function(e){for(var t=0,n=0;r>t;t++)n+=a(o[t],e);return n/r}:function(){return 0}},e.prototype.getSortFunction=function(e,n){var i,o,r,s,a,c,u,l,d,p,h;if(r=this,e=r.prepareSearch(e,n),h=!e.query&&n.sort_empty||n.sort,d=function(e,t){return"$score"===e?t.score:r.items[t.id][e]},a=[],h)for(i=0,o=h.length;o>i;i++)(e.query||"$score"!==h[i].field)&&a.push(h[i]);if(e.query){for(p=!0,i=0,o=a.length;o>i;i++)if("$score"===a[i].field){p=!1;break}p&&a.unshift({field:"$score",direction:"desc"})}else for(i=0,o=a.length;o>i;i++)if("$score"===a[i].field){a.splice(i,1);break}for(l=[],i=0,o=a.length;o>i;i++)l.push("desc"===a[i].direction?-1:1);return c=a.length,c?1===c?(s=a[0].field,u=l[0],function(e,n){return u*t(d(s,e),d(s,n))}):function(e,n){var i,o,r;for(i=0;c>i;i++)if(r=a[i].field,o=l[i]*t(d(r,e),d(r,n)))return o;return 0}:null},e.prototype.prepareSearch=function(e,t){if("object"==typeof e)return e;t=n({},t);var i=t.fields,o=t.sort,s=t.sort_empty;return i&&!r(i)&&(t.fields=[i]),o&&!r(o)&&(t.sort=[o]),s&&!r(s)&&(t.sort_empty=[s]),{options:t,query:String(e||"").toLowerCase(),tokens:this.tokenize(e),total:0,items:[]}},e.prototype.search=function(e,t){var n,i,o,r,s=this;return i=this.prepareSearch(e,t),t=i.options,e=i.query,r=t.score||s.getScoreFunction(i),e.length?s.iterator(s.items,function(e,o){n=r(e),(t.filter===!1||n>0)&&i.items.push({score:n,id:o})}):s.iterator(s.items,function(e,t){i.items.push({score:1,id:t})}),o=s.getSortFunction(i,t),o&&i.items.sort(o),i.total=i.items.length,"number"==typeof t.limit&&(i.items=i.items.slice(0,t.limit)),i};var t=function(e,t){return"number"==typeof e&&"number"==typeof t?e>t?1:t>e?-1:0:(e=a(String(e||"")),t=a(String(t||"")),e>t?1:t>e?-1:0)},n=function(e,t){var n,i,o,r;for(n=1,i=arguments.length;i>n;n++)if(r=arguments[n])for(o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);return e},i=function(e){return(e+"").replace(/^\s+|\s+$|/g,"")},o=function(e){return(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},r=Array.isArray||"undefined"!=typeof $&&$.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},s={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎð]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},a=function(){var e,t,n,i,o="",r={};for(n in s)if(s.hasOwnProperty(n))for(i=s[n].substring(2,s[n].length-1),o+=i,e=0,t=i.length;t>e;e++)r[i.charAt(e)]=n;var a=new RegExp("["+o+"]","g");return function(e){return e.replace(a,function(e){return r[e]}).toLowerCase()}}();return e})}]);