BookStack/resources/js/components/overlay.js
Dan Brown 5a533fff8b
Updated codeblock editor to work with fade animation
- 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
2019-12-07 16:54:34 +00:00

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;