Skip to content

Commit

Permalink
web: Re-enable context menu on mobile, with option to disable (#5000)
Browse files Browse the repository at this point in the history
* Re-enable context menu on mobile, with option to disable

* Review refactors

Co-authored-by: Adrian Wielgosik <adrian.wielgosik@gmail.com>
  • Loading branch information
danielhjacobs and adrian17 authored Aug 19, 2021
1 parent 58c907e commit 985a97d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions web/packages/core/src/ruffle-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export class RufflePlayer extends HTMLElement {
// so avoid shadowing it.
private contextMenuElement: HTMLElement;
private hasContextMenu = false;
// Allows the user to permanently disable the context menu.
private contextMenuForceDisabled = false;

// Whether this device is a touch device.
// Set to true when a touch event is encountered.
Expand Down Expand Up @@ -656,7 +658,7 @@ export class RufflePlayer extends HTMLElement {
}

private pointerDown(event: PointerEvent): void {
// Disable context menu when touch support is being used
// Give option to disable context menu when touch support is being used
// to avoid a long press triggering the context menu. (#1972)
if (event.pointerType === "touch" || event.pointerType === "pen") {
this.isTouch = true;
Expand Down Expand Up @@ -706,13 +708,20 @@ export class RufflePlayer extends HTMLElement {
window.open(RUFFLE_ORIGIN, "_blank");
},
});
if (this.isTouch) {
items.push(null);
items.push({
text: "Hide this menu",
onClick: () => (this.contextMenuForceDisabled = true),
});
}
return items;
}

private showContextMenu(e: MouseEvent): void {
e.preventDefault();

if (!this.hasContextMenu || this.isTouch) {
if (!this.hasContextMenu || this.contextMenuForceDisabled) {
return;
}

Expand Down

0 comments on commit 985a97d

Please sign in to comment.