Added option to disable context menu

Added to both the game config and as a function in the Mouse Manager.
This commit is contained in:
Richard Davey 2017-07-25 12:33:37 +01:00
parent 1b4e53d06f
commit 87edd6cb94
3 changed files with 30 additions and 1 deletions

View file

@ -58,6 +58,8 @@ var Config = new Class({
this.inputMouse = GetValue(config, 'input.mouse', true);
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
this.disableContextMenu = GetValue(config, 'disableContextMenu', false);
// If you do: { banner: false } it won't display any banner at all
this.hideBanner = (GetValue(config, 'banner', null) === false);

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: 'ef2515e0-70eb-11e7-ad8e-3beabf57a909'
build: 'ac7c3390-712c-11e7-94b3-cb219d37da47'
};
module.exports = CHECKSUM;

View file

@ -11,6 +11,11 @@ var MouseManager = new Class({
{
this.manager = inputManager;
/**
* @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully.
*/
this.capture = false;
this.enabled = false;
this.target;
@ -30,16 +35,33 @@ var MouseManager = new Class({
this.target = this.manager.game.canvas;
}
if (config.disableContextMenu)
{
this.disableContextMenu();
}
if (this.enabled)
{
this.startListeners();
}
},
disableContextMenu: function ()
{
document.body.addEventListener('contextmenu', function (event) {
event.preventDefault();
return false;
});
return this;
},
startListeners: function ()
{
var queue = this.manager.queue;
var _this = this;
var handler = function (event)
{
if (event.preventDefaulted)
@ -49,6 +71,11 @@ var MouseManager = new Class({
}
queue.push(event);
if (_this.capture)
{
event.preventDefault();
}
};
this.handler = handler;