Skip to content

Commit 85596fd

Browse files
committed
Correcting comments and clearing the code of the sticky navbar.
1 parent bc58c5b commit 85596fd

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

javascripts/_jbossorg-navbarfix.js

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,72 @@
11
/*
2-
* This script prevents a navbar with the #navbar-fix identifier
2+
* This script prevents a navbar with the #sticky-navbar identifier
33
* from scrolling off the top of the browser window. It does this by
4-
* detecting when that's about to occur and creating a copy that's
5-
* added to the page with a fixed position, aligned to the top of
4+
* detecting when that's about to occur and switching a style class
5+
* which sets it at a fixed position, aligned to the top of
66
* the page.
77
*
8-
* When the user scrolls back up then this copy is
9-
* removed so the normal navbar is fully visible again.
8+
* When the user scrolls back up then this style class is switched
9+
* back so the normal navbar is fully visible again.
1010
*
1111
* Because you can't scroll the fixed copy we're not able to use this
1212
* for the collapsed navigation where menu items are shown vertically.
1313
*/
1414

1515
var isNavBarFixed = 0;
1616

17-
var defaultNavbarOffset = $("#sticky-navbar").offset().top;
17+
var defaultNavbarOffset = $("#sticky-navbar").length ? $("#sticky-navbar").offset().top : 0 ;
1818

1919
processScroll();
2020
$(window).on('scroll', processScroll);
2121

2222
function processScroll() {
2323

2424
var navbar = $("#sticky-navbar");
25-
var breadcrumb = $(".breadcrumb");
25+
26+
if (navbar.length==0) {
27+
return
28+
}
29+
30+
var breadcrumb;
2631

2732
if (isNavBarFixed) {
2833
breadcrumb = $(".breadcrumb-fixed");
34+
} else {
35+
breadcrumb = $(".breadcrumb");
2936
}
3037

31-
if (navbar == null || typeof (navbar.offset()) == "undefined" ) {
32-
return
33-
}
34-
38+
// Measuring additionall offset depending whether tabzilla exists and is open.
3539
var additionalTabzillaOffset = 0;
3640
var tabzilla = $('#tabnav-panel');
37-
if (typeof tabzilla != undefined) {
41+
if (tabzilla.length) {
3842
if (tabzilla.hasClass('tabnav-opened')) {
3943
additionalTabzillaOffset=240;
4044
}
4145
}
4246

4347
// Tabzilla offset needs to bo added if it's open.
4448
if (!isNavBarFixed && $(window).scrollTop() >= (defaultNavbarOffset + additionalTabzillaOffset) ) {
49+
50+
// Switching navbar style to fixed position at the top.
4551
navbar.addClass("navbar-fixed");
4652
navbar.removeClass("navbar-fix");
53+
54+
// Trick in order to prevent content movement when the navigation starts to scroll.
4755
breadcrumb.addClass("breadcrumb-fixed");
4856
breadcrumb.removeClass("breadcrumb");
57+
4958
isNavBarFixed = 1;
59+
5060
} else if (isNavBarFixed && $(window).scrollTop() < (defaultNavbarOffset + additionalTabzillaOffset) ) {
61+
62+
// Switching navbar style to non-fixed position.
5163
navbar.addClass("navbar-fix");
5264
navbar.removeClass("navbar-fixed");
65+
5366
breadcrumb.removeClass("breadcrumb-fixed");
5467
breadcrumb.addClass("breadcrumb");
55-
isNavBarFixed = 0
68+
69+
isNavBarFixed = 0;
70+
5671
}
5772
}

0 commit comments

Comments
 (0)