mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-11 20:54:38 +08:00
573c4e26d5
Now tags load with the page, not via AJAX.
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
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));
|
|
this.openIfContainsError();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
openIfContainsError() {
|
|
const error = this.content.querySelector('.text-neg.text-small');
|
|
if (error) {
|
|
this.open();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
export default Collapsible; |