|
|
@ -2,6 +2,8 @@ import rootScope from "../../lib/rootScope"; |
|
|
|
import { blurActiveElement, cancelEvent, findUpClassName } from "../../helpers/dom"; |
|
|
|
import { blurActiveElement, cancelEvent, findUpClassName } from "../../helpers/dom"; |
|
|
|
import { ripple } from "../ripple"; |
|
|
|
import { ripple } from "../ripple"; |
|
|
|
import animationIntersector from "../animationIntersector"; |
|
|
|
import animationIntersector from "../animationIntersector"; |
|
|
|
|
|
|
|
import appNavigationController, { NavigationItem } from "../appNavigationController"; |
|
|
|
|
|
|
|
import { isMobileSafari, isSafari } from "../../helpers/userAgent"; |
|
|
|
|
|
|
|
|
|
|
|
export type PopupOptions = Partial<{closable: true, overlayClosable: true, withConfirm: string, body: true}>; |
|
|
|
export type PopupOptions = Partial<{closable: true, overlayClosable: true, withConfirm: string, body: true}>; |
|
|
|
export default class PopupElement { |
|
|
|
export default class PopupElement { |
|
|
@ -17,6 +19,8 @@ export default class PopupElement { |
|
|
|
protected onCloseAfterTimeout: () => void; |
|
|
|
protected onCloseAfterTimeout: () => void; |
|
|
|
protected onEscape: () => boolean = () => true; |
|
|
|
protected onEscape: () => boolean = () => true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected navigationItem: NavigationItem; |
|
|
|
|
|
|
|
|
|
|
|
constructor(className: string, buttons?: Array<PopupButton>, options: PopupOptions = {}) { |
|
|
|
constructor(className: string, buttons?: Array<PopupButton>, options: PopupOptions = {}) { |
|
|
|
this.element.classList.add('popup'); |
|
|
|
this.element.classList.add('popup'); |
|
|
|
this.element.className = 'popup' + (className ? ' ' + className : ''); |
|
|
|
this.element.className = 'popup' + (className ? ' ' + className : ''); |
|
|
@ -33,7 +37,7 @@ export default class PopupElement { |
|
|
|
//ripple(this.closeBtn);
|
|
|
|
//ripple(this.closeBtn);
|
|
|
|
this.header.prepend(this.btnClose); |
|
|
|
this.header.prepend(this.btnClose); |
|
|
|
|
|
|
|
|
|
|
|
this.btnClose.addEventListener('click', this.destroy, {once: true}); |
|
|
|
this.btnClose.addEventListener('click', this.hide, {once: true}); |
|
|
|
|
|
|
|
|
|
|
|
if(options.overlayClosable) { |
|
|
|
if(options.overlayClosable) { |
|
|
|
const onOverlayClick = (e: MouseEvent) => { |
|
|
|
const onOverlayClick = (e: MouseEvent) => { |
|
|
@ -46,8 +50,6 @@ export default class PopupElement { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('keydown', this._onKeyDown, {capture: true}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(options.withConfirm) { |
|
|
|
if(options.withConfirm) { |
|
|
|
this.btnConfirm = document.createElement('button'); |
|
|
|
this.btnConfirm = document.createElement('button'); |
|
|
|
this.btnConfirm.classList.add('btn-primary'); |
|
|
|
this.btnConfirm.classList.add('btn-primary'); |
|
|
@ -98,14 +100,15 @@ export default class PopupElement { |
|
|
|
this.element.append(this.container); |
|
|
|
this.element.append(this.container); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _onKeyDown = (e: KeyboardEvent) => { |
|
|
|
|
|
|
|
if(e.key === 'Escape' && this.onEscape()) { |
|
|
|
|
|
|
|
cancelEvent(e); |
|
|
|
|
|
|
|
this.destroy(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public show() { |
|
|
|
public show() { |
|
|
|
|
|
|
|
this.navigationItem = { |
|
|
|
|
|
|
|
type: 'popup', |
|
|
|
|
|
|
|
onPop: this.destroy, |
|
|
|
|
|
|
|
onEscape: this.onEscape |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appNavigationController.pushItem(this.navigationItem); |
|
|
|
|
|
|
|
|
|
|
|
blurActiveElement(); // * hide mobile keyboard
|
|
|
|
blurActiveElement(); // * hide mobile keyboard
|
|
|
|
document.body.append(this.element); |
|
|
|
document.body.append(this.element); |
|
|
|
void this.element.offsetWidth; // reflow
|
|
|
|
void this.element.offsetWidth; // reflow
|
|
|
@ -114,15 +117,21 @@ export default class PopupElement { |
|
|
|
animationIntersector.checkAnimations(true); |
|
|
|
animationIntersector.checkAnimations(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public destroy = () => { |
|
|
|
public hide = () => { |
|
|
|
|
|
|
|
appNavigationController.back(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private destroy = () => { |
|
|
|
this.onClose && this.onClose(); |
|
|
|
this.onClose && this.onClose(); |
|
|
|
this.element.classList.add('hiding'); |
|
|
|
this.element.classList.add('hiding'); |
|
|
|
this.element.classList.remove('active'); |
|
|
|
this.element.classList.remove('active'); |
|
|
|
|
|
|
|
|
|
|
|
window.removeEventListener('keydown', this._onKeyDown, {capture: true}); |
|
|
|
if(this.btnClose) this.btnClose.removeEventListener('click', this.hide); |
|
|
|
if(this.btnClose) this.btnClose.removeEventListener('click', this.destroy); |
|
|
|
|
|
|
|
rootScope.overlayIsActive = false; |
|
|
|
rootScope.overlayIsActive = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appNavigationController.removeItem(this.navigationItem); |
|
|
|
|
|
|
|
this.navigationItem = undefined; |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
this.element.remove(); |
|
|
|
this.element.remove(); |
|
|
|
this.onCloseAfterTimeout && this.onCloseAfterTimeout(); |
|
|
|
this.onCloseAfterTimeout && this.onCloseAfterTimeout(); |
|
|
|