Skip to content

Commit c104437

Browse files
committed
TouchManager.disableContextMenu is a new method that will try to disable the context menu on touch devices, if the Game Config disableContextMenu is set. Previously, it only tried to do it for the Mouse Manager, but now does it for touch as well. Fix phaserjs#4778
1 parent 4d4ab05 commit c104437

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/input/touch/TouchManager.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var TouchManager = new Class({
3232
initialize:
3333

3434
function TouchManager (inputManager)
35-
{
35+
{ó
3636
/**
3737
* A reference to the Input Manager.
3838
*
@@ -186,12 +186,40 @@ var TouchManager = new Class({
186186
this.target = this.manager.game.canvas;
187187
}
188188

189+
if (config.disableContextMenu)
190+
{
191+
this.disableContextMenu();
192+
}
193+
189194
if (this.enabled && this.target)
190195
{
191196
this.startListeners();
192197
}
193198
},
194199

200+
/**
201+
* Attempts to disable the context menu from appearing if you touch-hold on the browser.
202+
*
203+
* Works by listening for the `contextmenu` event and prevent defaulting it.
204+
*
205+
* Use this if you need to disable the OS context menu on mobile.
206+
*
207+
* @method Phaser.Input.Touch.TouchManager#disableContextMenu
208+
* @since 3.20.0
209+
*
210+
* @return {Phaser.Input.Touch.TouchManager} This Touch Manager instance.
211+
*/
212+
disableContextMenu: function ()
213+
{
214+
document.body.addEventListener('contextmenu', function (event)
215+
{
216+
event.preventDefault();
217+
return false;
218+
});
219+
220+
return this;
221+
},
222+
195223
/**
196224
* Starts the Touch Event listeners running as long as an input target is set.
197225
*

0 commit comments

Comments
 (0)