web: Fix some context menu and warning message issues

This commit is contained in:
Toad06 2021-02-05 00:10:04 +01:00 committed by GitHub
parent 5f25fe8807
commit b5749ee228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 22 deletions

View File

@ -59,6 +59,13 @@ interface ContextMenuItem {
* @param event The mouse event that triggered the click * @param event The mouse event that triggered the click
*/ */
onClick: (event: MouseEvent) => void; onClick: (event: MouseEvent) => void;
/**
* Whether to add a separator right after the item
*
* @default true
*/
separator?: boolean;
} }
/** /**
@ -604,17 +611,12 @@ export class RufflePlayer extends HTMLElement {
}); });
} }
} }
items.push({
text: "SEPARATOR",
onClick() {
// do nothing.
},
});
items.push({ items.push({
text: `About Ruffle (%VERSION_NAME%)`, text: `About Ruffle (%VERSION_NAME%)`,
onClick() { onClick() {
window.open(RUFFLE_ORIGIN, "_blank"); window.open(RUFFLE_ORIGIN, "_blank");
}, },
separator: false,
}); });
return items; return items;
} }
@ -634,19 +636,19 @@ export class RufflePlayer extends HTMLElement {
} }
// Populate context menu items. // Populate context menu items.
for (const { text, onClick } of this.contextMenuItems()) { for (const { text, onClick, separator } of this.contextMenuItems()) {
if (text == "SEPARATOR") { const menuItem = document.createElement("li");
const element = document.createElement("li"); menuItem.className = "menu_item active";
element.className = "menu_separator"; menuItem.textContent = text;
menuItem.addEventListener("click", onClick);
this.contextMenuElement.appendChild(menuItem);
if (separator !== false) {
const menuSeparator = document.createElement("li");
menuSeparator.className = "menu_separator";
const hr = document.createElement("hr"); const hr = document.createElement("hr");
element.appendChild(hr); menuSeparator.appendChild(hr);
this.contextMenuElement.appendChild(element); this.contextMenuElement.appendChild(menuSeparator);
} else {
const element = document.createElement("li");
element.className = "menu_item active";
element.textContent = text;
element.addEventListener("click", onClick);
this.contextMenuElement.appendChild(element);
} }
} }
@ -1017,14 +1019,14 @@ export class RufflePlayer extends HTMLElement {
<p>Flash Player has been removed from browsers in 2021.</p> <p>Flash Player has been removed from browsers in 2021.</p>
<p>This content is not yet supported by the Ruffle emulator and will likely not run as intended.</p> <p>This content is not yet supported by the Ruffle emulator and will likely not run as intended.</p>
<div> <div>
<a class="more-info-link" href="https://github.com/ruffle-rs/ruffle/wiki/Frequently-Asked-Questions-For-Users">More info</a> <a target="_top" class="more-info-link" href="https://github.com/ruffle-rs/ruffle/wiki/Frequently-Asked-Questions-For-Users">More info</a>
<button id="run-anyway-btn">Run anyway</button> <button id="run-anyway-btn">Run anyway</button>
</div> </div>
</div>`; </div>`;
this.container.prepend(div); this.container.prepend(div);
const button = <HTMLButtonElement>div.querySelector("#run-anyway-btn"); const button = <HTMLButtonElement>div.querySelector("#run-anyway-btn");
button.onclick = () => { button.onclick = () => {
div.remove(); div.parentNode!.removeChild(div);
}; };
} }
@ -1042,7 +1044,7 @@ export class RufflePlayer extends HTMLElement {
(<HTMLButtonElement>( (<HTMLButtonElement>(
this.container.querySelector("#continue-btn") this.container.querySelector("#continue-btn")
)).onclick = () => { )).onclick = () => {
div.remove(); div.parentNode!.removeChild(div);
}; };
} }

View File

@ -171,6 +171,7 @@ ruffleShadowTemplate.innerHTML = `
} }
#context-menu { #context-menu {
display: none;
color: black; color: black;
background-color: #FAFAFA; background-color: #FAFAFA;
border: 1px solid gray; border: 1px solid gray;
@ -187,7 +188,6 @@ ruffleShadowTemplate.innerHTML = `
padding: 5px 10px; padding: 5px 10px;
} }
#context-menu .active { #context-menu .active {
cursor: pointer; cursor: pointer;
color: black; color: black;