From aa86d7005b485cfcc31f6787f24ef75d9ea97031 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 16 Apr 2013 00:29:20 +0200 Subject: [PATCH] Added fix for browser's jump-to-anchor --- wcfsetup/install/files/js/WCF.js | 34 +++++++++++++++++++++--- wcfsetup/install/files/style/layout.less | 7 +++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 1c359e41b0..f52113ea19 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -4055,9 +4055,10 @@ WCF.Effect.Scroll = Class.extend({ * * @param jQuery element * @param boolean excludeMenuHeight + * @param boolean disableAnimation * @return boolean */ - scrollTo: function(element, excludeMenuHeight) { + scrollTo: function(element, excludeMenuHeight, disableAnimation) { if (!element.length) { return true; } @@ -4078,9 +4079,14 @@ WCF.Effect.Scroll = Class.extend({ } } - $('html,body').animate({ scrollTop: $elementOffset }, 400, function (x, t, b, c, d) { - return -c * ( ( t = t / d - 1 ) * t * t * t - 1) + b; - }); + if (disableAnimation === true) { + $('html,body').scrollTop($elementOffset); + } + else { + $('html,body').animate({ scrollTop: $elementOffset }, 400, function (x, t, b, c, d) { + return -c * ( ( t = t / d - 1 ) * t * t * t - 1) + b; + }); + } return false; } @@ -5166,6 +5172,26 @@ WCF.Search.User = WCF.Search.Base.extend({ */ WCF.System = { }; +/** + * Fixes scroll offset on page load. + */ +WCF.System.JumpToAnchor = { + execute: function() { + if (window.location.hash) { + var $element = $(window.location.hash); + if ($element.length) { + $element.addClass('userPanelJumpToAnchorFix'); + + new WCF.PeriodicalExecuter(function(pe) { + pe.stop(); + + $element.removeClass('userPanelJumpToAnchorFix'); + }, 5000); + } + } + } +}; + /** * System notification overlays. * diff --git a/wcfsetup/install/files/style/layout.less b/wcfsetup/install/files/style/layout.less index 278c41c619..c47aea12d8 100644 --- a/wcfsetup/install/files/style/layout.less +++ b/wcfsetup/install/files/style/layout.less @@ -148,6 +148,13 @@ } } +.userPanelJumpToAnchorFix:before { + content: ""; + display: block; + height: 40px; + margin-top: -40px; +} + @media only screen and (max-width: 768px) { .userPanel { height: auto; -- 2.20.1