Implement onbeforeunload composer confirmation. closes flarum/core#113

This commit is contained in:
Toby Zerner
2015-06-25 10:34:14 +09:30
parent ae8729250b
commit 34ca6d4515
3 changed files with 12 additions and 3 deletions

View File

@ -70,6 +70,10 @@ class Composer extends Component {
$(document)
.on('mousemove', this.handlers.onmousemove = this.onmousemove.bind(this))
.on('mouseup', this.handlers.onmouseup = this.onmouseup.bind(this));
window.onbeforeunload = e => {
return this.component && this.component.preventExit();
};
}
configHandle(element, isInitialized) {
@ -129,7 +133,12 @@ class Composer extends Component {
}
preventExit() {
return this.component && this.component.preventExit();
if (this.component) {
var preventExit = this.component.preventExit();
if (preventExit) {
return !confirm(preventExit);
}
}
}
render(anchorToBottom) {