Merge pull request #230 from GGodPL/main

add title id to betterMenuScreens.js
This commit is contained in:
slweeb 2024-01-04 23:25:57 -05:00 committed by GitHub
commit 7512cbda11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -106,7 +106,7 @@ const inject = () => {
/** /**
* *
* @param {string} menu Menu do be opened * @param {string} menu Menu to be opened
* @param {boolean} [closeCurrent] Whether it should forcefully close the current screen * @param {boolean} [closeCurrent] Whether it should forcefully close the current screen
*/ */
const openMenu = (menu, closeCurrent = false) => { const openMenu = (menu, closeCurrent = false) => {
@ -130,6 +130,7 @@ class MenuScreen {
this.showCloseButton = true; this.showCloseButton = true;
this.closeButtonText = "-"; this.closeButtonText = "-";
this.closeButtonClass = "XButton"; this.closeButtonClass = "XButton";
this.titleId = null;
} }
/** /**
@ -141,6 +142,15 @@ class MenuScreen {
return this; return this;
} }
/**
* Sets screen title ID
* @param {string} [id] Screen title element ID
*/
setTitleId(id) {
this.titleId = id;
return this;
}
/** /**
* Sets close button visibility. When false the close button will not be added to the menu screen * Sets close button visibility. When false the close button will not be added to the menu screen
* @param {boolean} show Visibility of the close button * @param {boolean} show Visibility of the close button
@ -253,7 +263,7 @@ class MenuScreen {
const inner = document.createElement("div"); const inner = document.createElement("div");
inner.className = this.innerDivClass ?? "menuScreen"; inner.className = this.innerDivClass ?? "menuScreen";
inner.innerHTML = `${this.showCloseButton ? `<button class="${this.closeButtonClass ?? "XButton"}" onclick="closeMenu();">${this.closeButtonText}` : ""}</button> inner.innerHTML = `${this.showCloseButton ? `<button class="${this.closeButtonClass ?? "XButton"}" onclick="closeMenu();">${this.closeButtonText}` : ""}</button>
<span class="menuTitle">${this.title ?? "Menu Screen"}</span><br><br><div class="menuText">` + this.innerHtml + "</div>"; <span class="menuTitle"${this.titleId ? ` id="${this.titleId}"` : ""}>${this.title ?? "Menu Screen"}</span><br><br><div class="menuText">` + this.innerHtml + "</div>";
this.nodes.forEach(n => inner.querySelector(".menuText").appendChild(n)); this.nodes.forEach(n => inner.querySelector(".menuText").appendChild(n));
parent.appendChild(inner); parent.appendChild(inner);
document.getElementById(id).appendChild(parent); document.getElementById(id).appendChild(parent);