X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/4a872012c5568c59aec7dc9825bee28902ce3431..refs/pull/1626/head:/resources/assets/js/components/chapter-toggle.js diff --git a/resources/assets/js/components/chapter-toggle.js b/resources/assets/js/components/chapter-toggle.js index 350c453ac..bfd0ac729 100644 --- a/resources/assets/js/components/chapter-toggle.js +++ b/resources/assets/js/components/chapter-toggle.js @@ -1,3 +1,4 @@ +import {slideUp, slideDown} from "../services/animations"; class ChapterToggle { @@ -9,56 +10,16 @@ class ChapterToggle { open() { const list = this.elem.parentNode.querySelector('.inset-list'); - this.elem.classList.add('open'); - list.style.display = 'block'; - list.style.maxHeight = ''; - const maxHeight = list.getBoundingClientRect().height + 10; - list.style.maxHeight = '0px'; - list.style.overflow = 'hidden'; - list.style.transition = 'max-height ease-in-out 240ms'; - - let transitionEndBound = onTransitionEnd.bind(this); - function onTransitionEnd() { - list.style.overflow = ''; - list.style.maxHeight = ''; - list.style.transition = ''; - list.style.display = `block`; - list.removeEventListener('transitionend', transitionEndBound); - } - - setTimeout(() => { - requestAnimationFrame(() => { - list.style.maxHeight = `${maxHeight}px`; - list.addEventListener('transitionend', transitionEndBound) - }); - }, 1); + this.elem.setAttribute('aria-expanded', 'true'); + slideDown(list, 240); } close() { const list = this.elem.parentNode.querySelector('.inset-list'); - - list.style.display = 'block'; this.elem.classList.remove('open'); - list.style.maxHeight = list.getBoundingClientRect().height + 'px'; - list.style.overflow = 'hidden'; - list.style.transition = 'max-height ease-in-out 240ms'; - - const transitionEndBound = onTransitionEnd.bind(this); - function onTransitionEnd() { - list.style.overflow = ''; - list.style.maxHeight = ''; - list.style.transition = ''; - list.style.display = 'none'; - list.removeEventListener('transitionend', transitionEndBound); - } - - setTimeout(() => { - requestAnimationFrame(() => { - list.style.maxHeight = `0px`; - list.addEventListener('transitionend', transitionEndBound) - }); - }, 1); + this.elem.setAttribute('aria-expanded', 'false'); + slideUp(list, 240); } click(event) {