1
0
mirror of https://github.com/lrsjng/h5ai.git synced 2025-04-04 12:42:50 +02:00

Redesigned js.

This commit is contained in:
Lars Jung 2011-09-29 13:43:22 +02:00
parent 8670b248a9
commit 4c1ed3d1e8
9 changed files with 493 additions and 461 deletions

@ -1,13 +1,13 @@
/*global $, Objects */
/*global $, H5aiJs */
Objects.Tree = function (pathCache, h5ai) {
H5aiJs.factory.Connector = function () {
var contentTypeRegEx = /^text\/html;h5ai=/,
pathnameStatusCache = {},
fetchStatus = function (pathname, callback) {
if (h5ai.settings.folderStatus[pathname]) {
callback(h5ai.settings.folderStatus[pathname]);
if (H5aiJs.h5ai.settings.folderStatus[pathname]) {
callback(H5aiJs.h5ai.settings.folderStatus[pathname]);
return;
} else if (pathnameStatusCache[pathname]) {
callback(pathnameStatusCache[pathname]);
@ -37,14 +37,14 @@ Objects.Tree = function (pathCache, h5ai) {
if (status !== "h5ai") {
path.status = status;
}
path.updateHtml();
h5ai.linkHoverStates();
H5aiJs.html.updateHtml(path);
H5aiJs.h5ai.linkHoverStates();
});
}
},
updatePaths = function () {
$.each(pathCache.cache, function (ref, cached) {
$.each(H5aiJs.pathCache.cache, function (ref, cached) {
updatePath(cached);
});
},
@ -76,7 +76,7 @@ Objects.Tree = function (pathCache, h5ai) {
$(html).find("#table td").closest("tr").each(function () {
var path = pathCache.getPath(pathname, this);
var path = H5aiJs.pathCache.getPath(pathname, this);
if (path.isFolder && (!path.isParentFolder || includeParent)) {
content[path.absHref] = path;
@ -92,7 +92,7 @@ Objects.Tree = function (pathCache, h5ai) {
fetchStatusAndContent(pathname, false, function (status, content) {
var path = pathCache.getPath(pathname);
var path = H5aiJs.pathCache.getPath(pathname);
path.status = status;
path.content = content;
@ -103,7 +103,7 @@ Objects.Tree = function (pathCache, h5ai) {
fetchPath(pathname, function (path) {
var parent = pathCache.splitPathname(pathname)[0];
var parent = H5aiJs.pathCache.splitPathname(pathname)[0];
path.treeOpen = true;
if (childPath) {
@ -120,25 +120,24 @@ Objects.Tree = function (pathCache, h5ai) {
fetchTree(document.location.pathname, function (path) {
$("#tree")
.append(path.updateTreeHtml())
.append(H5aiJs.html.updateTreeHtml(path))
.scrollpanel()
.show();
h5ai.shiftTree(false, true);
h5ai.linkHoverStates();
H5aiJs.h5ai.shiftTree(false, true);
H5aiJs.h5ai.linkHoverStates();
setTimeout(function () { $("#tree").get(0).updateScrollbar(); }, 1);
});
},
init = function () {
if (h5ai.settings.showTree) {
if (H5aiJs.h5ai.settings.showTree) {
updatePaths();
populateTree();
}
},
tree = {
fetchStatusAndContent: fetchStatusAndContent,
init: init
};
return tree;
return {
fetchStatusAndContent: fetchStatusAndContent,
init: init
};
};

@ -1,6 +1,6 @@
/*global $, Objects */
/*global $, H5aiJs */
Objects.Extended = function (pathCache, h5ai) {
H5aiJs.factory.Extended = function () {
var settings = {
customHeader: "h5ai.header.html",
@ -17,15 +17,15 @@ Objects.Extended = function (pathCache, h5ai) {
var $ul = $("body > nav ul"),
pathname = "/",
path = pathCache.getPath(pathname),
path = H5aiJs.pathCache.getPath(pathname),
pathnameParts = document.location.pathname.split("/");
$ul.append(path.updateCrumbHtml());
$ul.append(H5aiJs.html.updateCrumbHtml(path));
$.each(pathnameParts, function (idx, part) {
if (part !== "") {
pathname += part + "/";
$ul.append(pathCache.getPath(pathname).updateCrumbHtml());
$ul.append(H5aiJs.html.updateCrumbHtml(H5aiJs.pathCache.getPath(pathname)));
}
});
},
@ -37,8 +37,8 @@ Objects.Extended = function (pathCache, h5ai) {
$size = $ths.eq(3).find("a"),
sortquery = document.location.search,
order = {
column: (sortquery.indexOf("C=N") >= 0) ? "name" : (sortquery.indexOf("C=M") >= 0) ? "date" : (sortquery.indexOf("C=S") >= 0) ? "size" : h5ai.settings.sortorder.column,
ascending: (sortquery.indexOf("O=A") >= 0) ? true : (sortquery.indexOf("O=D") >= 0) ? false : h5ai.settings.sortorder.ascending
column: (sortquery.indexOf("C=N") >= 0) ? "name" : (sortquery.indexOf("C=M") >= 0) ? "date" : (sortquery.indexOf("C=S") >= 0) ? "size" : H5aiJs.h5ai.settings.sortorder.column,
ascending: (sortquery.indexOf("O=A") >= 0) ? true : (sortquery.indexOf("O=D") >= 0) ? false : H5aiJs.h5ai.settings.sortorder.ascending
},
$icon, $ul, $li;
@ -66,8 +66,8 @@ Objects.Extended = function (pathCache, h5ai) {
// entries
$("#table td").closest("tr").each(function () {
var path = pathCache.getPath(document.location.pathname, this);
$ul.append(path.updateExtendedHtml());
var path = H5aiJs.pathCache.getPath(document.location.pathname, this);
$ul.append(H5aiJs.html.updateExtendedHtml(path));
});
$("#extended").append($ul);

@ -1,6 +1,6 @@
/*global window, $, Objects, localStorage */
/*global window, $, H5aiJs, localStorage */
Objects.H5ai = function (options, langs) {
H5aiJs.factory.H5ai = function (options, langs) {
var defaults = {
store: {
@ -256,7 +256,7 @@ Objects.H5ai = function (options, langs) {
if ($indicator.hasClass("unknown")) {
$.get("/h5ai/php/treecontent.php", { "href": $entry.find("> a").attr("href") }, function (html) {
var $content = $(html);
$indicator.removeClass("unknown");

260
src/h5ai/js/inc/Html.js Normal file

@ -0,0 +1,260 @@
/*global $, H5aiJs */
H5aiJs.factory.Html = function () {
var imagesPath = "/h5ai/images",
iconsPath = "/h5ai/icons",
image = function (id) {
return imagesPath + "/" + id + ".png";
},
icon = function (id, big) {
return iconsPath + "/" + (big ? "48x48" : "16x16") + "/" + id + ".png";
},
onClick = function (path, context) {
H5aiJs.h5ai.triggerPathClick(path, context);
},
updateCrumbHtml = function (path) {
var $html, $a;
if (path.html.$crumb && path.html.$crumb.data("status") === path.status) {
return path.html.$crumb;
}
$html = $("<li class='crumb' />")
.data("path", path)
.addClass(path.isFolder ? "folder" : "file");
if (path.status) {
$html.data("status", path.status);
}
$a = $("<a><img src='" + image("crumb") + "' alt='>' />" + path.label + "</a>")
.appendTo($html)
.attr("href", path.absHref)
.click(function() { onClick(path, "crumb"); });
if (path.isDomain) {
$html.addClass("domain");
$a.find("img").attr("src", image("home"));
}
if (path.isCurrentFolder) {
$html.addClass("current");
}
if (!isNaN(path.status)) {
if (path.status === 200) {
$("<img class='hint' src='" + image("page") + "' alt='not listable' />").appendTo($a);
} else {
$("<span class='hint'>(" + path.status + ")</span>").appendTo($a);
}
}
if (path.html.$crumb) {
path.html.$crumb.replaceWith($html);
}
path.html.$crumb = $html;
return $html;
},
updateExtendedHtml = function (path) {
var $html, $a, $label;
if (path.html.$extended && path.html.$extended.data("status") === path.status) {
return path.html.$extended;
}
$html = $("<li class='entry' />")
.data("path", path)
.addClass(path.isFolder ? "folder" : "file");
if (path.status) {
$html.data("status", path.status);
}
$label = $("<span class='label'>" + path.label + "</span>");
$a = $("<a />")
.attr("href", path.absHref)
.click(function() { onClick(path, "extended"); })
.appendTo($html)
.append($("<span class='icon small'><img src='" + path.icon16 + "' alt='" + path.alt + "' /></span>"))
.append($("<span class='icon big'><img src='" + path.icon48 + "' alt='" + path.alt + "' /></span>"))
.append($label)
.append($("<span class='date'>" + path.date + "</span>"))
.append($("<span class='size'>" + path.size + "</span>"));
$a.hover(
function () {
if ($("#extended").hasClass("icons-view")) {
var $this = $(this);
$(".status.default").hide();
$(".status.dynamic")
.empty()
.append($this.find(".label").clone())
.append($("<span class='sep'>·</span>"))
.append($this.find(".date").clone())
.show();
if (!$this.closest(".entry").hasClass("folder")) {
$(".status.dynamic")
.append($("<span class='sep'>·</span>"))
.append($this.find(".size").clone());
}
}
},
function () {
$(".status.default").show();
$(".status.dynamic").empty().hide();
}
);
if (path.isParentFolder) {
if (!H5aiJs.h5ai.settings.setParentFolderLabels) {
$label.addClass("l10n-parentDirectory");
}
$html.addClass("folder-parent");
}
if (!isNaN(path.status)) {
if (path.status === 200) {
$html.addClass("page");
$a.find(".icon.small img").attr("src", icon("folder-page"));
$a.find(".icon.big img").attr("src", icon("folder-page", true));
} else {
$html.addClass("error");
$label.append($("<span class='hint'> " + path.status + " </span>"));
}
}
if (path.html.$extended) {
path.html.$extended.replaceWith($html);
}
path.html.$extended = $html;
return $html;
},
updateTreeHtml = function (path) {
var $html, $blank, $a, $indicator, $ul, idx;
$html = $("<div class='entry' />")
.data("path", path)
.addClass(path.isFolder ? "folder" : "file");
$blank = $("<span class='blank' />").appendTo($html);
$a = $("<a />")
.attr("href", path.absHref)
.click(function() { path.onClick(path, "tree"); })
.appendTo($html)
.append($("<span class='icon'><img src='" + path.icon16 + "' /></span>"))
.append($("<span class='label'>" + path.label + "</span>"));
if (path.isFolder) {
// indicator
if (path.status === undefined || !path.isEmpty()) {
$indicator = $("<span class='indicator initiated'><img src='" + image("tree") + "' /></span>")
.click(function (event) {
var $entry = $indicator.closest(".entry"); // $html
if ($indicator.hasClass("unknown")) {
H5aiJs.connector.fetchStatusAndContent(path.absHref, false, function (status, content) {
path.status = status;
path.content = content;
path.treeOpen = true;
$("#tree").get(0).updateScrollbar(true);
updateTreeHtml(path);
$("#tree").get(0).updateScrollbar();
});
} else if ($indicator.hasClass("open")) {
path.treeOpen = false;
$indicator.removeClass("open");
$("#tree").get(0).updateScrollbar(true);
$entry.find("> ul.content").slideUp(function() {
$("#tree").get(0).updateScrollbar();
});
} else {
path.treeOpen = true;
$indicator.addClass("open");
$("#tree").get(0).updateScrollbar(true);
$entry.find("> ul.content").slideDown(function() {
$("#tree").get(0).updateScrollbar();
});
}
});
if (path.status === undefined) {
$indicator.addClass("unknown");
} else if (path.treeOpen) {
$indicator.addClass("open");
}
$blank.replaceWith($indicator);
}
// is path the domain?
if (path.isDomain) {
$html.addClass("domain");
$a.find(".icon img").attr("src", icon("folder-home"));
}
// is path the current folder?
if (path.isCurrentFolder) {
$html.addClass("current");
$a.find(".icon img").attr("src", icon("folder-open"));
}
// does it have subfolders?
if (!path.isEmpty()) {
$ul = $("<ul class='content' />").appendTo($html);
$.each(path.content, function (idx, entry) {
$("<li />").append(updateTreeHtml(entry)).appendTo($ul);
});
if (path.status === undefined || !path.treeOpen) {
$ul.hide();
}
}
// reflect folder status
if (!isNaN(path.status)) {
if (path.status === 200) {
$a.find(".icon img").attr("src", icon("folder-page"));
$a.append($("<span class='hint'><img src='" + image("page") + "' /></span>"));
} else {
$html.addClass("error");
$a.append($("<span class='hint'>" + path.status + "</span>"));
}
}
}
if (path.html.$tree) {
path.html.$tree.replaceWith($html);
}
path.html.$tree = $html;
return $html;
},
updateHtml = function (path) {
updateCrumbHtml(path);
updateExtendedHtml(path);
updateTreeHtml(path);
};
return {
updateCrumbHtml: updateCrumbHtml,
updateExtendedHtml: updateExtendedHtml,
updateTreeHtml: updateTreeHtml,
updateHtml: updateHtml
};
};

105
src/h5ai/js/inc/Path.js Normal file

@ -0,0 +1,105 @@
/*global $, H5aiJs */
H5aiJs.factory.Path = function (folder, tableRow) {
var path,
checkedDecodeUri = function (uri) {
try { return decodeURI(uri); } catch (err) {}
return uri;
},
isEmpty = function () {
return !path.content || $.isEmptyObject(path.content);
},
onClick = function (context) {
H5aiJs.h5ai.triggerPathClick(path, context);
},
init = function () {
var $tds, $img, $a, splits;
path = {
// parentFolder: undefined,
// label: undefined,
// date: undefined,
// size: undefined,
// href: undefined,
// absHref: undefined,
// alt: undefined,
// icon16: undefined,
// icon48: undefined,
// isFolder: undefined,
// isParentFolder: undefined,
// isCurrentFolder: undefined,
// isDomain: undefined,
status: undefined, // undefined, "h5ai" or HTTP response code
content: undefined, // associative array path.absHref -> path
html: {
$crumb: undefined,
$extended: undefined,
$tree: undefined
},
treeOpen: false,
isEmpty: isEmpty,
onClick: onClick
};
if (!H5aiJs.pathCache.pathEndsWithSlash(folder)) {
folder += "/";
}
if (tableRow) {
$tds = $(tableRow).find("td");
$img = $tds.eq(0).find("img");
$a = $tds.eq(1).find("a");
path.parentFolder = folder;
path.label = $a.text();
path.date = $tds.eq(2).text();
path.size = $tds.eq(3).text();
path.href = $a.attr("href");
path.alt = $img.attr("alt");
path.icon16 = $img.attr("src");
} else {
splits = H5aiJs.pathCache.splitPathname(folder);
path.parentFolder = splits[0];
path.label = checkedDecodeUri(splits[1]);
if (path.label === "/") {
path.label = checkedDecodeUri(document.domain) + "/";
}
path.date = "";
path.size = "";
path.href = splits[1];
path.alt = "[DIR]";
path.icon16 = "/h5ai/icons/16x16/folder.png";
}
if (H5aiJs.pathCache.pathEndsWithSlash(path.label)) {
path.label = path.label.slice(0, -1);
}
path.icon48 = path.icon16.replace("16x16", "48x48");
path.isFolder = (path.alt === "[DIR]");
path.isParentFolder = (path.isFolder && path.label === "Parent Directory");
path.absHref = path.isParentFolder ? path.href : path.parentFolder + path.href;
path.isCurrentFolder = (path.absHref === document.location.pathname);
path.isDomain = (path.absHref === "/");
if (path.isParentFolder && H5aiJs.h5ai.settings.setParentFolderLabels) {
if (path.isDomain) {
path.label = checkedDecodeUri(document.domain);
} else {
path.label = checkedDecodeUri(H5aiJs.pathCache.splitPathname(H5aiJs.pathCache.splitPathname(path.parentFolder)[0])[1].slice(0, -1));
}
}
};
init();
return path;
};

@ -0,0 +1,61 @@
/*global $, H5aiJs */
H5aiJs.factory.PathCache = function () {
var pathCache,
cache = {},
rePathnameSplit = /^(\/(.*\/)*)([^\/]+\/?)$/,
rePathEndsWithSlash = /\/$/,
splitPathname = function (pathname) {
var match;
if (pathname === "/") {
return ["", "/"];
}
match = rePathnameSplit.exec(pathname);
return [match[1], match[3]];
},
pathEndsWithSlash = function (pathname) {
return rePathEndsWithSlash.test(pathname);
},
getAbsHref = function (folder, tableRow) {
var $a, isParentFolder, href;
if (!pathEndsWithSlash(folder)) {
folder += "/";
}
if (!tableRow) {
return folder;
}
$a = $(tableRow).find("td").eq(1).find("a");
isParentFolder = ($a.text() === "Parent Directory");
href = $a.attr("href");
return isParentFolder ? undefined : folder + href;
},
getPath = function (folder, tableRow) {
var absHref = getAbsHref(folder, tableRow),
path = cache[absHref];
if (!path) {
path = new H5aiJs.factory.Path(folder, tableRow);
if (!path.isParentFolder) {
cache[path.absHref] = path;
}
}
return path;
};
pathCache = {
splitPathname: splitPathname,
pathEndsWithSlash: pathEndsWithSlash,
getPath: getPath,
cache: cache
};
return pathCache;
};

@ -1,404 +0,0 @@
/*global $, Objects */
Objects.Path = function (pathCache, folder, tableRow) {
var path,
checkedDecodeUri = function (uri) {
try { return decodeURI(uri); } catch (err) {}
return uri;
},
isEmpty = function () {
return !path.content || $.isEmptyObject(path.content);
},
onClick = function (context) {
h5ai.triggerPathClick(path, context);
},
updateHtml = function () {
path.updateCrumbHtml();
path.updateExtendedHtml();
path.updateTreeHtml();
},
updateCrumbHtml = function () {
var $html, $a;
if (path.html.$crumb && path.html.$crumb.data("status") === path.status) {
return path.html.$crumb;
}
$html = $("<li class='crumb' />")
.data("path", path)
.addClass(path.isFolder ? "folder" : "file");
if (path.status) {
$html.data("status", path.status);
}
$a = $("<a><img src='/h5ai/images/crumb.png' alt='>' />" + path.label + "</a>")
.appendTo($html)
.attr("href", path.absHref)
.click(function() { onClick("crumb"); });
if (path.isDomain) {
$html.addClass("domain");
$a.find("img").attr("src", "/h5ai/images/home.png");
}
if (path.isCurrentFolder) {
$html.addClass("current");
}
if (!isNaN(path.status)) {
if (path.status === 200) {
$("<img class='hint' src='/h5ai/images/page.png' alt='not listable' />").appendTo($a);
} else {
$("<span class='hint'>(" + path.status + ")</span>").appendTo($a);
}
}
if (path.html.$crumb) {
path.html.$cpathreplaceWith($html);
}
path.html.$crumb = $html;
return $html;
},
updateExtendedHtml = function () {
var $html, $a, $label;
if (path.html.$extended && path.html.$extended.data("status") === path.status) {
return path.html.$extended;
}
$html = $("<li class='entry' />")
.data("path", path)
.addClass(path.isFolder ? "folder" : "file");
if (path.status) {
$html.data("status", path.status);
}
$label = $("<span class='label'>" + path.label + "</span>");
$a = $("<a />")
.attr("href", path.absHref)
.click(function() { onClick("extended"); })
.appendTo($html)
.append($("<span class='icon small'><img src='" + path.icon16 + "' alt='" + path.alt + "' /></span>"))
.append($("<span class='icon big'><img src='" + path.icon48 + "' alt='" + path.alt + "' /></span>"))
.append($label)
.append($("<span class='date'>" + path.date + "</span>"))
.append($("<span class='size'>" + path.size + "</span>"));
$a.hover(
function () {
if ($("#extended").hasClass("icons-view")) {
var $this = $(this);
$(".status.default").hide();
$(".status.dynamic")
.empty()
.append($this.find(".label").clone())
.append($("<span class='sep'>·</span>"))
.append($this.find(".date").clone())
.show();
if (!$this.closest(".entry").hasClass("folder")) {
$(".status.dynamic")
.append($("<span class='sep'>·</span>"))
.append($this.find(".size").clone());
}
}
},
function () {
$(".status.default").show();
$(".status.dynamic").empty().hide();
}
);
if (path.isParentFolder) {
if (!h5ai.settings.setParentFolderLabels) {
$label.addClass("l10n-parentDirectory");
}
$html.addClass("folder-parent");
}
if (!isNaN(path.status)) {
if (path.status === 200) {
$html.addClass("page");
$a.find(".icon.small img").attr("src", "/h5ai/icons/16x16/folder-page.png");
$a.find(".icon.big img").attr("src", "/h5ai/icons/48x48/folder-page.png");
} else {
$html.addClass("error");
$label.append($("<span class='hint'> " + path.status + " </span>"));
}
}
if (path.html.$extended) {
path.html.$extended.replaceWith($html);
}
path.html.$extended = $html;
return $html;
},
updateTreeHtml = function () {
var $html, $blank, $a, $indicator, $ul, idx;
$html = $("<div class='entry' />")
.data("path", path)
.addClass(path.isFolder ? "folder" : "file");
$blank = $("<span class='blank' />").appendTo($html);
$a = $("<a />")
.attr("href", path.absHref)
.click(function() { path.onClick("tree"); })
.appendTo($html)
.append($("<span class='icon'><img src='" + path.icon16 + "' /></span>"))
.append($("<span class='label'>" + path.label + "</span>"));
if (path.isFolder) {
// indicator
if (path.status === undefined || !path.isEmpty()) {
$indicator = $("<span class='indicator'><img src='/h5ai/images/tree.png' /></span>");
if (path.status === undefined) {
$indicator.addClass("unknown");
} else if (path.treeOpen) {
$indicator.addClass("open");
}
$indicator.click(function(event) {
if ($indicator.hasClass("unknown")) {
tree.fetchStatusAndContent(path.absHref, false, function (status, content) {
path.status = status;
path.content = content;
path.treeOpen = true;
$("#tree").get(0).updateScrollbar(true);
path.updateTreeHtml(function() {
$("#tree").get(0).updateScrollbar();
});
});
} else if ($indicator.hasClass("open")) {
path.treeOpen = false;
$indicator.removeClass("open");
$("#tree").get(0).updateScrollbar(true);
$html.find("> ul.content").slideUp(function() {
$("#tree").get(0).updateScrollbar();
});
} else {
path.treeOpen = true;
$indicator.addClass("open");
$("#tree").get(0).updateScrollbar(true);
$html.find("> ul.content").slideDown(function() {
$("#tree").get(0).updateScrollbar();
});
}
});
$html.addClass("initiatedIndicator");
$blank.replaceWith($indicator);
}
// is path the domain?
if (path.isDomain) {
$html.addClass("domain");
$a.find(".icon img").attr("src", "/h5ai/icons/16x16/folder-home.png");
}
// is path the current folder?
if (path.isCurrentFolder) {
$html.addClass("current");
$a.find(".icon img").attr("src", "/h5ai/icons/16x16/folder-open.png");
}
// does it have subfolders?
if (!path.isEmpty()) {
$ul = $("<ul class='content' />").appendTo($html);
$.each(path.content, function (idx, entry) {
$("<li />").append(entry.updateTreeHtml()).appendTo($ul);
});
if (path.status === undefined || !path.treeOpen) {
$ul.hide();
}
}
// reflect folder status
if (!isNaN(path.status)) {
if (path.status === 200) {
$a.find(".icon img").attr("src", "/h5ai/icons/16x16/folder-page.png");
$a.append($("<span class='hint'><img src='/h5ai/images/page.png' /></span>"));
} else {
$html.addClass("error");
$a.append($("<span class='hint'>" + path.status + "</span>"));
}
}
}
if (path.html.$tree) {
path.html.$tree.replaceWith($html);
}
path.html.$tree = $html;
return $html;
},
init = function () {
var $tds, $img, $a, splits;
path = {
// parentFolder: undefined,
// label: undefined,
// date: undefined,
// size: undefined,
// href: undefined,
// absHref: undefined,
// alt: undefined,
// icon16: undefined,
// icon48: undefined,
// isFolder: undefined,
// isParentFolder: undefined,
// isCurrentFolder: undefined,
// isDomain: undefined,
status: undefined, // undefined, "h5ai" or HTTP response code
content: undefined, // associative array path.absHref -> path
html: {
$crumb: undefined,
$extended: undefined,
$tree: undefined
},
treeOpen: false,
isEmpty: isEmpty,
onClick: onClick,
updateHtml: updateHtml,
updateCrumbHtml: updateCrumbHtml,
updateExtendedHtml: updateExtendedHtml,
updateTreeHtml: updateTreeHtml
};
if (!pathCache.pathEndsWithSlash(folder)) {
folder += "/";
}
if (tableRow) {
$tds = $(tableRow).find("td");
$img = $tds.eq(0).find("img");
$a = $tds.eq(1).find("a");
path.parentFolder = folder;
path.label = $a.text();
path.date = $tds.eq(2).text();
path.size = $tds.eq(3).text();
path.href = $a.attr("href");
path.alt = $img.attr("alt");
path.icon16 = $img.attr("src");
} else {
splits = pathCache.splitPathname(folder);
path.parentFolder = splits[0];
path.label = checkedDecodeUri(splits[1]);
if (path.label === "/") {
path.label = checkedDecodeUri(document.domain) + "/";
}
path.date = "";
path.size = "";
path.href = splits[1];
path.alt = "[DIR]";
path.icon16 = "/h5ai/icons/16x16/folder.png";
}
if (pathCache.pathEndsWithSlash(path.label)) {
path.label = path.label.slice(0, -1);
}
path.icon48 = path.icon16.replace("16x16", "48x48");
path.isFolder = (path.alt === "[DIR]");
path.isParentFolder = (path.isFolder && path.label === "Parent Directory");
path.absHref = path.isParentFolder ? path.href : path.parentFolder + path.href;
path.isCurrentFolder = (path.absHref === document.location.pathname);
path.isDomain = (path.absHref === "/");
if (path.isParentFolder && h5ai.settings.setParentFolderLabels) {
if (path.isDomain) {
path.label = checkedDecodeUri(document.domain);
} else {
path.label = checkedDecodeUri(pathCache.splitPathname(pathCache.splitPathname(path.parentFolder)[0])[1].slice(0, -1));
}
}
};
init();
return path;
};
Objects.PathCache = function () {
var pathCache,
cache = {},
rePathnameSplit = /^(\/(.*\/)*)([^\/]+\/?)$/,
rePathEndsWithSlash = /\/$/,
splitPathname = function (pathname) {
var match;
if (pathname === "/") {
return ["", "/"];
}
match = rePathnameSplit.exec(pathname);
return [match[1], match[3]];
},
pathEndsWithSlash = function (pathname) {
return rePathEndsWithSlash.test(pathname);
},
getAbsHref = function (folder, tableRow) {
var $a, isParentFolder, href;
if (!pathEndsWithSlash(folder)) {
folder += "/";
}
if (!tableRow) {
return folder;
}
$a = $(tableRow).find("td").eq(1).find("a");
isParentFolder = ($a.text() === "Parent Directory");
href = $a.attr("href");
return isParentFolder ? undefined : folder + href;
},
getPath = function (folder, tableRow) {
var absHref = getAbsHref(folder, tableRow),
path = cache[absHref];
if (!path) {
path = new Objects.Path(pathCache, folder, tableRow);
if (!path.isParentFolder) {
cache[path.absHref] = path;
}
}
return path;
};
pathCache = {
splitPathname: splitPathname,
pathEndsWithSlash: pathEndsWithSlash,
getPath: getPath,
cache: cache
};
return pathCache;
};

@ -6,28 +6,35 @@
(function($) {
"use strict";
var Objects = {},
pathCache, h5ai, extended, tree;
var H5aiJs = {
factory: {},
init: function () {
this.h5ai = new this.factory.H5ai(h5aiOptions, h5aiLangs);
this.pathCache = new this.factory.PathCache();
this.connector = new this.factory.Connector();
this.html = new this.factory.Html();
this.extended = new this.factory.Extended();
// @include "inc/h5ai.js"
// @include "inc/path.js"
// @include "inc/extended.js"
// @include "inc/tree.js"
this.extended.init();
this.connector.init();
this.h5ai.init();
pathCache = new Objects.PathCache();
h5ai = new Objects.H5ai(h5aiOptions, h5aiLangs);
extended = new Objects.Extended(pathCache, h5ai);
tree = new Objects.Tree(pathCache, h5ai);
$.h5ai = {
click: $.proxy(this.h5ai.pathClick, this.h5ai)
};
}
};
$.h5ai = {
click: $.proxy(h5ai.pathClick, h5ai)
};
// @include "inc/H5ai.js"
// @include "inc/Path.js"
// @include "inc/PathCache.js"
// @include "inc/Connector.js"
// @include "inc/Html.js"
// @include "inc/Extended.js"
$(function () {
extended.init();
tree.init();
h5ai.init();
H5aiJs.init();
});
}(jQuery));

@ -6,22 +6,26 @@
(function($) {
"use strict";
var Objects = {},
h5ai;
var H5aiJs = {
factory: {},
init: function () {
this.h5ai = new this.factory.H5ai(h5aiOptions, h5aiLangs);
// @include "inc/h5ai.js"
this.h5ai.init();
$("#tree").scrollpanel();
this.h5ai.shiftTree(false, true);
h5ai = new Objects.H5ai(h5aiOptions, h5aiLangs);
$.h5ai = {
click: $.proxy(this.h5ai.pathClick, this.h5ai)
};
}
};
$.h5ai = {
click: $.proxy(h5ai.pathClick, h5ai)
};
// @include "inc/H5ai.js"
$(function () {
h5ai.init();
$("#tree").scrollpanel();
h5ai.shiftTree(false, true);
H5aiJs.init();
});
}(jQuery));