forked from tidyverse/dplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkgdown.js
49 lines (39 loc) · 1.08 KB
/
pkgdown.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
$(function() {
$("#sidebar").stick_in_parent({
offset_top: $("#sidebar").offset().top
});
$('body').scrollspy({
target: '#sidebar'
});
var cur_path = paths(location.pathname);
$("#navbar ul li a").each(function(index, value) {
if (value.text == "Home")
return;
if (value.getAttribute("href") === "#")
return;
var path = paths(value.pathname);
if (is_prefix(cur_path, path)) {
// Add class to parent <li>, and enclosing <li> if in dropdown
var menu_anchor = $(value);
menu_anchor.parent().addClass("active");
menu_anchor.closest("li.dropdown").addClass("active");
}
});
});
function paths(pathname) {
var pieces = pathname.split("/");
pieces.shift(); // always starts with /
var end = pieces[pieces.length - 1];
if (end === "index.html" || end === "")
pieces.pop();
return(pieces);
}
function is_prefix(needle, haystack) {
if (needle.length > haystack.lengh)
return(false);
for (var i = 0; i < haystack.length; i++) {
if (needle[i] != haystack[i])
return(false);
}
return(true);
}