From 52090ddcc3f13b53f155e182757eebb38814c940 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 20 Jan 2016 14:16:32 -0500 Subject: [PATCH] fix(pathLink) prefix when js disabled --- lib/client.js | 1 + lib/client/dom.js | 6 ++++-- lib/client/listeners.js | 4 +++- lib/cloudfunc.js | 14 ++++++++------ lib/server/route.js | 1 + tmpl/fs/pathLink.hbs | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/client.js b/lib/client.js index 9221c6c9..ee203a84 100644 --- a/lib/client.js +++ b/lib/client.js @@ -448,6 +448,7 @@ var Util, DOM, CloudFunc, join; panel.innerHTML = CloudFunc.buildFromJSON({ data : json, id : panel.id, + prefix : CloudCmd.PREFIX, template : { file : templFile, path : templPath, diff --git a/lib/client/dom.js b/lib/client/dom.js index 42027644..ddb6b32f 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1061,9 +1061,11 @@ var CloudCmd, Util, DOM, CloudFunc; this.getCurrentPath = function(currentFile) { var current = currentFile || DOM.getCurrentFile(), element = DOM.getByTag('a', current)[0], - path = element.getAttribute('href'); + path = element.getAttribute('href'), + prefix = CloudCmd.PREFIX, + fs = CloudFunc.FS; - path = path.replace(CloudFunc.FS, ''); + path = path.replace(RegExp('^' + prefix + fs), ''); return path; }; diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 46c7e2c2..51336371 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -100,6 +100,8 @@ var Util, DOM, CloudFunc, CloudCmd; function onPathElementClick(panel, event) { var link, href, url, noCurrent, + fs = CloudFunc.FS, + prefix = CloudCmd.PREFIX, element = event.target, attr = element.getAttribute('data-name'); @@ -128,7 +130,7 @@ var Util, DOM, CloudFunc, CloudCmd; */ link = link.replace('%%', '%25%'); link = decodeURI(link); - link = link.replace(CloudFunc.FS, '') || '/'; + link = link.replace(RegExp('^' + prefix + fs), '') || '/'; noCurrent = isNoCurrent(panel); diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index 1387693c..1b2347bf 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -87,7 +87,7 @@ * возвращаеться массив каталогов * @param url - адрес каталога */ - function getPathLink(url, template) { + function getPathLink(url, prefix, template) { var namesRaw, names, length, pathHTML = '', path = '/'; @@ -121,7 +121,8 @@ pathHTML += rendy(template, { path: path, name: name, - slash: slash + slash: slash, + prefix: prefix }); } }); @@ -138,6 +139,7 @@ var file, i, n, type, attribute, size, owner, mode, dotDot, link, dataName, linkResult, + prefix = params.prefix, template = params.template, templateFile = template.file, templateLink = template.link, @@ -149,10 +151,10 @@ * Строим путь каталога в котором мы находимся * со всеми подкаталогами */ - htmlPath = getPathLink(path, template.pathLink), + htmlPath = getPathLink(path, prefix, template.pathLink), fileTable = rendy(template.path, { - link : FS + path, + link : prefix + FS + path, fullPath : path, path : htmlPath }), @@ -183,7 +185,7 @@ if (dotDot === '') dotDot = '/'; - link = FS + dotDot; + link = prefix + FS + dotDot; linkResult = rendy(template.link, { link : link, @@ -209,7 +211,7 @@ n = files.length; for (i = 0; i < n; i++) { file = files[i]; - link = FS + path + file.name; + link = prefix + FS + path + file.name; if (file.size === 'dir') { type = 'directory'; diff --git a/lib/server/route.js b/lib/server/route.js index 975be4b0..fda52ded 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -214,6 +214,7 @@ if (!error) { panel = CloudFunc.buildFromJSON({ data : json, + prefix : config('prefix'), template : Template }), diff --git a/tmpl/fs/pathLink.hbs b/tmpl/fs/pathLink.hbs index 304af188..9f386055 100644 --- a/tmpl/fs/pathLink.hbs +++ b/tmpl/fs/pathLink.hbs @@ -1 +1 @@ -{{ name }}{{ slash }} \ No newline at end of file +{{ name }}{{ slash }} \ No newline at end of file