From b4132849257acc37fa7d54a889498b6dfab330be Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 13 Dec 2012 10:53:31 -0500 Subject: [PATCH] added functions DOM.getCurrentFileContent(pCallBack [, pCurrentFile]) and Util.setTimeout(pFunction [, pCallBack, pTime]) --- ChangeLog | 3 ++ lib/client/dom.js | 17 +++++++++- lib/client/menu.js | 82 +++++++++++++++++++--------------------------- lib/util.js | 4 +-- 4 files changed, 54 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a799c12..30d4ff9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ * Added ability to upload files to GDrive. +* Added functions DOM.getCurrentFileContent(pCallBack [, pCurrentFile]) +and Util.setTimeout(pFunction [, pCallBack, pTime]) + 2012.12.12, Version 0.1.8 * Added ability to shutdown Cloud Commander diff --git a/lib/client/dom.js b/lib/client/dom.js index 13272b85..2b344b99 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -758,7 +758,22 @@ var CloudCommander, Util, DOM, CloudFunc; } return lCurrent; }; - + + /** + * unified way to get current file content + * + * @pCurrentFile + */ + DOM.getCurrentFileContent = function(pCallBack, pCurrentFile){ + var lPath = DOM.getCurrentPath(pCurrentFile), + lRet = DOM.ajax({ + url : lPath, + error : DOM.Images.showError, + success : Util.retExec(pCallBack) + }); + + return lRet; + }; /** * unified way to get RefreshButton diff --git a/lib/client/menu.js b/lib/client/menu.js index 92db3f1f..09b12f19 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -76,29 +76,22 @@ var CloudCommander, Util, DOM, CloudFunc, $; 'gist': { name: 'Gist', callback: function(key, opt){ - var lCurrent = DOM.getCurrentFile(), - lPath = DOM.getCurrentPath(), - lName = DOM.getCurrentName(lCurrent); + DOM.getCurrentFileContent(function(pData){ + var lName = DOM.getCurrentName(); + if( Util.isObject(pData) ) + pData = JSON.stringify(pData, null, 4); - DOM.ajax({ - url : lPath, - error : DOM.Images.showError, - success : function(data, textStatus, jqXHR){ - if( Util.isObject(data) ) - data = JSON.stringify(data, null, 4); - - var lGitHub = cloudcmd.GitHub; - - if('init' in lGitHub) - lGitHub.createGist(data, lName); - else - Util.exec(cloudcmd.GitHub, - function(){ - lGitHub.createGist(data, lName); - }); - } + var lGitHub = cloudcmd.GitHub; + + if('init' in lGitHub) + lGitHub.createGist(pData, lName); + else + Util.exec(cloudcmd.GitHub, + function(){ + lGitHub.createGist(pData, lName); + }); }); - + Util.log('Uploading to gist...'); } }, @@ -107,39 +100,30 @@ var CloudCommander, Util, DOM, CloudFunc, $; name: 'GDrive', callback: function(key, opt){ - - - var lCurrent = DOM.getCurrentFile(), - lPath = DOM.getCurrentPath(), - lName = DOM.getCurrentName(lCurrent); - - DOM.ajax({ - url : lPath, - error : DOM.Images.showError, - success : function(data, textStatus, jqXHR){ - if( Util.isObject(data) ) - data = JSON.stringify(data, null, 4); - var lData = { - data: data, - name: lName - }; - - var lGDrive = cloudcmd.GDrive; + DOM.getCurrentFileContent(function(data){ + var lName = DOM.getCurrentName(); + + if( Util.isObject(data) ) + data = JSON.stringify(data, null, 4); + var lData = { + data: data, + name: lName + }; - if('init' in lGDrive) - lGDrive.init(lData); - else - Util.exec(cloudcmd.GDrive, lData); - } - }); - - Util.log('Uploading to gdrive...'); - } + var lGDrive = cloudcmd.GDrive; + + if('init' in lGDrive) + lGDrive.init(lData); + else + Util.exec(cloudcmd.GDrive, lData); + }); + + Util.log('Uploading to gdrive...'); } } + } }, - download: { name: 'Download', callback: function(key, opt){ diff --git a/lib/util.js b/lib/util.js index 498c1a27..5c8e6b16 100644 --- a/lib/util.js +++ b/lib/util.js @@ -242,8 +242,8 @@ var Util, exports; * @param pArg */ Util.retExec = function(pCallBack, pArg){ - return function(){ - Util.exec(pCallBack, pArg); + return function(pArgument){ + Util.exec(pCallBack, pArg || pArgument); }; };