mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-22 06:40:01 +08:00
Upgraded app to Laravel 5.7
This commit is contained in:
41
resources/js/components/collapsible.js
Normal file
41
resources/js/components/collapsible.js
Normal file
@ -0,0 +1,41 @@
|
||||
import {slideDown, slideUp} from "../services/animations";
|
||||
|
||||
/**
|
||||
* Collapsible
|
||||
* Provides some simple logic to allow collapsible sections.
|
||||
*/
|
||||
class Collapsible {
|
||||
|
||||
constructor(elem) {
|
||||
this.elem = elem;
|
||||
this.trigger = elem.querySelector('[collapsible-trigger]');
|
||||
this.content = elem.querySelector('[collapsible-content]');
|
||||
|
||||
if (!this.trigger) return;
|
||||
|
||||
this.trigger.addEventListener('click', this.toggle.bind(this));
|
||||
}
|
||||
|
||||
open() {
|
||||
this.elem.classList.add('open');
|
||||
this.trigger.setAttribute('aria-expanded', 'true');
|
||||
slideDown(this.content, 300);
|
||||
}
|
||||
|
||||
close() {
|
||||
this.elem.classList.remove('open');
|
||||
this.trigger.setAttribute('aria-expanded', 'false');
|
||||
slideUp(this.content, 300);
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.elem.classList.contains('open')) {
|
||||
this.close();
|
||||
} else {
|
||||
this.open();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Collapsible;
|
Reference in New Issue
Block a user