web: Simplify custom context menu separators logic
Instead deduplicating separators in `RufflePlayer.showContextMenu()` using DOM attributes, do it right in `RufflePlayer.contextMenuItems()`, using a simpler approach.
This commit is contained in:
parent
b46f511326
commit
156c76cb94
|
@ -885,7 +885,8 @@ export class RufflePlayer extends HTMLElement {
|
||||||
readonly separatorBefore: boolean;
|
readonly separatorBefore: boolean;
|
||||||
}[] = this.instance.prepare_context_menu();
|
}[] = this.instance.prepare_context_menu();
|
||||||
customItems.forEach((item, index) => {
|
customItems.forEach((item, index) => {
|
||||||
if (item.separatorBefore) {
|
// Don't start with separators.
|
||||||
|
if (item.separatorBefore && items.length > 0) {
|
||||||
items.push(null);
|
items.push(null);
|
||||||
}
|
}
|
||||||
items.push({
|
items.push({
|
||||||
|
@ -897,8 +898,12 @@ export class RufflePlayer extends HTMLElement {
|
||||||
enabled: item.enabled,
|
enabled: item.enabled,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Don't start with separators.
|
||||||
|
if (items.length > 0) {
|
||||||
|
items.push(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
items.push(null);
|
|
||||||
|
|
||||||
if (this.fullscreenEnabled) {
|
if (this.fullscreenEnabled) {
|
||||||
if (this.isFullscreen) {
|
if (this.isFullscreen) {
|
||||||
|
@ -1020,20 +1025,6 @@ export class RufflePlayer extends HTMLElement {
|
||||||
// Populate context menu items.
|
// Populate context menu items.
|
||||||
for (const item of this.contextMenuItems()) {
|
for (const item of this.contextMenuItems()) {
|
||||||
if (item === null) {
|
if (item === null) {
|
||||||
// Don't start with separators.
|
|
||||||
if (!this.contextMenuElement.lastElementChild) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't repeat separators.
|
|
||||||
if (
|
|
||||||
this.contextMenuElement.lastElementChild.classList.contains(
|
|
||||||
"menu_separator"
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const menuSeparator = document.createElement("li");
|
const menuSeparator = document.createElement("li");
|
||||||
menuSeparator.className = "menu_separator";
|
menuSeparator.className = "menu_separator";
|
||||||
const hr = document.createElement("hr");
|
const hr = document.createElement("hr");
|
||||||
|
|
Loading…
Reference in New Issue