forked from metacpan/metacpan-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbar.js
38 lines (33 loc) · 1.36 KB
/
toolbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$(function() {
var el = $('.nav-list').first();
var topRow = $('.main-content').first();
if (!el.length) return;
var height = el.height();
var content = $("div.content");
if (!content.length) return;
var right_panel = $("#right-panel");
if (right_panel.length && right_panel.height() > content.height()) {
content = right_panel;
}
if(height > content.height()) return;
function alignSidebar(e) {
var scrollTop = $(window).scrollTop();
var screenHeight = $(window).height();
var contentTop = content.offset().top;
var contentHeight = content.height();
if (height > contentHeight || scrollTop < contentTop + (height > screenHeight ? height - screenHeight : 0)) {
el.addClass("sticky-panel-top").removeClass("sticky-panel-bottom sticky-panel-sticky");
}
else if (scrollTop + height > contentTop + contentHeight) {
el.addClass("sticky-panel-bottom").removeClass("sticky-panel-top sticky-panel-sticky");
}
else if (height > screenHeight) {
el.addClass("sticky-panel-bottom sticky-panel-sticky").removeClass("sticky-panel-top");
}
else {
el.addClass("sticky-panel-sticky sticky-panel-top").removeClass("sticky-panel-bottom");
}
};
$(window).scroll(alignSidebar);
alignSidebar();
});