Skip to content

Commit 87edd6c

Browse files
committed
Added option to disable context menu
Added to both the game config and as a function in the Mouse Manager.
1 parent 1b4e53d commit 87edd6c

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

v3/src/boot/Config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var Config = new Class({
5858
this.inputMouse = GetValue(config, 'input.mouse', true);
5959
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
6060

61+
this.disableContextMenu = GetValue(config, 'disableContextMenu', false);
62+
6163
// If you do: { banner: false } it won't display any banner at all
6264
this.hideBanner = (GetValue(config, 'banner', null) === false);
6365

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'ef2515e0-70eb-11e7-ad8e-3beabf57a909'
2+
build: 'ac7c3390-712c-11e7-94b3-cb219d37da47'
33
};
44
module.exports = CHECKSUM;

v3/src/input/mouse/MouseManager.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ var MouseManager = new Class({
1111
{
1212
this.manager = inputManager;
1313

14+
/**
15+
* @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully.
16+
*/
17+
this.capture = false;
18+
1419
this.enabled = false;
1520

1621
this.target;
@@ -30,16 +35,33 @@ var MouseManager = new Class({
3035
this.target = this.manager.game.canvas;
3136
}
3237

38+
if (config.disableContextMenu)
39+
{
40+
this.disableContextMenu();
41+
}
42+
3343
if (this.enabled)
3444
{
3545
this.startListeners();
3646
}
3747
},
3848

49+
disableContextMenu: function ()
50+
{
51+
document.body.addEventListener('contextmenu', function (event) {
52+
event.preventDefault();
53+
return false;
54+
});
55+
56+
return this;
57+
},
58+
3959
startListeners: function ()
4060
{
4161
var queue = this.manager.queue;
4262

63+
var _this = this;
64+
4365
var handler = function (event)
4466
{
4567
if (event.preventDefaulted)
@@ -49,6 +71,11 @@ var MouseManager = new Class({
4971
}
5072

5173
queue.push(event);
74+
75+
if (_this.capture)
76+
{
77+
event.preventDefault();
78+
}
5279
};
5380

5481
this.handler = handler;

0 commit comments

Comments
 (0)