-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathguide.js
72 lines (65 loc) · 1.83 KB
/
guide.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
$(function () {
function closeSubItems (which) {
var $which = $('nav#guide #' + which + '.subitems');
$('nav#guide #' + which + '.item.primary').removeClass('expanded');
$which.find('.item.secondary').each(function () {
$(this)
.stop()
.animate({
height: 0
, opacity: 0
}, 200, function () {
$(this).removeClass('expanded');
$(this)
.hide()
.css({
height: ''
, opacity: ''
});
});
});
}
function openSubItems (which) {
var $which = $('nav#guide #' + which + '.subitems');
$('nav#guide #' + which + '.item.primary').addClass('expanded');
$which.find('.item.secondary').each(function () {
$(this)
.filter(':hidden')
.css({
height: 0
, opacity: 0
, display: 'block'
})
.show();
$(this)
.stop()
.animate({
height: 24
, opacity: 1
}, 200, function () {
$(this).addClass('expanded');
});
});
}
var current = '';
$('nav#guide .item.primary').each(function () {
var id = $(this).attr('id');
if ($(this).hasClass('active')) current = id;
});
$('nav#guide .item.primary span').click(function (e) {
e.preventDefault();
var action = ($(this).hasClass('expand')) ? 'expand' : 'collapse';
if (action === 'expand') {
var $parent = $(this).parent('.item.primary')
, id = $parent.attr('id')
, $list = $parent.next('#' + id + '.subitems');
if (current.length) closeSubItems(current);
current = id;
openSubItems(current);
} else if (action === 'collapse') {
var $parent = $(this).parent('.item.primary')
, id = $parent.attr('id');
closeSubItems(id);
}
});
});