mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
update: common/components/ConfirmDocumentUnload
This commit is contained in:
committed by
Franz Liedke
parent
dde9c9c51b
commit
9615fd3e39
@@ -17,21 +17,23 @@ import Component from '../Component';
|
||||
*
|
||||
*/
|
||||
export default class ConfirmDocumentUnload extends Component {
|
||||
config(isInitialized, context) {
|
||||
if (isInitialized) return;
|
||||
|
||||
const handler = () => this.props.when() || undefined;
|
||||
|
||||
$(window).on('beforeunload', handler);
|
||||
|
||||
context.onunload = () => {
|
||||
$(window).off('beforeunload', handler);
|
||||
};
|
||||
handler() {
|
||||
return this.attrs.when() || undefined;
|
||||
}
|
||||
|
||||
view() {
|
||||
oncreate(vnode) {
|
||||
super.oncreate(vnode);
|
||||
|
||||
$(window).on('beforeunload', this.handler);
|
||||
}
|
||||
|
||||
onremove(vnode) {
|
||||
$(window).off('beforeunload', this.handler);
|
||||
}
|
||||
|
||||
view(vnode) {
|
||||
// To avoid having to render another wrapping <div> here, we assume that
|
||||
// this component is only wrapped around a single element / component.
|
||||
return this.props.children[0];
|
||||
return vnode.children[0];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user