Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions resources/assets/js/components/chapter-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,56 @@ class ChapterToggle {
}

open() {
let list = this.elem.parentNode.querySelector('.inset-list');
const list = this.elem.parentNode.querySelector('.inset-list');

this.elem.classList.add('open');
list.style.display = 'block';
list.style.height = '';
let height = list.getBoundingClientRect().height;
list.style.height = '0px';
list.style.maxHeight = '';
const maxHeight = list.getBoundingClientRect().height + 10;
list.style.maxHeight = '0px';
list.style.overflow = 'hidden';
list.style.transition = 'height ease-in-out 240ms';
list.style.transition = 'max-height ease-in-out 240ms';

let transitionEndBound = onTransitionEnd.bind(this);
function onTransitionEnd() {
list.style.overflow = '';
list.style.height = '';
list.style.maxHeight = '';
list.style.transition = '';
list.style.display = `block`;
list.removeEventListener('transitionend', transitionEndBound);
}

setTimeout(() => {
list.style.height = `${height}px`;
list.addEventListener('transitionend', transitionEndBound)
requestAnimationFrame(() => {
list.style.maxHeight = `${maxHeight}px`;
list.addEventListener('transitionend', transitionEndBound)
});
}, 1);
}

close() {
let list = this.elem.parentNode.querySelector('.inset-list');
const list = this.elem.parentNode.querySelector('.inset-list');

this.elem.classList.remove('open');
list.style.display = 'block';
list.style.height = list.getBoundingClientRect().height + 'px';
this.elem.classList.remove('open');
list.style.maxHeight = list.getBoundingClientRect().height + 'px';
list.style.overflow = 'hidden';
list.style.transition = 'height ease-in-out 240ms';
list.style.transition = 'max-height ease-in-out 240ms';

let transitionEndBound = onTransitionEnd.bind(this);
const transitionEndBound = onTransitionEnd.bind(this);
function onTransitionEnd() {
list.style.overflow = '';
list.style.height = '';
list.style.maxHeight = '';
list.style.transition = '';
list.style.display = 'none';
list.removeEventListener('transitionend', transitionEndBound);
}

setTimeout(() => {
list.style.height = `0px`;
list.addEventListener('transitionend', transitionEndBound)
requestAnimationFrame(() => {
list.style.maxHeight = `0px`;
list.addEventListener('transitionend', transitionEndBound)
});
}, 1);
}

Expand All @@ -64,4 +69,4 @@ class ChapterToggle {

}

module.exports = ChapterToggle;
module.exports = ChapterToggle;
2 changes: 1 addition & 1 deletion resources/assets/sass/_lists.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
display: none;
padding-left: 0;
}
.sub-menu.open {
[chapter-toggle].open + .sub-menu {
display: block;
}
}
Expand Down