forked from dhondta/python-codext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollapsible-navbar.js
More file actions
54 lines (53 loc) · 1.8 KB
/
Copy pathcollapsible-navbar.js
File metadata and controls
54 lines (53 loc) · 1.8 KB
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
String.prototype.format = function() {
a = this;
for (k in arguments) {
a = a.replace("{" + k + "}", arguments[k])
}
return a
}
$(document).ready(function () {
$('li.toctree-l1').each(function () {
var parent = $(this);
var span = parent.find('span:first');
var sibling = null;
var remove = true;
$('li.toctree-l1').each(function() {
var a = $(this).find('a:first');
if (a.text() != '' && a.text() == span.text()) {
parent.prepend(a);
span.remove();
span = a;
if ($(this).hasClass('current')) parent.addClass('current');
sibling = $(this);
return false
}
});
if (sibling === null && parent.find('ul.subnav:not(li.toctree-l2)').children('li').length) {
sibling = parent;
remove = false;
}
if (sibling !== null) {
var ul = parent.find('ul.subnav:not(li.toctree-l2)');
var new_a = '<a class="fa fa-caret-{0} collapse-navbar" href="#" style="display: inline-block; position: absolute; width: auto; right: 0; margin-right: 2px; padding-left: 2px; padding-right: 2px; z-index: 1001;"></a>';
if (!ul.children('li.current').length && !parent.hasClass('current')) {
ul.hide();
$(new_a.format("left")).insertBefore(span);
} else {
$(new_a.format("down")).insertBefore(span);
}
if (remove) sibling.remove();
}
});
$('a.collapse-navbar').click(function () {
var parent = $(this).closest('li.toctree-l1');
var subnav = parent.find('ul.subnav:not(li.toctree-l2)');
if ($(this).hasClass('fa-caret-left')) {
subnav.show();
$(this).removeClass('fa-caret-left');
$(this).addClass('fa-caret-down');
} else {
subnav.hide();
$(this).addClass('fa-caret-left');
$(this).removeClass('fa-caret-down');
}
});});