fire a warning before closing an unsaved file
This commit is contained in:
@@ -66,9 +66,8 @@ function doClickSave() {
|
||||
'doClickSave');
|
||||
},
|
||||
success: function(json,text,xhr){
|
||||
|
||||
|
||||
|
||||
jQuery(editor).data('saved', true); // Set as saved
|
||||
editor.on("change", store_changes_function); // Re-enable change watcher
|
||||
// reenable disabled submit button
|
||||
var t=jQuery("input[name='save']");
|
||||
t.attr('class','');
|
||||
|
||||
@@ -55,12 +55,18 @@ jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||
jQuery(document).on('click', '#filesTab button[class="close"]', function (e) {
|
||||
var tab_body = jQuery(jQuery(this).parent().attr("href")); // it should be a div
|
||||
var tab_header = jQuery(this).parent().parent(); // it should be a li
|
||||
|
||||
if (tab_header.hasClass('active') === true) { //Set active an other tab
|
||||
jQuery(tab_header).prev().children('a[data-toggle="tab"]').tab('show'); // Select first tab
|
||||
var saved = jQuery(tab_body.find('textarea').data('editor')).data('saved');
|
||||
var close = true;
|
||||
if (saved === false) {
|
||||
close = confirm("You are closing an unsaved file")
|
||||
}
|
||||
if (close) {
|
||||
if (tab_header.hasClass('active') === true) { //Set active an other tab
|
||||
jQuery(tab_header).prev().children('a[data-toggle="tab"]').tab('show'); // Select first tab
|
||||
}
|
||||
tab_header.remove(); //remove li of tab
|
||||
tab_body.remove(); //remove li of tab
|
||||
}
|
||||
tab_header.remove(); //remove li of tab
|
||||
tab_body.remove(); //remove li of tab
|
||||
});
|
||||
|
||||
// Revert current file
|
||||
|
||||
@@ -113,6 +113,11 @@
|
||||
CodeMirror.showHint(cm, CodeMirror.pythonHint);
|
||||
}
|
||||
{{pass}}
|
||||
store_changes_function = function(instance, changeObj) {
|
||||
jQuery(instance).data('saved', false);
|
||||
instance.off("change", store_changes_function);
|
||||
}
|
||||
editor.on("change", store_changes_function);
|
||||
// save the editor as textarea data attribute
|
||||
jQuery("#{{=id}} textarea").data('editor', editor);
|
||||
var hlLine = editor.addLineClass(0, "background", "activeline");
|
||||
|
||||
Reference in New Issue
Block a user