-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdw.js
79 lines (67 loc) · 2.37 KB
/
dw.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(function($, undefined){
"use strict";
var autoScrolling = false;
var manualSideNavControl = false;
function updateHeader(title) {
$(".menu-logo").toggleClass("active", !title);
$("header .header-logo").text(title || "DataWorker");
}
function handleScrolledToTop(isAtTop) {
var $fbtn = $(".fbtn-container");
$fbtn.toggleClass("not-visible", isAtTop).attr("aria-hidden", isAtTop);
if (isAtTop && !manualSideNavControl) {
$("#side-nav .collapse").collapse("hide");
}
}
function scrollToTarget(e, hash) {
var isPopState = e.type === "popstate";
if (isPopState) {
hash = window.location.hash;
}
var $target = $("section" + hash);
if ($target.length) {
autoScrolling = true;
$("html, body").animate({ scrollTop: $target.offset().top }, 500, function () {
autoScrolling = false;
});
// Prevent browser from scrolling to target and back before animating
if (!isPopState && window.history && window.history.pushState) {
window.history.pushState(null, "", hash);
e.preventDefault();
}
}
}
window.onpopstate = scrollToTarget;
$(document)
// Close mobile side-nav on navigation
.on("click", "#side-nav a:not([data-toggle])", function() {
$("#side-nav").trigger("click.dismiss.bs.menu");
})
// Refresh scrollspy when side-nav is opened
.on("shown.bs.menu", function() {
$("body").scrollspy("refresh");
})
// Create accordion effect in side-nav
.on("show.bs.collapse", "#side-nav .collapse", function() {
$("#side-nav .collapse.in").collapse("hide");
})
// Animate scrolling to target
.on("click", 'a[href^="#"]', function (e) {
// Prevent auto-expanding on scroll when user manually toggled a section
manualSideNavControl = $(this).data("toggle") === "collapse";
scrollToTarget(e, $(this).attr("href"));
})
// Handle scrollspy events
.on("activate.bs.scrollspy", "#side-nav li", function() {
var hash = $("a", this).attr("href");
// Update header title to match current section
if ($("section" + hash).length) {
updateHeader($(this).text().trim());
handleScrolledToTop(hash === "#top");
}
// Auto-expand side-nav
if (!autoScrolling && !manualSideNavControl) {
$(this).closest(".collapse").collapse("show");
}
})
})(jQuery);