From cad88ad22900879f0ea53f4dbb32eec2342c4069 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 14 Feb 2014 10:31:15 -0500 Subject: [PATCH] refactor(client) ajaxLoad --- lib/client.js | 75 ++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/lib/client.js b/lib/client.js index 2ba96c49..49e81d98 100644 --- a/lib/client.js +++ b/lib/client.js @@ -327,26 +327,26 @@ var Util, DOM, CloudFunc; * @param pOptions * { refresh, nohistory } - необходимость обновить данные о каталоге */ - this.ajaxLoad = function(pPath, pOptions) { - if (!pOptions) - pOptions = {}; + this.ajaxLoad = function(path, options) { + var json, str, + ret = options && options.refresh, + SLASH = '/', + fsPath = decodeURI(path), + noJSONPath = Util.removeStr(fsPath, '?json' ), + cleanPath = Util.removeStrOneTime(noJSONPath, CloudFunc.FS) || SLASH, + title = CloudFunc.getTitle(cleanPath), + oldURL = window.location.pathname; - /* Отображаем красивые пути */ - var lSLASH = '/', - title = CloudFunc.getTitle(lCleanPath), - lFSPath = decodeURI(pPath), - lNOJSPath = Util.removeStr( lFSPath, '?json' ), - lCleanPath = Util.removeStrOneTime( lNOJSPath, CloudFunc.FS ) || lSLASH, - - lOldURL = window.location.pathname; + if (!options) + options = {}; - if (lCleanPath === lSLASH) - lNOJSPath = lSLASH; + if (cleanPath === SLASH) + noJSONPath = SLASH; - Util.log ('reading dir: "' + lCleanPath + '";'); + Util.log ('reading dir: "' + cleanPath + '";'); - if (!pOptions.nohistory) - DOM.setHistory(lNOJSPath, null, lNOJSPath); + if (!options.nohistory) + DOM.setHistory(noJSONPath, null, noJSONPath); DOM.setTitle(title); @@ -357,40 +357,35 @@ var Util, DOM, CloudFunc; * если стоит поле обязательной перезагрузки - * перезагружаемся */ - var lRet = pOptions.refresh; - if (!lRet) { - var lJSON = Storage.get(lCleanPath); + if (!ret) { + str = Storage.get(cleanPath); - if (lJSON) { - lJSON = Util.parseJSON(lJSON); - CloudCmd.createFileTable(lJSON); + if (!str) + ret = true; + else { + json = Util.parseJSON(str); + CloudCmd.createFileTable(json); } - else - lRet = true; } - if (lRet) + if (ret) DOM.getCurrentFileContent({ - url : lFSPath, - - dataType: 'json', - - error : function() { - DOM.setHistory(lOldURL, null, lOldURL); + url : fsPath, + dataType : 'json', + error : function() { + DOM.setHistory(oldURL, null, oldURL); }, - - success : function(pData) { - CloudCmd.createFileTable(pData); + success : function(data) { + var str = Util.stringifyJSON(data), + MAX_SIZE = 50000; - /* переводим таблицу файлов в строку, для * - * сохранения в localStorage */ - var lJSON_s = Util.stringifyJSON(pData); - Util.log(lJSON_s.length); + CloudCmd.createFileTable(data); + Util.log(str.length); /* если размер данных не очень бошьой * * сохраняем их в кэше */ - if (lJSON_s.length < 50000 ) - Storage.set(lCleanPath, lJSON_s); + if (str.length < MAX_SIZE) + Storage.set(cleanPath, str); } }); };