Improved initial jump to an anchor
authorAlexander Ebert <ebert@woltlab.com>
Mon, 13 May 2013 17:49:14 +0000 (19:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 13 May 2013 17:49:14 +0000 (19:49 +0200)
wcfsetup/install/files/js/WCF.js

index 852ff9bea772b473c74a158d82846009c25ed81f..5285678dede2c924ce00d6c2c840618c269107c3 100755 (executable)
@@ -5508,13 +5508,23 @@ WCF.System.JumpToAnchor = {
                if (window.location.hash) {
                        var $element = $(window.location.hash);
                        if ($element.length) {
-                               $element.addClass('userPanelJumpToAnchorFix');
-                               
-                               new WCF.PeriodicalExecuter(function(pe) {
-                                       pe.stop();
+                               if ($.browser.chrome || $.browser.msie) {
+                                       $element.addClass('userPanelJumpToAnchorFix');
                                        
-                                       $element.removeClass('userPanelJumpToAnchorFix');
-                               }, 5000);
+                                       $(document).on('readystatechange', function() {
+                                               if (document.readyState === 'complete') {
+                                                       // wait 100ms
+                                                       new WCF.PeriodicalExecuter(function(pe) {
+                                                               pe.stop();
+                                                               
+                                                               $element.removeClass('userPanelJumpToAnchorFix');
+                                                       }, 100);
+                                               }
+                                       });
+                               }
+                               else {
+                                       window.scrollBy(0, -1 * $('.userPanel').outerHeight());
+                               }
                        }
                }
        }