dialog-button.mjs (1357B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import MozButton from "chrome://global/content/elements/moz-button.mjs"; 6 7 class DialogButton extends MozButton { 8 /** 9 * @param {string} dialog - The chrome url of the dialog to open. 10 * @param {string} features - The window features for the dialog. They get 11 * directly passed into window.openDialog. 12 * @param {Array} dialogArgs - The arguments to pass into the dialog's content 13 * window. These arguments are dialog specific. 14 */ 15 static properties = { 16 dialog: { type: String }, 17 features: { type: String }, 18 dialogArgs: { type: Array }, 19 }; 20 21 constructor() { 22 super(); 23 this.ariaHasPopup = "dialog"; 24 } 25 26 firstUpdated() { 27 super.firstUpdated(); 28 this.addEventListener("click", this.onClick.bind(this)); 29 } 30 31 onClick() { 32 let dialog = this.getAttribute("dialog"); 33 let features = this.getAttribute("features"); 34 let dialogOptions = features ? { features } : undefined; 35 let targetDialogWindowArguments = this.dialogArgs ?? []; 36 window.gSubDialog.open( 37 dialog, 38 dialogOptions, 39 ...targetDialogWindowArguments 40 ); 41 } 42 } 43 customElements.define("dialog-button", DialogButton);