- md5
- a0c6e7923273eaf8ef50f25792e9d5d4
- sha1
- ddd859a5a564a1b1f1a0f4c866069367eacdff63
- sha256
- 5b7b8cfd0369428d7366d9e62e4cb714219ac5e352692a30b8935adc23289e5c
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/window.customElements.define("joomla-toolbar-button",class extends HTMLElement{get task(){return this.getAttribute("task")}get listSelection(){return this.hasAttribute("list-selection")}get form(){return this.getAttribute("form")}get formValidation(){return this.hasAttribute("form-validation")}get confirmMessage(){return this.getAttribute("confirm-message")}constructor(){if(super(),!Joomla)throw new Error("Joomla API is not properly initiated");this.confirmationReceived=!1,this.onChange=this.onChange.bind(this),this.executeTask=this.executeTask.bind(this)}connectedCallback(){this.buttonElement=this.querySelector("button, a"),this.buttonElement.addEventListener("click",this.executeTask);const t=this.form||"adminForm";if(this.formElement=document.getElementById(t),this.disabled=!1,this.listSelection&&this.setDisabled(!0),this.listSelection){if(!this.formElement)throw new Error(`The form "${t}" is required to perform the task, but the form was not found on the page.`);this.formElement.boxchecked.addEventListener("change",this.onChange)}this.onHideDropdown=this.onHideDropdown.bind(this),this.buttonElement.classList.contains("dropdown-toggle")&&this.buttonElement.addEventListener("hide.bs.dropdown",this.onHideDropdown)}disconnectedCallback(){this.formElement.boxchecked&&this.formElement.boxchecked.removeEventListener("change",this.onChange),this.buttonElement.removeEventListener("click",this.executeTask),this.buttonElement.classList.contains("dropdown-toggle")&&this.buttonElement.removeEventListener("hide.bs.dropdown",this.onHideDropdown)}onHideDropdown(t){if(t.clickEvent&&t.clickEvent.target instanceof Element){const e=t.clickEvent.target;this.formElement&&this.formElement.contains(e)&&e.closest('input[type="checkbox"], label')&&this.formElement.boxchecked&&this.formElement.boxchecked.value>0&&t.preventDefault()}}onChange({target:t}){this.setDisabled(t.value<1)}setDisabled(t){if(this.disabled=!!t,this.buttonElement)if(this.disabled){if(this.buttonElement.classList.contains("dropdown-toggle")&&this.buttonElement.classList.contains("show")&&window.bootstrap&&window.bootstrap.Dropdown){const e=window.bootstrap.Dropdown.getInstance(this.buttonElement);e&&e.hide()}this.buttonElement.nodeName==="BUTTON"?this.buttonElement.disabled=!0:this.buttonElement.classList.add("disabled")}else this.buttonElement.nodeName==="BUTTON"?this.buttonElement.disabled=!1:this.buttonElement.classList.remove("disabled")}executeTask(){return this.disabled?!1:this.confirmMessage&&!this.confirmationReceived?(import("joomla.dialog").then(t=>t.default.confirm(this.confirmMessage,Joomla.Text._("WARNING","Warning"))).then(t=>{t&&(this.confirmationReceived=!0,this.buttonElement.click())}),!1):(this.confirmationReceived=!1,this.task&&Joomla.submitbutton(this.task,this.form,this.formValidation),!0)}});
The same content is in 7 releases, Joomla 5.4.9-rc1 to 6.1.4. See them all, or every version of this file.