Merge pull request #50 from tophf/unsaved-code-warning
Edit style: warn before losing changes in code areas
This commit is contained in:
commit
ab36efdd71
33
edit.js
33
edit.js
|
@ -27,6 +27,8 @@ function setupCodeMirror(textarea) {
|
|||
smartIndent: prefs.getPref("smart-indent"),
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"}
|
||||
});
|
||||
cm.lastChange = cm.changeGeneration();
|
||||
cm.on("change", indicateCodeChange);
|
||||
editors.push(cm);
|
||||
}
|
||||
|
||||
|
@ -35,9 +37,29 @@ function makeDirty() {
|
|||
}
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
return dirty ? t('styleChangesNotSaved') : null;
|
||||
return dirty || isCodeDirty() ? t('styleChangesNotSaved') : null;
|
||||
}
|
||||
|
||||
function isCodeDirty() {
|
||||
for(var i=0; i < editors.length; i++) {
|
||||
if (!editors[i].isClean(editors[i].lastChange)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function indicateCodeChange(cm) {
|
||||
var clean = cm.isClean(cm.lastChange);
|
||||
if (clean != cm.lastClean) {
|
||||
cm.lastClean = clean;
|
||||
var label = cm.getTextArea().previousElementSibling;
|
||||
if (label) {
|
||||
label.textContent = label.textContent.replace(/\*?$/, clean ? '' : '*');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function addAppliesTo(list, name, value) {
|
||||
var showingEverything = list.querySelector(".applies-to-everything") != null;
|
||||
// blow away "Everything" if it's there
|
||||
|
@ -206,7 +228,7 @@ function validate() {
|
|||
|
||||
function save() {
|
||||
// save the contents of the CodeMirror editors back into the textareas
|
||||
for(var i=0; i < editors.length; i++) {
|
||||
for (var i=0; i < editors.length; i++) {
|
||||
editors[i].save();
|
||||
}
|
||||
|
||||
|
@ -271,6 +293,13 @@ function getMeta(e) {
|
|||
|
||||
function saveComplete(style) {
|
||||
dirty = false;
|
||||
|
||||
for(var i=0; i < editors.length; i++) {
|
||||
var cm = editors[i];
|
||||
cm.lastChange = cm.changeGeneration(true);
|
||||
indicateCodeChange(cm);
|
||||
}
|
||||
|
||||
// Go from new style URL to edit style URL
|
||||
if (location.href.indexOf("id=") == -1) {
|
||||
// give the code above a moment before we kill the page
|
||||
|
|
Loading…
Reference in New Issue
Block a user