mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
refactor(cloudfunc) getPathElement
This commit is contained in:
parent
84aca85217
commit
9b8a161b94
1 changed files with 20 additions and 28 deletions
|
|
@ -327,38 +327,30 @@ var Util;
|
|||
* @param url - адрес каталога
|
||||
*/
|
||||
function getPathElement(url) {
|
||||
var i, shortName, slashIndex,
|
||||
folders = [],
|
||||
href = '<a href="',
|
||||
title = '" title="',
|
||||
_l = '">',
|
||||
hrefEnd ='</a>',
|
||||
|
||||
/* корневой каталог */
|
||||
htmlPath = href + FS + title +
|
||||
'/' + _l + '/' +
|
||||
hrefEnd;
|
||||
var pathHTML = '',
|
||||
path = '/',
|
||||
template = '<a data-name="js-path-link" href="/fs{{ path }}" title="{{ path }}">{{ name }}</a>{{ slash }}',
|
||||
names = url.split('/')
|
||||
.slice(0, -1);
|
||||
|
||||
do {
|
||||
folders.push(url);
|
||||
url = url.substr(url, url.lastIndexOf('/'));
|
||||
} while (url !== '');
|
||||
|
||||
/* Формируем ссылки на каждый каталог в пути */
|
||||
for (i = folders.length - 1; i > 0; i--) {
|
||||
url = folders[i];
|
||||
slashIndex = url.lastIndexOf('/') + 1;
|
||||
shortName = Util.rmStr(url, url.substr(url, slashIndex));
|
||||
names[0] = '/';
|
||||
|
||||
names.forEach(function(name, index) {
|
||||
var slash = '/';
|
||||
|
||||
if (i !== 1)
|
||||
htmlPath += href + FS + url +
|
||||
title + url + _l +
|
||||
shortName + hrefEnd + '/';
|
||||
if (!index)
|
||||
slash = '';
|
||||
else
|
||||
htmlPath += shortName + '/';
|
||||
}
|
||||
path += name + '/';
|
||||
|
||||
pathHTML += Util.render(template, {
|
||||
path: path,
|
||||
name: name,
|
||||
slash: slash
|
||||
});
|
||||
});
|
||||
|
||||
return htmlPath;
|
||||
return pathHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue