From a898f53e5280222141fa873e6cbf2ed423e83e7f Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 27 Nov 2013 16:01:24 +0000 Subject: [PATCH] refactor(edit) add save --- lib/client/edit.js | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index fbb635da..5fb23643 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -143,39 +143,41 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; Ace.commands.addCommand({ name : 'save', bindKey : { win: 'Ctrl-S', mac: 'Command-S' }, - exec : function () { - var lPath = DOM.getCurrentPath(), - lValue = Ace.getValue(); + exec : save + }); + } + + function save () { + var lPath = DOM.getCurrentPath(), + lValue = Ace.getValue(); + + CloudCmd.getConfig(function(config) { + var isDiff = config.diff; + + Util.ifExec(!isDiff, function(patch) { + var query, + isString = Util.isString(patch), + length = isString && patch.length < lValue.length; - CloudCmd.getConfig(function(config) { - var isDiff = config.diff; - - Util.ifExec(!isDiff, function(patch) { - var query, - isString = Util.isString(patch), - length = isString && patch.length < lValue.length; + Value = lValue; + + if (isString && length) { + lValue = patch; + query = '?patch'; + } + + DOM.checkStorageHash(lPath, function(error, equal) { + if (!error) { + if (!equal) + query = ''; - Value = lValue; - - if (isString && length) { - lValue = patch; - query = '?patch'; - } - - DOM.checkStorageHash(lPath, function(error, equal) { - if (!error) { - if (!equal) - query = ''; - - DOM.RESTful.save(lPath, lValue, onSave, query); - } - }); - - }, function(callback) { - diff(lValue, callback); - }); + DOM.RESTful.save(lPath, lValue, onSave, query); + } }); - } + + }, function(callback) { + diff(lValue, callback); + }); }); }