Future-proof redirection to fragments in Gecko
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 19 Mar 2010 20:45:29 +0000 (20:45 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 19 Mar 2010 20:45:29 +0000 (20:45 +0000)
Previously, in Gecko we wouldn't set document.location.hash at all until
the page loaded.  This means that if they fix their bug, so setting
document.location.hash to an id that doesn't yet exist (but will before
load is finished) works properly, we still would only jump to the right
place onload, not ASAP.  Now we'll jump to the right place ASAP, and
then jump again on load, which is better (although still annoying if the
gap ends up being perceptible).

Too bad I can't think of a way to feature-test this.

RELEASE-NOTES
skins/common/wikibits.js

index 1045b40..d6e7564 100644 (file)
@@ -32,6 +32,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   options
 * $wgAllowUserCssPrefs option allows disabling CSS-based preferences; which can
   improve page loading speed.
+* Future-proof redirection to fragments in Gecko, so things work a little nicer
+  if they fix <https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
 
 === Bug fixes in 1.17 ===
 * (bug 17560) Half-broken deletion moved image files to deletion archive without
index 7cee761..2a75478 100644 (file)
@@ -497,16 +497,21 @@ function redirectToFragment( fragment ) {
                        return;
                }
        }
-       if ( is_gecko ) {
-               // Mozilla needs to wait until after load, otherwise the window doesn't scroll
-               addOnloadHook(function() {
-                       if ( window.location.hash == '' ) {
-                               window.location.hash = fragment;
-                       }
-               });
-       } else {
-               if ( window.location.hash == '' ) {
-                       window.location.hash = fragment;
+       if ( window.location.hash == '' ) {
+               window.location.hash = fragment;
+
+               // Mozilla needs to wait until after load, otherwise the window doesn't
+               // scroll.  See <https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
+               // There's no obvious way to detect this programmatically, so we use
+               // version-testing.  If Firefox fixes the bug, they'll jump twice, but
+               // better twice than not at all, so make the fix hit future versions as
+               // well.
+               if ( is_gecko ) {
+                       addOnloadHook(function() {
+                               if ( window.location.hash == fragment ) {
+                                       window.location.hash = fragment;
+                               }
+                       });
                }
        }
 }