(function(){"use strict";function _(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,f(e,n)}function y(e){return y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(o){return o.__proto__||Object.getPrototypeOf(o)},y(e)}function f(e,n){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},f(e,n)}function A(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function p(e,n,o){return A()?p=Reflect.construct.bind():p=function(i,a,u){var l=[null];l.push.apply(l,a);var c=Function.bind.apply(i,l),r=new c;return u&&f(r,u.prototype),r},p.apply(null,arguments)}function E(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function v(e){var n=typeof Map=="function"?new Map:void 0;return v=function(t){if(t===null||!E(t))return t;if(typeof t!="function")throw new TypeError("Super expression must either be null or a function");if(typeof n<"u"){if(n.has(t))return n.get(t);n.set(t,i)}function i(){return p(t,arguments,y(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),f(i,t)},v(e)}function w(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}/** * @package Joomla.JavaScript * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */customElements.define("joomla-field-module-order",function(e){_(n,e);function n(){var t;return t=e.call(this)||this,t.linkedFieldSelector="",t.linkedFieldElement="",t.originalPosition="",t.writeDynaList.bind(w(t)),t.getNewOrder.bind(w(t)),t}var o=n.prototype;return o.connectedCallback=function(){if(this.linkedFieldSelector=this.getAttribute("data-linked-field")||"jform_position",!this.linkedFieldSelector)throw new Error("No linked field defined!");if(this.linkedFieldElement=document.getElementById(this.linkedFieldSelector),!this.linkedFieldElement)throw new Error("No linked field defined!");var i=this;this.originalPosition=this.linkedFieldElement.value,this.getNewOrder(this.originalPosition),this.linkedFieldElement.addEventListener("change",function(){i.originalPosition=i.linkedFieldElement.value,i.getNewOrder(i.linkedFieldElement.value)})},o.writeDynaList=function(i,a,u,l){var c=0,r=document.createElement("select");this.hasAttribute("disabled")&&r.setAttribute("disabled",""),this.getAttribute("onchange")&&r.setAttribute("onchange",this.getAttribute("onchange")),this.getAttribute("size")&&r.setAttribute("size",this.getAttribute("size")),r.classList.add(i.itemClass),r.setAttribute("name",i.name),r.id=i.id;for(var g in a)if(a.hasOwnProperty(g)){var d=document.createElement("option"),s=a[g];d.value=s[1],d.innerHTML=Joomla.sanitizeHtml(s[2]),(u&&l===s[1]||!u&&c===0)&&d.setAttribute("selected","selected"),r.appendChild(d),c+=1}this.innerHTML="",this.appendChild(r)},o.getNewOrder=function(i){var a=this.getAttribute("data-url"),u=this.getAttribute("data-client-id"),l=this.getAttribute("data-ordering"),c=this.getAttribute("data-name"),r=this.getAttribute("data-client-attr")?this.getAttribute("data-client-attr"):"form-select",g=""+this.getAttribute("data-id"),d=""+this.getAttribute("data-module-id"),s=[],O=this;Joomla.request({url:a+"&client_id="+u+"&position="+i+"&module_id="+d,method:"GET",perform:!0,headers:{"Content-Type":"application/x-www-form-urlencoded"},onSuccess:function(h){if(h){var m;try{m=JSON.parse(h)}catch(k){console.error(k)}if(m.data.length>0){for(var b=0;b<m.data.length;b+=1)s[b]=m.data[b].split(",");O.writeDynaList({name:c,id:g,itemClass:r},s,O.originalPosition,l)}}typeof h.messages=="object"&&h.messages!==null&&Joomla.renderMessages(h.messages)}})},n}(v(HTMLElement)))})();