- md5
- cadb1f341ed99baa3b615b9578dc3a8e
- sha1
- 0b3d5572dbd962223d47e65c80e394a6b7725346
- sha256
- 3a188befc67d1c28114b01c470140e1c002d16079224cb530cde16d0422b7957
/**
* @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.setAttribute("aria-disabled","true"),this.buttonElement.classList.add("disabled")}else this.buttonElement.nodeName==="BUTTON"?(this.buttonElement.removeAttribute("aria-disabled"),this.buttonElement.classList.remove("disabled")):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 8 releases, Joomla 6.2.0-beta2 to 6.3.0-alpha1. See them all, or every version of this file.