mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
5a533fff8b
- Added fadeIn to animation JS service. - Updated overlay to use anim service and to recieve a callback for after-anim actions. - Updated code editor popup to refresh Codemirror instance layout after animation has completed. Fixes #1672
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import {fadeIn, fadeOut} from "../services/animations";
|
|
|
|
class Overlay {
|
|
|
|
constructor(elem) {
|
|
this.container = elem;
|
|
elem.addEventListener('click', event => {
|
|
if (event.target === elem) return this.hide();
|
|
});
|
|
|
|
window.addEventListener('keyup', event => {
|
|
if (event.key === 'Escape') {
|
|
this.hide();
|
|
}
|
|
});
|
|
|
|
let closeButtons = elem.querySelectorAll('.popup-header-close');
|
|
for (let i=0; i < closeButtons.length; i++) {
|
|
closeButtons[i].addEventListener('click', this.hide.bind(this));
|
|
}
|
|
}
|
|
|
|
hide(onComplete = null) { this.toggle(false, onComplete); }
|
|
show(onComplete = null) { this.toggle(true, onComplete); }
|
|
|
|
toggle(show = true, onComplete) {
|
|
if (show) {
|
|
fadeIn(this.container, 240, onComplete);
|
|
} else {
|
|
fadeOut(this.container, 240, onComplete);
|
|
}
|
|
}
|
|
|
|
focusOnBody() {
|
|
const body = this.container.querySelector('.popup-body');
|
|
if (body) {
|
|
body.focus();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
export default Overlay; |