2020-06-27 18:56:01 -04:00
|
|
|
import {fadeIn, fadeOut} from "../services/animations";
|
|
|
|
import {onSelect} from "../services/dom";
|
2022-11-15 07:44:57 -05:00
|
|
|
import {Component} from "./component";
|
2020-06-27 18:56:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Popup window that will contain other content.
|
|
|
|
* This component provides the show/hide functionality
|
|
|
|
* with the ability for popup@hide child references to close this.
|
|
|
|
*/
|
2022-11-15 07:44:57 -05:00
|
|
|
export class Popup extends Component {
|
2020-06-27 18:56:01 -04:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
this.container = this.$el;
|
|
|
|
this.hideButtons = this.$manyRefs.hide || [];
|
|
|
|
|
|
|
|
this.onkeyup = null;
|
|
|
|
this.onHide = null;
|
|
|
|
this.setupListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
setupListeners() {
|
|
|
|
let lastMouseDownTarget = null;
|
|
|
|
this.container.addEventListener('mousedown', event => {
|
|
|
|
lastMouseDownTarget = event.target;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.container.addEventListener('click', event => {
|
|
|
|
if (event.target === this.container && lastMouseDownTarget === this.container) {
|
|
|
|
return this.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
onSelect(this.hideButtons, e => this.hide());
|
|
|
|
}
|
|
|
|
|
|
|
|
hide(onComplete = null) {
|
2022-04-20 09:58:37 -04:00
|
|
|
fadeOut(this.container, 120, onComplete);
|
2020-06-27 18:56:01 -04:00
|
|
|
if (this.onkeyup) {
|
|
|
|
window.removeEventListener('keyup', this.onkeyup);
|
|
|
|
this.onkeyup = null;
|
|
|
|
}
|
|
|
|
if (this.onHide) {
|
|
|
|
this.onHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
show(onComplete = null, onHide = null) {
|
2022-04-20 09:58:37 -04:00
|
|
|
fadeIn(this.container, 120, onComplete);
|
2020-06-27 18:56:01 -04:00
|
|
|
|
|
|
|
this.onkeyup = (event) => {
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.addEventListener('keyup', this.onkeyup);
|
|
|
|
this.onHide = onHide;
|
|
|
|
}
|
|
|
|
|
2022-11-15 07:44:57 -05:00
|
|
|
}
|