0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Moving dirty editor handling out of uploadMgr

issue #1327

- just moved to be in editor obj, everything else is the same
This commit is contained in:
Hannah Wolfe 2013-11-11 09:14:18 +00:00
parent 340206fa4b
commit 3fd3102486

View file

@ -448,8 +448,16 @@
return this.uploadMgr.getEditorValue(); return this.uploadMgr.getEditorValue();
}, },
unloadDirtyMessage: function () {
return "==============================\n\n" +
"Hey there! It looks like you're in the middle of writing" +
" something and you haven't saved all of your content." +
"\n\nSave before you go!\n\n" +
"==============================";
},
setEditorDirty: function (dirty) { setEditorDirty: function (dirty) {
return this.uploadMgr.setEditorDirty(dirty); window.onbeforeunload = dirty ? this.unloadDirtyMessage : null;
}, },
initUploads: function () { initUploads: function () {
@ -465,6 +473,7 @@
var self = this; var self = this;
this.editor.setOption("readOnly", false); this.editor.setOption("readOnly", false);
this.editor.on('change', function () { this.editor.on('change', function () {
self.setEditorDirty(true);
self.renderPreview(); self.renderPreview();
}); });
}, },
@ -662,30 +671,16 @@
return value; return value;
} }
function unloadDirtyMessage() {
return "==============================\n\n" +
"Hey there! It looks like you're in the middle of writing" +
" something and you haven't saved all of your content." +
"\n\nSave before you go!\n\n" +
"==============================";
}
function setEditorDirty(dirty) {
window.onbeforeunload = dirty ? unloadDirtyMessage : null;
}
// Public API // Public API
_.extend(this, { _.extend(this, {
getEditorValue: getEditorValue, getEditorValue: getEditorValue,
handleUpload: handleUpload, handleUpload: handleUpload
setEditorDirty: setEditorDirty
}); });
// initialise // initialise
editor.on('change', function (cm, changeObj) { editor.on('change', function (cm, changeObj) {
/*jslint unparam:true*/ /*jslint unparam:true*/
setEditorDirty(true);
var linesChanged = _.range(changeObj.from.line, changeObj.from.line + changeObj.text.length); var linesChanged = _.range(changeObj.from.line, changeObj.from.line + changeObj.text.length);
_.each(linesChanged, function (ln) { _.each(linesChanged, function (ln) {