From a41b26b458689525c196a112fc974cb634296f2a Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 7 May 2014 14:26:50 -0400 Subject: [PATCH] feature(client) loadDir: change params --- lib/client.js | 90 ++++++++++++++++++++++++----------------- lib/client/key.js | 10 ++--- lib/client/listeners.js | 18 +++++---- 3 files changed, 67 insertions(+), 51 deletions(-) diff --git a/lib/client.js b/lib/client.js index e7f277e3..7a87917e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -28,43 +28,52 @@ var Util, DOM, CloudFunc; * Функция привязываеться ко всем ссылкам и * загружает содержимое каталогов * - * @param paramLink - ссылка - * @param needRefresh - необходимость обязательной загрузки данных с сервера + * @param params - { + * paramLink - ссылка + * needRefresh - необходимость обязательной загрузки данных с сервера + * panel + * } + * @param event */ - this.loadDir = function(paramLink, needRefresh, panel) { - return function(event) { - var link, imgPosition, panelChanged, - currentLink = DOM.getCurrentLink(), - href = currentLink.href; - - if (paramLink) - link = paramLink; - else - link = Util.rmStr(href, CloudCmd.HOST); - - link += '?json'; - - if (link || currentLink.target !== '_blank') { - if (panel && panel !== Info.panel) { - DOM.changePanel(); - panelChanged = true; - } - - if (panelChanged || needRefresh) - imgPosition = { - top: true - }; - - Images.showLoad(imgPosition); - - /* загружаем содержимое каталога */ - CloudCmd.ajaxLoad(link, { - refresh: needRefresh - }, panel); + this.loadDir = function(params, event) { + var link, imgPosition, panelChanged, pathParams, + isRefresh, panel, + currentLink = DOM.getCurrentLink(), + href = currentLink.href; + + if (params) { + pathParams = params.path; + isRefresh = params.isRefresh; + panel = params.panel; + } + + if (pathParams) + link = pathParams; + else + link = Util.rmStr(href, CloudCmd.HOST); + + link += '?json'; + + if (link || currentLink.target !== '_blank') { + if (panel && panel !== Info.panel) { + DOM.changePanel(); + panelChanged = true; } - DOM.preventDefault(event); - }; + if (panelChanged || isRefresh) + imgPosition = { + top: true + }; + + Images.showLoad(imgPosition); + + /* загружаем содержимое каталога */ + CloudCmd.ajaxLoad(link, { + refresh: isRefresh + }, panel); + } + + DOM.preventDefault(event); }; @@ -341,10 +350,13 @@ var Util, DOM, CloudFunc; panel = panelParam || current && current.parentElement, path = DOM.getCurrentDirPath(panel), link = CloudFunc.FS + path, - notSlashlLink = CloudFunc.rmLastSlash(link), - load = CloudCmd.loadDir(notSlashlLink, NEEDREFRESH, panel); + notSlashlLink = CloudFunc.rmLastSlash(link); - load(); + CloudCmd.loadDir({ + path : notSlashlLink, + isRefresh : NEEDREFRESH, + panel: panel + }); }; /** @@ -500,7 +512,9 @@ var Util, DOM, CloudFunc; path = parentPath; path = CloudFunc.FS + CloudFunc.rmLastSlash(path); - Util.exec(CloudCmd.loadDir(path)); + CloudCmd.loadDir({ + path: path + }); } }; diff --git a/lib/client/key.js b/lib/client/key.js index 4f3417af..69147078 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -370,7 +370,7 @@ var CloudCmd, Util, DOM; /* открываем папку*/ case Key.ENTER: if (Info.isDir) - Util.exec(CloudCmd.loadDir()); + CloudCmd.loadDir(); break; case Key.BACKSPACE: @@ -379,10 +379,10 @@ var CloudCmd, Util, DOM; break; case Key.BACKSLASH: - if (ctrl) { - path = '/'; - Util.exec(CloudCmd.loadDir(path)); - } + if (ctrl) + CloudCmd.loadDir({ + path: '/' + }); break; case Key.A: diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 1dea61b5..7dbc9ab6 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -97,7 +97,11 @@ var Util, DOM, CloudCmd; for (i = 0; i < n; i++) { ai = pathLinks[i]; link = Util.rmStr(ai.href, url), - loadDir = CloudCmd.loadDir(link, false, panel), + loadDir = Util.bind(CloudCmd.loadDir, { + path : link, + isRefresh : false, + panel : panel + }), Events.addClick(loadDir, ai); OnPathLinks.push(loadDir); } @@ -194,24 +198,22 @@ var Util, DOM, CloudCmd; function onDblClick(event) { var current = getLIElement(event.target), - isDir = DOM.isCurrentIsDir(current), - loadDirOnce = CloudCmd.loadDir(); + isDir = DOM.isCurrentIsDir(current); if (isDir) - loadDirOnce(event); + CloudCmd.loadDir(null, event); } function onTouch(event) { - var isCurrent, loadDirOnce, + var isCurrent, element = getLIElement(event.target), isDir = DOM.isCurrentIsDir(element); if (isDir) { - isCurrent = DOM.isCurrentFile(element), - loadDirOnce = CloudCmd.loadDir(); + isCurrent = DOM.isCurrentFile(element); if (isCurrent) - loadDirOnce(event); + CloudCmd.loadDir(null, event); } }