chuck.js/app/Game/Client/PointerLockManager.js
logsol 3cb2e39a18 Makes singleton variable name of NotificationCenter lowercase
When we require a singleton, its instance name should be named
by lowercase, since it is not a class.

Relates to #128
2016-10-10 22:11:55 +02:00

53 lines
No EOL
1.6 KiB
JavaScript

define([
"Lib/Utilities/QuerySelector",
"Lib/Utilities/NotificationCenter"
],
function (Qs, nc) {
"use strict";
function PointerLockManager() {
this.canvas = Qs.$("#canvas");
this.listeners = [];
if (!document) {
throw new Error("Using PointerLockManager, but window.document is not defined.");
}
document.addEventListener('pointerlockchange', this.update.bind(this), false);
document.addEventListener('mozpointerlockchange', this.update.bind(this), false);
document.addEventListener('webkitpointerlockchange', this.update.bind(this), false);
this.ncTokens = [
nc.on(nc.ns.client.pointerLock.request, this.request, this)
];
}
PointerLockManager.prototype.request = function() {
var canvas = this.canvas;
canvas.requestPointerLock = canvas.requestPointerLock ||
canvas.mozRequestPointerLock ||
canvas.webkitRequestPointerLock;
// Ask the browser to lock the pointer
canvas.requestPointerLock();
}
// called by the browser event and others
PointerLockManager.prototype.update = function(e, options) {
options = options ? options : {};
nc.trigger(nc.ns.client.pointerLock.change, this.isLocked(), options);
};
PointerLockManager.prototype.isLocked = function() {
return document.pointerLockElement === this.canvas ||
document.mozPointerLockElement === this.canvas ||
document.webkitPointerLockElement === this.canvas;
};
return new PointerLockManager();
});