Choices/assets/scripts/dist/bundle.js

2 lines
34 KiB
JavaScript
Raw Normal View History

!function(t){function e(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return t[i].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="/assets/scripts/dist/",e(0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function i(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 r=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),s=n(2),a=n(13),l=i(a),c=n(17),u=n(18),d=n(19),p=i(d),h=e.Choices=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?"[data-choice]":arguments[0],n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];o(this,t);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,u.isType)("String",e)){var r=document.querySelectorAll(e);if(r.length>1)for(var a=1;a<r.length;a++){var c=r[a];new t(c,options)}}var d={items:[],addItems:!0,removeItems:!0,editItems:!1,maxItems:!1,delimiter:",",allowDuplicates:!0,allowPaste:!0,allowSearch:!0,regexFilter:!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"},templates:{},callbackOnInit:function(){},callbackOnRender:function(){},callbackOnRemoveItem:function(){},callbackOnAddItem:function(){}};this.initialised=!1,this.options=(0,u.extend)(d,n),this.store=(0,s.createStore)(l.default),this.passedElement=(0,u.isType)("String",e)?document.querySelector(e):e,this.highlightPosition=0,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(t,[{key:"handleEnter",value:function(t,e){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=!t.some(function(t){return t.value===e})):n=!1,n)){var i=!0;this.options.regexFilter&&(i=this.regexFilter(e)),i&&(this.addItem(e),this.clearInput(this.passedElement))}}},{key:"handleBackspaceKey",value:function(t){if(this.options.removeItems&&t){var e=t[t.length-1],n=t.some(function(t){return t.selected===!0});this.options.editItems&&!n&&e?(this.input.value=e.value,this.removeItem(e)):(this.selectItem(e),this.removeAllSelectedItems())}}},{key:"handleClick",value:function(t,e,n){var i=this;this.options.removeItems&&e&&!function(){var o=e.getAttribute("data-id");t.forEach(function(t){t.id!==parseInt(o)||t.selected?n||i.deselectItem(t):i.selectItem(t)})}()}},{key:"onKeyDown",value:function(t){if(t.target===this.input){var e=t.ctrlKey||t.metaKey,n=46,i=8,o=13,r=65,s=27,a=38,l=40,c=this.getItemsFilteredByActive(),d=(this.getOptionsFiltere
},n.apply(t,[e])},t.prototype.getScoreFunction=function(t,e){var n,i,o,r;n=this,t=n.prepareSearch(t,e),o=t.tokens,i=t.options.fields,r=o.length;var s=function(t,e){var n,i;return t?(t=String(t||""),i=t.search(e.regex),-1===i?0:(n=e.string.length/t.length,0===i&&(n+=.5),n)):0},a=function(){var t=i.length;return t?1===t?function(t,e){return s(e[i[0]],t)}:function(e,n){for(var o=0,r=0;t>o;o++)r+=s(n[i[o]],e);return r/t}:function(){return 0}}();return r?1===r?function(t){return a(o[0],t)}:"and"===t.options.conjunction?function(t){for(var e,n=0,i=0;r>n;n++){if(e=a(o[n],t),0>=e)return 0;i+=e}return i/r}:function(t){for(var e=0,n=0;r>e;e++)n+=a(o[e],t);return n/r}:function(){return 0}},t.prototype.getSortFunction=function(t,n){var i,o,r,s,a,l,c,u,d,p,h;if(r=this,t=r.prepareSearch(t,n),h=!t.query&&n.sort_empty||n.sort,d=function(t,e){return"$score"===t?e.score:r.items[e.id][t]},a=[],h)for(i=0,o=h.length;o>i;i++)(t.query||"$score"!==h[i].field)&&a.push(h[i]);if(t.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(u=[],i=0,o=a.length;o>i;i++)u.push("desc"===a[i].direction?-1:1);return l=a.length,l?1===l?(s=a[0].field,c=u[0],function(t,n){return c*e(d(s,t),d(s,n))}):function(t,n){var i,o,r;for(i=0;l>i;i++)if(r=a[i].field,o=u[i]*e(d(r,t),d(r,n)))return o;return 0}:null},t.prototype.prepareSearch=function(t,e){if("object"==typeof t)return t;e=n({},e);var i=e.fields,o=e.sort,s=e.sort_empty;return i&&!r(i)&&(e.fields=[i]),o&&!r(o)&&(e.sort=[o]),s&&!r(s)&&(e.sort_empty=[s]),{options:e,query:String(t||"").toLowerCase(),tokens:this.tokenize(t),total:0,items:[]}},t.prototype.search=function(t,e){var n,i,o,r,s=this;return i=this.prepareSearch(t,e),e=i.options,t=i.query,r=e.score||s.getScoreFunction(i),t.length?s.iterator(s.items,function(t,o){n=r(t),(e.filter===!1||n>0)&&i.items.push({score:n,id:o})}):s.iterator(s.items,function(t,e){i.items.push({score:1,id:e})}),o=s.getSortFunction(i,e),o&&i.items.sort(o),i.total=i.items.length,"number"==typeof e.limit&&(i.items=i.items.slice(0,e.limit)),i};var e=function(t,e){return"number"==typeof t&&"number"==typeof e?t>e?1:e>t?-1:0:(t=a(String(t||"")),e=a(String(e||"")),t>e?1:e>t?-1:0)},n=function(t,e){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)&&(t[o]=r[o]);return t},i=function(t){return(t+"").replace(/^\s+|\s+$|/g,"")},o=function(t){return(t+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},r=Array.isArray||"undefined"!=typeof $&&$.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},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 t,e,n,i,o="",r={};for(n in s)if(s.hasOwnProperty(n))for(i=s[n].substring(2,s[n].length-1),o+=i,t=0,e=i.length;e>t;t++)r[i.charAt(t)]=n;var a=new RegExp("["+o+"]","g");return function(t){return t.replace(a,function(t){return r[t]}).toLowerCase()}}();return t})}]);