Skip to content

Commit 4e19596

Browse files
committed
Attempt adjust scroll position for anchors with top-bar active
1 parent da996b3 commit 4e19596

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

pbtech/template/overall_footer.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ <h3 class="alert_title">&nbsp;</h3><p class="alert_text"></p>
5050
jQuery(function($) {
5151
'use strict';
5252

53+
/* Anchor jump offset for top-bar */
54+
function scroll_if_anchor(href) {
55+
href = typeof(href) == "string" ? href : $(this).attr("href");
56+
57+
if(!href) return;
58+
var fromTop = $topBarHeight + 4;
59+
var $target = $(href);
60+
61+
// Older browsers without pushState might flicker here, as they momentarily jump to the wrong position (IE < 10)
62+
if($target.length) {
63+
$('html, body').scrollTop($target.offset().top - fromTop);
64+
if(history && "pushState" in history) {
65+
history.pushState({}, document.title, window.location.href.split("#")[0] + href);
66+
//window.location.hash = href;
67+
return false;
68+
}
69+
}
70+
}
71+
72+
var $topBar = $('#top-bar');
73+
var $topBarHeight = 0;
74+
75+
if ($topBar.length) {
76+
$topBarHeight = $topBar.outerHeight();
77+
78+
$("body").on("click", "a[href^='#']", scroll_if_anchor);
79+
80+
scroll_if_anchor(window.location.hash);
81+
}
82+
83+
/* Collapse boxes */
5384
$('.stat-block.online-list').attr('id', 'online-list');
5485
$('.stat-block.birthday-list').attr('id', 'birthday-list');
5586
$('.stat-block.statistics').attr('id', 'statistics');
@@ -71,6 +102,7 @@ <h3 class="alert_title">&nbsp;</h3><p class="alert_text"></p>
71102
});
72103

73104
<!-- IF S_VIEWTOPIC -->
105+
/* Mini-profile context drop-down menus */
74106
phpbb.dropdownVisibleContainers += ', .profile-context';
75107

76108
$('.postprofile').each(function() {

0 commit comments

Comments
 (0)