diff --git a/lib/client/edit.js b/lib/client/edit.js index 7f1b05a6..dab31f77 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -14,7 +14,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M Storage = DOM.Storage, exec = Util.exec, join = CloudCmd.join, - + FileName, Menu, Value, Edit = this, @@ -43,7 +43,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M function init(callback) { exec.series([ CloudCmd.View, - load, + loadFiles, function(callback) { DOM.loadSocket(initSocket); callback(); @@ -87,7 +87,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M }); socket.on('patch', function(name, data, hash) { - if (name === Info.path) + if (name === FileName) loadDiff(function(error) { if (error) console.error(error); @@ -144,8 +144,10 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M } this.show = function(callback) { - var name = Info.name, - isDir = Info.isDir; + var isDir = Info.isDir, + name = Info.name; + + FileName = Info.path; Images.show.load(); @@ -347,8 +349,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M }; Edit.save = function() { - var path = Info.path, - value = Ace.getValue(); + var value = Ace.getValue(); Files.get('config', function(error, config) { var isDiff = config.diff, @@ -370,9 +371,9 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M var result = data || Value; if (isPatch) - Edit.save.patch(path, patch); + Edit.save.patch(FileName, patch); else - Edit.save.write(path + query, result); + Edit.save.write(FileName + query, result); }, function(func) { zip(value, function(error, data) { if (error) @@ -383,7 +384,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M }); }); - }, exec.with(doDiff, path)); + }, exec.with(doDiff, FileName)); }); }; @@ -427,9 +428,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M patch = Diff.createPatch(Value, newValue); exec(callback, patch); }, function(func) { - var path = Info.path; - - DOM.getDataFromStorage(path, function(error, data) { + DOM.getDataFromStorage(FileName, function(error, data) { if (data) Value = data; @@ -562,7 +561,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M } } - function load(callback) { + function loadFiles(callback) { var url = join([ 'theme-tomorrow_night_blue', 'ext-language_tools', @@ -603,7 +602,6 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M var ret, size = Format.size(Value.length), isError = /^error/.test(text), - path = Info.path, msg = '\nShould I save file anyway?'; if (!isError) { @@ -613,7 +611,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M if (error) console.error(error); - DOM.saveDataToStorage(path, Value, hash); + DOM.saveDataToStorage(FileName, Value, hash); }); DOM.setCurrentSize(size); @@ -621,7 +619,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M ret = Dialog.confirm(text + msg); if (ret) - RESTful.write(path, Value, onSave); + RESTful.write(FileName, Value, onSave); } } @@ -634,7 +632,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M }; function readWithFlag(flag) { - var path = Info.path; + var path = FileName; Util.check(arguments, ['flag']);