CoreFiles by mySites.guru
joomla-field-fancy-select-es5.min.js1 lines, 9,310 bytes, from Joomla_4.0.0-beta3-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta2
md5
6d5a4e53c02437ada175354f8a976d9e
sha1
80fb32c43046994f02ea238dc428be1c5f0d0cf9
sha256
c61318164fc3db1c09173695a7eda929dcae45aed68f48fcc272d21cf065a5ca
"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _wrapNativeSuper(a){var b="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(a){function c(){return _construct(a,arguments,_getPrototypeOf(this).constructor)}if(null===a||!_isNativeFunction(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(c,a)},_wrapNativeSuper(a)}function _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _isNativeFunction(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}window.customElements.define("joomla-field-fancy-select",function(a){function b(){var a;if(_classCallCheck(this,b),a=c.call(this),a.keyCode={ENTER:13},!Joomla)throw new Error("Joomla API is not properly initiated");if(!window.Choices)throw new Error("JoomlaFieldFancySelect requires Choices.js to work");return a.choicesCache={},a.activeXHR=null,a.choicesInstance=null,a.isDisconnected=!1,a}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"allowCustom",get:function get(){return this.hasAttribute("allow-custom")}},{key:"remoteSearch",get:function get(){return this.hasAttribute("remote-search")}},{key:"url",get:function get(){return this.getAttribute("url")}},{key:"termKey",get:function get(){return this.getAttribute("term-key")||"term"}},{key:"minTermLength",get:function get(){return parseInt(this.getAttribute("min-term-length"))||1}},{key:"newItemPrefix",get:function get(){return this.getAttribute("new-item-prefix")||""}},{key:"placeholder",get:function get(){return this.getAttribute("placeholder")}},{key:"searchPlaceholder",get:function get(){return this.getAttribute("search-placeholder")}},{key:"value",get:function get(){return this.choicesInstance.getValue(!0)},set:function set(a){this.choicesInstance.setChoiceByValue(a)}}]),_createClass(b,[{key:"connectedCallback",value:function connectedCallback(){var a=this;if(window.Choices||"complete"===document.readyState)this.doConnect();else{var b=function(){a.doConnect(),window.removeEventListener("load",b)};window.addEventListener("load",b)}}},{key:"doConnect",value:function doConnect(){var a=this;if(this.select=this.querySelector("select"),!this.select)throw new Error("JoomlaFieldFancySelect requires <select> element to work");if(this.choicesInstance)return void(this.isDisconnected&&(this.choicesInstance.init(),this.isDisconnected=!1));if(this.isDisconnected=!1,this.select.multiple&&this.placeholder){var c=document.createElement("option");c.setAttribute("placeholder",""),c.textContent=this.placeholder,this.select.appendChild(c)}if(this.choicesInstance=new Choices(this.select,{placeholderValue:this.placeholder,searchPlaceholderValue:this.searchPlaceholder,removeItemButton:!0,searchFloor:this.minTermLength,searchResultLimit:10,shouldSort:!1,fuseOptions:{threshold:.3},noResultsText:Joomla.Text._("JGLOBAL_SELECT_NO_RESULTS_MATCH","No results found"),noChoicesText:Joomla.Text._("JGLOBAL_SELECT_NO_RESULTS_MATCH","No results found"),itemSelectText:Joomla.Text._("JGLOBAL_SELECT_PRESS_TO_SELECT","Press to select"),classNames:{button:"choices__button_joomla"}}),this.allowCustom){var d=this.choicesInstance._highlightChoice;this.choicesInstance._highlightChoice=function(b){b&&d.call(a.choicesInstance,b)},this.addEventListener("mouseleave",function(){if(a.choicesInstance.dropdown.isActive){var b=Array.from(a.choicesInstance.dropdown.element.querySelectorAll(".".concat(a.choicesInstance.config.classNames.highlightedState)));b.forEach(function(b){b.classList.remove(a.choicesInstance.config.classNames.highlightedState),b.setAttribute("aria-selected","false")}),a.choicesInstance._highlightPosition=0}}),this.addEventListener("keydown",function(b){if(b.keyCode===a.keyCode.ENTER&&b.target===a.choicesInstance.input.element&&(b.preventDefault(),!a.choicesInstance._highlightPosition&&b.target.value)){var c=a.choicesInstance.dropdown.element.querySelector(".".concat(a.choicesInstance.config.classNames.highlightedState));if(!c){var d=b.target.value.toLowerCase(),e=!1;return(a.choicesInstance.config.choices.some(function(a){return(a.value.toLowerCase()===d||a.label.toLowerCase()===d)&&(e=a.value,!0)}),!1===e&&Object.keys(a.choicesCache).some(function(b){return(b.toLowerCase()===d||a.choicesCache[b].toLowerCase()===d)&&(e=b,!0)}),!1!==e)?(a.choicesInstance.setChoiceByValue(e),b.target.value=null,void a.choicesInstance.hideDropdown()):(a.choicesInstance.setChoices([{value:a.newItemPrefix+b.target.value,label:b.target.value,selected:!0,customProperties:{value:b.target.value}}],"value","label",!1),a.choicesCache[b.target.value]=b.target.value,b.target.value=null,a.choicesInstance.hideDropdown(),!1)}}})}if(this.remoteSearch&&this.url){this.choicesInstance.config.choices.forEach(function(b){a.choicesCache[b.value]=b.label});var b=null;this.select.addEventListener("search",function(){clearTimeout(b),b=setTimeout(a.requestLookup.bind(a),300)})}}},{key:"disconnectedCallback",value:function disconnectedCallback(){this.choicesInstance&&(this.choicesInstance.destroy(),this.isDisconnected=!0),this.activeXHR&&(this.activeXHR.abort(),this.activeXHR=null)}},{key:"requestLookup",value:function requestLookup(){var a=this,b=this.url;b+=-1===b.indexOf("?")?"?":"&",b+="".concat(encodeURIComponent(this.termKey),"=").concat(encodeURIComponent(this.choicesInstance.input.value)),this.activeXHR&&this.activeXHR.abort(),this.activeXHR=Joomla.request({url:b,onSuccess:function onSuccess(b){a.activeXHR=null;var c=b?JSON.parse(b):[];if(c.length){for(var d,e=c.length-1;0<=e;e--)d=c[e],d.value=""+d.value,a.choicesCache[d.value]?c.splice(e,1):a.choicesCache[d.value]=d.text;c.length&&a.choicesInstance.setChoices(c,"value","text",!1)}},onError:function onError(){a.activeXHR=null}})}},{key:"disableAllOptions",value:function disableAllOptions(){var a=this.choicesInstance._store.choices;a.forEach(function(b,c){a[c].disabled=!0,a[c].selected=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(a,"value","label",!0)}},{key:"enableAllOptions",value:function enableAllOptions(){var a=this.choicesInstance._store.choices,b=this.choicesInstance.getValue(!0);a.forEach(function(b,c){a[c].disabled=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(a,"value","label",!0),this.value=b}},{key:"disableByValue",value:function disableByValue(a){var b=this.choicesInstance._store.choices,c=this.choicesInstance.getValue(!0);b.forEach(function(c,d){c.value===a&&(b[d].disabled=!0,b[d].selected=!1)});var d=c.indexOf(a);-1<d&&c.slice(d,1),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(b,"value","label",!0),this.value=c}},{key:"enableByValue",value:function enableByValue(a){var b=this.choicesInstance._store.choices,c=this.choicesInstance.getValue(!0);b.forEach(function(c,d){c.value===a&&(b[d].disabled=!1)}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(b,"value","label",!0),this.value=c}}]),b}(_wrapNativeSuper(HTMLElement)));

The same content is in 3 releases, Joomla 4.0.0-beta2 to 4.0.0-beta4. See them all, or every version of this file.