This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
collapsibleListSet.js
37 lines (32 loc) · 1.82 KB
/
collapsibleListSet.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
// collapsibleListSet is a container that wraps two elements: label and list.
// The label toggles the collapsed state of the list.
// This also scans for any children that is the currentItem
// ('.js-collapsibleListSet__list li.is-currentItem'). If any of these items
// are present, then the collapsibleListSet's classes will be all removed.
// The reason is for this is due to limitations on how we can style multi level
// nested items that take up an absolute space relative to an item that is not
// the collapsibleListSet. (see `.pageNavList__item.is-currentItem` and
// `.pageNavListBounder`).
// A collapsibleListSet's classes can also be removed if it is a child of another
// collapsibleListSet.
(function() {
$('.js-collapsibleListSet').each(function(index, container) {
var $container = $(container);
var $label = $container.find('> .js-collapsibleListSet__label');
var $list = $container.find('> .js-collapsibleListSet__list');
if ($container.parents('.js-collapsibleListSet, .js-collapsibleListSet--nullified').length > 0
|| $list.find('.is-currentItem').length > 0) {
$container.removeClass('collapsibleListSet js-collapsibleListSet');
$container.addClass('js-collapsibleListSet--nullified');
$container.find('> .js-collapsibleListSet__label').removeClass('collapsibleListSet__label is-collapsed js-collapsibleListSet__label');
$container.find('> .js-collapsibleListSet__list').removeClass('collapsibleListSet__list is-collapsed js-collapsibleListSet__list');
return;
}
$label.click(function() {
// Set up the element to transition to a set max-height. This is necessary
// because it is not possible to use pure css to animate height.
$list.css('max-height', $list[0].scrollHeight);
$([$label, $list]).toggleClass('is-collapsed');
});
});
})();