-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbreadcrumbs.js
More file actions
82 lines (62 loc) · 1.67 KB
/
breadcrumbs.js
File metadata and controls
82 lines (62 loc) · 1.67 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
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
80
81
82
/* Simple Breadcrumbs
licensed under MIT.
by Evan Myller (emyller@7ws.co)
*/
+function ($) {
'use strict';
function reset(item) {
if (!item)
item = $('ul.simplebreadcrumb');
// hide all subitems
$('ul', item).hide();
// unset items' 'selected' state
$('li', item).show().removeClass('selected current');
// reset style values
$('ul,li', item).css({height: 'auto', width: 'auto'});
}
//add a class to identify dead end entries
$('ul.simplebreadcrumb li').addClass('_has_no_subitems');
$('ul.simplebreadcrumb li:has(ul)') // items with submenus
// add a class to identify them
.removeClass('_has_no_subitems')
.addClass('_has_subitems')
.on('click', function (e) {
// prevent any activation
e.preventDefault();
var item = $(this),
handle = item.children(':first');
// do nothing if the click wasn't fired on the handle
if (!(handle[0] === e.target || $.contains(handle, e.target)))
return;
// toggle 'selected' state
item.toggleClass('selected');
// toggle 'current' state
if (item.is('.selected')) {
item.parents('li').removeClass('current');
item.addClass('current');
}
else {
item.parent().closest('li').addClass('current');
item.removeClass('current');
}
// determine which axis do the folding based on subitems' display
var folding = !$('li', item).css('display').indexOf('inline')
? {width: 'toggle'}
: {height: 'toggle'};
item.children('ul').animate(
folding,
{
queue: false,
duration: 250,
done: function () {
item.siblings().animate(
folding,
{queue: false}
);
!item.is('.selected') && reset(item);
}
});
});
// reset items by default
reset();
}(jQuery);