aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-20 07:43:24 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-20 07:43:24 -0700
commitd94b8c098ae434a3f1187ec9a96d431d52461fd4 (patch)
tree524fdbea7b7cffefbdfbd7bb03a5d56e9d17e74b /src
parentcc8858d0e0aaa3dbfd24a9c900db8746a23d6353 (diff)
parent5762096f05b3f6def9ca82688840bf5b87ca0f85 (diff)
Merge pull request #970 from vvuk/non-fs-pointer-lock
teach library_browser about non-fullscreen pointerlock if Module.element PointerLock is true
Diffstat (limited to 'src')
-rw-r--r--src/library_browser.js46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index bdd94bac..5526456a 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -193,6 +193,35 @@ mergeInto(LibraryManager.library, {
}
};
Module['preloadPlugins'].push(audioPlugin);
+
+ // is this the right place?
+ var canvas = Module['canvas'];
+ canvas.requestPointerLock = canvas['requestPointerLock'] ||
+ canvas['mozRequestPointerLock'] ||
+ canvas['webkitRequestPointerLock'];
+ canvas.exitPointerLock = document['exitPointerLock'] ||
+ document['mozExitPointerLock'] ||
+ document['webkitExitPointerLock'];
+ canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
+
+ function pointerLockChange() {
+ Browser.pointerLock = document['pointerLockElement'] === canvas ||
+ document['mozPointerLockElement'] === canvas ||
+ document['webkitPointerLockElement'] === canvas;
+ }
+
+ document.addEventListener('pointerlockchange', pointerLockChange, false);
+ document.addEventListener('mozpointerlockchange', pointerLockChange, false);
+ document.addEventListener('webkitpointerlockchange', pointerLockChange, false);
+
+ if (Module['elementPointerLock']) {
+ canvas.addEventListener("click", function(ev) {
+ if (!Browser.pointerLock && canvas.requestPointerLock) {
+ canvas.requestPointerLock();
+ ev.preventDefault();
+ }
+ }, false);
+ }
},
createContext: function(canvas, useWebGL, setInModule) {
@@ -292,13 +321,6 @@ mergeInto(LibraryManager.library, {
if ((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
document['fullScreenElement'] || document['fullscreenElement']) === canvas) {
- canvas.requestPointerLock = canvas['requestPointerLock'] ||
- canvas['mozRequestPointerLock'] ||
- canvas['webkitRequestPointerLock'];
- canvas.exitPointerLock = document['exitPointerLock'] ||
- document['mozExitPointerLock'] ||
- document['webkitExitPointerLock'];
- canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
canvas.cancelFullScreen = document['cancelFullScreen'] ||
document['mozCancelFullScreen'] ||
document['webkitCancelFullScreen'];
@@ -312,21 +334,11 @@ mergeInto(LibraryManager.library, {
if (Module['onFullScreen']) Module['onFullScreen'](Browser.isFullScreen);
}
- function pointerLockChange() {
- Browser.pointerLock = document['pointerLockElement'] === canvas ||
- document['mozPointerLockElement'] === canvas ||
- document['webkitPointerLockElement'] === canvas;
- }
-
if (!this.fullScreenHandlersInstalled) {
this.fullScreenHandlersInstalled = true;
document.addEventListener('fullscreenchange', fullScreenChange, false);
document.addEventListener('mozfullscreenchange', fullScreenChange, false);
document.addEventListener('webkitfullscreenchange', fullScreenChange, false);
-
- document.addEventListener('pointerlockchange', pointerLockChange, false);
- document.addEventListener('mozpointerlockchange', pointerLockChange, false);
- document.addEventListener('webkitpointerlockchange', pointerLockChange, false);
}
canvas.requestFullScreen = canvas['requestFullScreen'] ||