From 1d91b6807098c7780f0a442151176ec9b01cf0ad Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 13 Dec 2012 14:11:21 -0500 Subject: [PATCH] refactored --- lib/client/dom.js | 33 +++++++++++++++++++++++--------- lib/client/editor/_codemirror.js | 8 +++----- lib/client/menu.js | 19 +++++++----------- lib/client/viewer.js | 2 +- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 2b344b99..45b4fb6c 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -25,7 +25,7 @@ var CloudCommander, Util, DOM, CloudFunc; 'could not be none' }); - if(lRet_b) + if(lRet_b) DOM.removeClass(pCurrentFile, getCurrentFile()); return lRet_b; @@ -758,19 +758,34 @@ var CloudCommander, Util, DOM, CloudFunc; } return lCurrent; }; - + /** * unified way to get current file content * + * @pCallBack - callback function or data struct {sucess, error} * @pCurrentFile */ - DOM.getCurrentFileContent = function(pCallBack, pCurrentFile){ - var lPath = DOM.getCurrentPath(pCurrentFile), - lRet = DOM.ajax({ - url : lPath, - error : DOM.Images.showError, - success : Util.retExec(pCallBack) - }); + DOM.getCurrentFileContent = function(pParams, pCurrentFile){ + var lRet, + lParams = pParams ? pParams : {}, + lPath = DOM.getCurrentPath(pCurrentFile), + lError = function(){ + Util.exec(pParams.error); + DOM.Images.showError(); + }; + + if( Util.isFunction(lParams) ) + lParams = { + error : lError, + success : Util.retExec(pParams) + }; + else + lParams.error = lError; + + if(!lParams.url) + lParams.url = lPath; + + lRet = DOM.ajax(lParams); return lRet; }; diff --git a/lib/client/editor/_codemirror.js b/lib/client/editor/_codemirror.js index 82141574..836465c0 100644 --- a/lib/client/editor/_codemirror.js +++ b/lib/client/editor/_codemirror.js @@ -146,14 +146,12 @@ var CloudCommander, Util, DOM, CodeMirror; 400); /* reading data from current file */ - DOM.ajax({ - url:lPath, - error: function(jqXHR, textStatus, errorThrown){ + DOM.getCurrentFileContent({ + error : function(){ Loading = false; - return DOM.Images.showError(jqXHR); }, - success:function(data, textStatus, jqXHR){ + success : function(data){ /* if we got json - show it */ if(typeof data === 'object') data = JSON.stringify(data, null, 4); diff --git a/lib/client/menu.js b/lib/client/menu.js index 09b12f19..c8656795 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -129,25 +129,20 @@ var CloudCommander, Util, DOM, CloudFunc, $; callback: function(key, opt){ DOM.Images.showLoad(); - var lCurrent = DOM.getCurrentFile(), - lLink = DOM.getByTag('a', lCurrent)[0].href; + var lPath = DOM.getCurrentPath(), + lId = DOM.getIdBySrc(lPath); - console.log('downloading file ' + lLink +'...'); + Util.log('downloading file ' + lPath +'...'); - lLink = lLink + '?download'; - - lLink = Util.removeStr( lLink, CloudFunc.NOJS ); - var lId = DOM.getIdBySrc(lLink); + lPath = lPath + '?download'; if(!DOM.getById(lId)){ var lDownload = DOM.anyload({ name : 'iframe', async : false, className : 'hidden', - src : lLink, - func : function(){ - DOM.Images.hideLoad(); - } + src : lPath, + func : Util.retFunc(DOM.Images.hideLoad) }); DOM.Images.hideLoad(); @@ -155,7 +150,7 @@ var CloudCommander, Util, DOM, CloudFunc, $; document.body.removeChild(lDownload); }, 10000); } - else + else DOM.Images.showError({ responseText: 'Error: You trying to' + 'download same file to often'}); diff --git a/lib/client/viewer.js b/lib/client/viewer.js index d2c62cb6..d3f56e7f 100644 --- a/lib/client/viewer.js +++ b/lib/client/viewer.js @@ -131,7 +131,7 @@ var CloudCommander, Util, DOM, CloudFunc, $; */ FancyBox.loadData = function(pA, pCallBack){ var lLink = pA.href; - + /* убираем адрес хоста */ lLink = lLink.replace(cloudcmd.HOST, '');