MDL-34590 javascript-static: nuclear option in openpopup
authorTim Hunt <T.J.Hunt@open.ac.uk>
Thu, 9 Aug 2012 11:52:11 +0000 (12:52 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 9 Aug 2012 15:17:36 +0000 (17:17 +0200)
I think we have finally tamed Chrome on all platforms. (Crosses fingers.)

lib/javascript-static.js

index f802776..6e7042d 100644 (file)
@@ -1195,10 +1195,29 @@ function openpopup(event, args) {
     }
 
     if (args.fullscreen) {
-        setTimeout(function() {
+        // In some browser / OS combinations (E.g. Chrome on Windows), the
+        // window initially opens slighly too big. The width and heigh options
+        // seem to control the area inside the browser window, so what with
+        // scroll-bars, etc. the actual window is bigger than the screen.
+        // Therefore, we need to fix things up after the window is open.
+        var hackcount = 100;
+        var get_size_exactly_right = function() {
             windowobj.moveTo(0, 0);
-            windowobj.resizeTo(screen.availWidth, screen.availHeight)
-        }, 0);
+            windowobj.resizeTo(screen.availWidth, screen.availHeight);
+
+            // Unfortunately, it seems that in Chrome on Ubuntu, if you call
+            // something like windowobj.resizeTo(1280, 1024) too soon (up to
+            // about 50ms) after the window is open, then it actually behaves
+            // as if you called windowobj.resizeTo(0, 0). Therefore, we need to
+            // check that the resize actually worked, and if not, repeatedly try
+            // again after a short delay until it works (but with a limit of
+            // hackcount repeats.
+            if (hackcount > 0 && (windowobj.innerHeight < 10 || windowobj.innerWidth < 10)) {
+                hackcount -= 1;
+                setTimeout(get_size_exactly_right, 10);
+            }
+        }
+        setTimeout(get_size_exactly_right, 0);
     }
     windowobj.focus();