Commits

Eric Fredricksen committed be6d7a4

Get firefox working again. Fullscreen isnt very full screen, tho

Comments (0)

Files changed (2)

 <html>
 
 <head>
+<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
+<meta content="utf-8" http-equiv="encoding">
 <title>Halfblock</title>
 <script type="text/javascript" src="gl-matrix.js"></script>
 <script type="text/javascript" src="perlin.js"></script>
 
 
 function togglePointerLock() {
-  if (cancan.requestPointerLock) {
-    if (window.pointerLocked)
-      document.exitPointerLock();
-    else
-      cancan.requestPointerLock();
-  }
+  if (!cancan.requestPointerLock) return;  // not supported
+
+  if (window.pointerLockRequiresFullscreen && 
+      !window.pointerLocked && 
+      !window.fullscreen)
+    cancan.requestFullscreen();
+  else if (!window.pointerLocked)
+    cancan.requestPointerLock();
+  else
+    document.exitPointerLock();
 }
 
 
   document.exitPointerLock = document.exitPointerLock ||
     document.mozExitPointerLock ||
     document.webkitExitPointerLock;
+  window.pointerLockRequiresFullscreen = !!cancan.mozRequestPointerLock;
 
   window.addEventListener('keydown', onkeydown, true);
   window.addEventListener('keyup',   onkeyup,   true);
   if (window.pointerLocked && GAME && !GAME.loading) {
     var movementX = event.movementX || 
       event.mozMovementX || 
-      event.webkitMovementX;
+      event.webkitMovementX ||
+      0;
     var movementY = event.movementY || 
       event.mozMovementY ||
-      event.webkitMovementY;
+      event.webkitMovementY ||
+      0;
     var spinRate = 0.01;
     AVATAR.yaw += movementX * spinRate;
     AVATAR.pitch += movementY * spinRate;
 }
 
 function fullscreenChange() {
-  AVATAR.fullscreen = (document.webkitFullscreenElement || 
+  window.fullscreen = (document.webkitFullscreenElement || 
                        document.mozFullscreenElement ||
                        document.mozFullScreenElement) === cancan;
+  if (window.pointerLockRequiresFullscreen && 
+      window.fullscreen &&
+      !window.pointerLocked) {
+    togglePointerLock();
+  }
 }
 
 function pointerLockChange() {