From 0dec6bc0422f6abc736fc7d39a9fd1083caef161 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 19 Feb 2013 07:52:13 -0500 Subject: [PATCH] added ability to add ?json flag only if we work with dir --- ChangeLog | 2 ++ lib/client/dom.js | 40 +++++++++++++++++++++++++++------------- lib/server/commander.js | 18 +++--------------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca88af7f..5eb6efe6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -146,6 +146,8 @@ now json data of file structure would be getted from click event with ?json flag. "no-js" part of url would not be supported anymore. +* Added ability to add ?json flag only if we work with dir. + 2012.12.12, Version 0.1.8 diff --git a/lib/client/dom.js b/lib/client/dom.js index ddecac5b..bd586171 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -884,15 +884,11 @@ var CloudCommander, Util, */ DOM.getCurrentFileContent = function(pParams, pCurrentFile){ var lRet, - lParams = pParams ? pParams : {}, - /* adding ?json param - * if file would be ignored and - * if directory would be - * geted back in json format - */ - lPath = DOM.getCurrentPath(pCurrentFile) + '?json', - lErrorWas = pParams.error, - lError = function(jqXHR){ + lCurrentFile = pCurrentFile ? pCurrentFile : DOM.getCurrentFile(), + lParams = pParams ? pParams : {}, + lPath = DOM.getCurrentPath(lCurrentFile), + lErrorWas = pParams.error, + lError = function(jqXHR){ Util.exec(lErrorWas); DOM.Images.showError(jqXHR); }; @@ -901,6 +897,10 @@ var CloudCommander, Util, lParams.error = lError; + + if( DOM.isCurrentDir(lCurrentFile) ) + lPath += '?json'; + if(!lParams.url) lParams.url = lPath; @@ -916,9 +916,11 @@ var CloudCommander, Util, * @pCurrentFile */ DOM.getCurrentData = function(pCallBack, pCurrentFile){ + var lParams, + lCurrentFile = pCurrentFile ? pCurrentFile : DOM.getCurrentFile(), lFunc = function(pData){ - var lName = DOM.getCurrentName(pCurrentFile); + var lName = DOM.getCurrentName(lCurrentFile); if( Util.isObject(pData) ){ pData = Util.stringifyJSON(pData); @@ -942,7 +944,7 @@ var CloudCommander, Util, }; - return DOM.getCurrentFileContent(lParams, pCurrentFile); + return DOM.getCurrentFileContent(lParams, lCurrentFile); }; /** @@ -1042,12 +1044,24 @@ var CloudCommander, Util, * @param pCurrentFile */ DOM.isCurrentFile = function(pCurrentFile){ - var lCurrentFileClass = pCurrentFile.className, - lIsCurrent = lCurrentFileClass.indexOf(CURRENT_FILE) >= 0; + var lClass = pCurrentFile && pCurrentFile.className, + lIsCurrent = lClass && lClass.indexOf(CURRENT_FILE) >= 0; return lIsCurrent; }; + /** + * check is current file is a directory + * + * @param pCurrentFile + */ + DOM.isCurrentDir = function(pCurrentFile){ + var lSize = DOM.getCurrentSize(pCurrentFile), + lRet = lSize === ''; + + return lRet; + }; + /** * get link from current (or param) file diff --git a/lib/server/commander.js b/lib/server/commander.js index 3f9e2678..9c24a027 100644 --- a/lib/server/commander.js +++ b/lib/server/commander.js @@ -212,11 +212,8 @@ lJSON[i+1] = lJSONFile; } - /* если js недоступен - * или отключен выcылаем html-код - * и прописываем соответствующие заголовки - */ - if( noJS(lReq) ){ + /* если js отключен выcылаем html-код */ + if( main.getQuery(lReq) === 'html' ){ var lPanel = CloudFunc.buildFromJSON(lJSON); lList = '' + ''; @@ -385,6 +382,7 @@ return lRet; } + function getDirPath(pReq){ var lRet = getCleanPath(pReq); @@ -394,16 +392,6 @@ return lRet; } - function noJS(pReq){ - var lNoJS, lPath; - if(pReq){ - lPath = getPath(pReq); - - lNoJS = lPath === '/' || main.getQuery(pReq) === 'html'; - } - - return lNoJS; - } function isGZIP(pReq){ var lEnc, lGZIP;