mirror of
https://github.com/flarum/framework.git
synced 2024-12-11 21:43:38 +08:00
Implement onbeforeunload composer confirmation. closes flarum/core#113
This commit is contained in:
parent
0c7da167c2
commit
b6fb560359
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user