]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/components/chapter-toggle.js
Update errors.php
[bookstack] / resources / assets / js / components / chapter-toggle.js
index e3a542ea4cdaf4e9994fce1788473e9db4cd526c..bfd0ac7296576f6151aa61e686a3591fd6b72e6a 100644 (file)
@@ -1,3 +1,4 @@
+import {slideUp, slideDown} from "../services/animations";
 
 class ChapterToggle {
 
@@ -8,53 +9,17 @@ 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.overflow = 'hidden';
-        list.style.transition = 'height ease-in-out 240ms';
-
-        let transitionEndBound = onTransitionEnd.bind(this);
-        function onTransitionEnd() {
-            list.style.overflow = '';
-            list.style.height = '';
-            list.style.transition = '';
-            list.style.display = `block`;
-            list.removeEventListener('transitionend', transitionEndBound);
-        }
-
-        setTimeout(() => {
-            list.style.height = `${height}px`;
-            list.addEventListener('transitionend', transitionEndBound)
-        }, 1);
+        this.elem.setAttribute('aria-expanded', 'true');
+        slideDown(list, 240);
     }
 
     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';
-        list.style.overflow = 'hidden';
-        list.style.transition = 'height ease-in-out 240ms';
-
-        let transitionEndBound = onTransitionEnd.bind(this);
-        function onTransitionEnd() {
-            list.style.overflow = '';
-            list.style.height = '';
-            list.style.transition = '';
-            list.style.display =  'none';
-            list.removeEventListener('transitionend', transitionEndBound);
-        }
-
-        setTimeout(() => {
-            list.style.height = `0px`;
-            list.addEventListener('transitionend', transitionEndBound)
-        }, 1);
+        this.elem.setAttribute('aria-expanded', 'false');
+        slideUp(list, 240);
     }
 
     click(event) {
@@ -65,4 +30,4 @@ class ChapterToggle {
 
 }
 
-module.exports = ChapterToggle;
+export default ChapterToggle;