mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-08-02 20:53:02 +00:00
feature(edit) add confirm, if file changed and not saved, before close
This commit is contained in:
parent
05c2257f2c
commit
676f2d17af
2 changed files with 32 additions and 4 deletions
|
|
@ -89,7 +89,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip;
|
|||
var UndoManager = ace.require('ace/undomanager').UndoManager;
|
||||
|
||||
Ace.setValue(Value);
|
||||
CloudCmd.View.show(Element, focus);
|
||||
CloudCmd.View.show(Element, focus, {
|
||||
beforeClose: isChanged
|
||||
});
|
||||
|
||||
Session.setUndoManager(new UndoManager());
|
||||
}, function(callback) {
|
||||
|
|
@ -121,6 +123,20 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip;
|
|||
Ace.gotoLine(number);
|
||||
};
|
||||
|
||||
function isChanged() {
|
||||
var is,
|
||||
value = Ace.getValue(),
|
||||
isEqual = value === Value,
|
||||
msg = 'Do you want to save changes to ' + name + '?';
|
||||
|
||||
if (!isEqual) {
|
||||
is = Dialog.confirm(msg);
|
||||
|
||||
if (is)
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
function setEmmet(isHTML) {
|
||||
getEditConfig(function(config) {
|
||||
var extensions = config.extensions,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
* function shows FancyBox
|
||||
*/
|
||||
function show(data, callback, newConfig) {
|
||||
var path, element, func, name,
|
||||
var path, element, func,
|
||||
config = {};
|
||||
|
||||
if (!Loading) {
|
||||
|
|
@ -86,8 +86,20 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
|
||||
Util.copyObj(config, Config);
|
||||
|
||||
for (name in newConfig)
|
||||
config[name] = newConfig[name];
|
||||
if (newConfig)
|
||||
Object.keys(newConfig).forEach(function(name) {
|
||||
var func,
|
||||
asyncCall = Util.asyncCall,
|
||||
item = newConfig[name],
|
||||
isFunc = Util.isFunction(item);
|
||||
|
||||
if (isFunc) {
|
||||
func = config[name];
|
||||
config[name] = Util.bind(asyncCall, [item, func]);
|
||||
} else {
|
||||
config[name] = newConfig[name];
|
||||
}
|
||||
});
|
||||
|
||||
$.fancybox(element, config);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue