Implement onbeforeunload composer confirmation. closes flarum/core#113

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

View File

@ -49,7 +49,7 @@ export default class ComposerBody extends Component {
}
preventExit() {
return this.content() && this.content() != this.props.originalContent && !confirm(this.props.confirmExit);
return this.content() && this.content() != this.props.originalContent && this.props.confirmExit;
}
onsubmit(value) {

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) {

View File

@ -68,7 +68,7 @@ export default class DiscussionComposer extends ComposerBody {
}
preventExit() {
return (this.title() || this.content()) && !confirm(this.props.confirmExit);
return (this.title() || this.content()) && this.props.confirmExit;
}
data() {