mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-06 09:41:14 -04:00
More refactorings.
This commit is contained in:
parent
4c1ed3d1e8
commit
caced60eaa
10 changed files with 150 additions and 165 deletions
|
@ -16,5 +16,5 @@ release.dir = release
|
|||
|
||||
|
||||
# tools
|
||||
wepp = tools/wepp
|
||||
tool.wepp = tools/wepp
|
||||
|
||||
|
|
|
@ -99,18 +99,14 @@ H5aiJs.factory.Extended = function () {
|
|||
|
||||
$(".folderCount").text($("#extended .entry.folder:not(.parentfolder)").size());
|
||||
$(".fileCount").text($("#extended .entry.file").size());
|
||||
},
|
||||
init = function () {
|
||||
};
|
||||
|
||||
this.init = function () {
|
||||
|
||||
initTitle();
|
||||
initBreadcrumb();
|
||||
initExtendedView();
|
||||
customize();
|
||||
initCounts();
|
||||
},
|
||||
extended = {
|
||||
init: init
|
||||
};
|
||||
|
||||
return extended;
|
||||
};
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
H5aiJs.factory.H5ai = function (options, langs) {
|
||||
|
||||
var defaults = {
|
||||
var $window = $(window),
|
||||
defaults = {
|
||||
store: {
|
||||
viewmode: "h5ai.viewmode",
|
||||
lang: "h5ai.lang"
|
||||
|
@ -41,7 +42,7 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
triggerPathClick = function (path, context) {
|
||||
|
||||
$.each(settings.callbacks.pathClick, function (idx, callback) {
|
||||
callback.call(window, path, context);
|
||||
callback(path, context);
|
||||
});
|
||||
},
|
||||
getViewmode = function () {
|
||||
|
@ -82,7 +83,7 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
|
||||
var adjustTopSpace = function () {
|
||||
|
||||
var winHeight = $(window).height(),
|
||||
var winHeight = $window.height(),
|
||||
navHeight = $("body > nav").outerHeight(),
|
||||
footerHeight = $("body > footer").outerHeight(),
|
||||
contentSpacing = 50,
|
||||
|
@ -103,7 +104,7 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
} catch (err) {}
|
||||
};
|
||||
|
||||
$(window).resize(function () {
|
||||
$window.resize(function () {
|
||||
adjustTopSpace();
|
||||
});
|
||||
adjustTopSpace();
|
||||
|
@ -168,7 +169,7 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
function () { shiftTree(true); },
|
||||
function () { shiftTree(); }
|
||||
);
|
||||
$(window).resize(function () { shiftTree(); });
|
||||
$window.resize(function () { shiftTree(); });
|
||||
shiftTree(false, true);
|
||||
},
|
||||
linkHoverStates = function () {
|
||||
|
@ -266,7 +267,9 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
$indicator.addClass("open");
|
||||
$entry.find("> .content").replaceWith($content);
|
||||
$("#tree").get(0).updateScrollbar();
|
||||
initIndicators();
|
||||
$content.find(".indicator:not(.initiated)")
|
||||
.click(onIndicatorClick)
|
||||
.addClass("initiated");
|
||||
}
|
||||
});
|
||||
} else if ($indicator.hasClass("open")) {
|
||||
|
@ -285,16 +288,14 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
},
|
||||
initIndicators = function () {
|
||||
|
||||
$("#tree .entry.folder .indicator:not(.initiated)").each(function () {
|
||||
|
||||
$(this).addClass("initiated").click(onIndicatorClick);
|
||||
});
|
||||
$("#tree .entry.folder .indicator:not(.initiated)")
|
||||
.click(onIndicatorClick)
|
||||
.addClass("initiated");
|
||||
},
|
||||
initZippedDownload = function () {
|
||||
|
||||
var x = 0,
|
||||
y = 0,
|
||||
$window = $(window),
|
||||
selected = function (hrefs) {
|
||||
|
||||
var query, idx;
|
||||
|
@ -377,8 +378,9 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
localize(langs, settings.lang, settings.useBrowserLang);
|
||||
initIndicators();
|
||||
initZippedDownload();
|
||||
},
|
||||
h5ai = {
|
||||
};
|
||||
|
||||
return {
|
||||
settings: settings,
|
||||
shiftTree: shiftTree,
|
||||
linkHoverStates: linkHoverStates,
|
||||
|
@ -387,6 +389,4 @@ H5aiJs.factory.H5ai = function (options, langs) {
|
|||
initIndicators: initIndicators,
|
||||
init: init
|
||||
};
|
||||
|
||||
return h5ai;
|
||||
};
|
||||
|
|
|
@ -2,25 +2,13 @@
|
|||
|
||||
H5aiJs.factory.Path = function (folder, tableRow) {
|
||||
|
||||
var path,
|
||||
checkedDecodeUri = function (uri) {
|
||||
var checkedDecodeUri = function (uri) {
|
||||
|
||||
try { return decodeURI(uri); } catch (err) {}
|
||||
return uri;
|
||||
},
|
||||
isEmpty = function () {
|
||||
$tds, $img, $a, splits;
|
||||
|
||||
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,
|
||||
|
@ -35,18 +23,14 @@ H5aiJs.factory.Path = function (folder, tableRow) {
|
|||
// isCurrentFolder: undefined,
|
||||
// isDomain: undefined,
|
||||
|
||||
status: undefined, // undefined, "h5ai" or HTTP response code
|
||||
content: undefined, // associative array path.absHref -> path
|
||||
html: {
|
||||
this.status = undefined; // undefined, "h5ai" or HTTP response code
|
||||
this.content = undefined; // associative array path.absHref -> path
|
||||
this.html = {
|
||||
$crumb: undefined,
|
||||
$extended: undefined,
|
||||
$tree: undefined
|
||||
},
|
||||
treeOpen: false,
|
||||
|
||||
isEmpty: isEmpty,
|
||||
onClick: onClick
|
||||
};
|
||||
this.treeOpen = false;
|
||||
|
||||
if (!H5aiJs.pathCache.pathEndsWithSlash(folder)) {
|
||||
folder += "/";
|
||||
|
@ -57,49 +41,56 @@ H5aiJs.factory.Path = function (folder, tableRow) {
|
|||
$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");
|
||||
this.parentFolder = folder;
|
||||
this.label = $a.text();
|
||||
this.date = $tds.eq(2).text();
|
||||
this.size = $tds.eq(3).text();
|
||||
this.href = $a.attr("href");
|
||||
this.alt = $img.attr("alt");
|
||||
this.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) + "/";
|
||||
this.parentFolder = splits[0];
|
||||
this.label = checkedDecodeUri(splits[1]);
|
||||
if (this.label === "/") {
|
||||
this.label = checkedDecodeUri(document.domain) + "/";
|
||||
}
|
||||
path.date = "";
|
||||
path.size = "";
|
||||
path.href = splits[1];
|
||||
path.alt = "[DIR]";
|
||||
path.icon16 = "/h5ai/icons/16x16/folder.png";
|
||||
this.date = "";
|
||||
this.size = "";
|
||||
this.href = splits[1];
|
||||
this.alt = "[DIR]";
|
||||
this.icon16 = "/h5ai/icons/16x16/folder.png";
|
||||
}
|
||||
|
||||
if (H5aiJs.pathCache.pathEndsWithSlash(path.label)) {
|
||||
path.label = path.label.slice(0, -1);
|
||||
if (H5aiJs.pathCache.pathEndsWithSlash(this.label)) {
|
||||
this.label = this.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 === "/");
|
||||
this.icon48 = this.icon16.replace("16x16", "48x48");
|
||||
this.isFolder = (this.alt === "[DIR]");
|
||||
this.isParentFolder = (this.isFolder && this.label === "Parent Directory");
|
||||
this.absHref = this.isParentFolder ? this.href : this.parentFolder + this.href;
|
||||
this.isCurrentFolder = (this.absHref === document.location.pathname);
|
||||
this.isDomain = (this.absHref === "/");
|
||||
|
||||
if (path.isParentFolder && H5aiJs.h5ai.settings.setParentFolderLabels) {
|
||||
if (path.isDomain) {
|
||||
path.label = checkedDecodeUri(document.domain);
|
||||
if (this.isParentFolder && H5aiJs.h5ai.settings.setParentFolderLabels) {
|
||||
if (this.isDomain) {
|
||||
this.label = checkedDecodeUri(document.domain);
|
||||
} else {
|
||||
path.label = checkedDecodeUri(H5aiJs.pathCache.splitPathname(H5aiJs.pathCache.splitPathname(path.parentFolder)[0])[1].slice(0, -1));
|
||||
this.label = checkedDecodeUri(H5aiJs.pathCache.splitPathname(H5aiJs.pathCache.splitPathname(this.parentFolder)[0])[1].slice(0, -1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
H5aiJs.factory.Path.prototype = {
|
||||
|
||||
isEmpty: function () {
|
||||
|
||||
return !this.content || $.isEmptyObject(this.content);
|
||||
},
|
||||
onClick: function (context) {
|
||||
|
||||
H5aiJs.h5ai.triggerPathClick(this, context);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
H5aiJs.factory.PathCache = function () {
|
||||
|
||||
var pathCache,
|
||||
cache = {},
|
||||
var cache = {},
|
||||
rePathnameSplit = /^(\/(.*\/)*)([^\/]+\/?)$/,
|
||||
rePathEndsWithSlash = /\/$/,
|
||||
splitPathname = function (pathname) {
|
||||
|
@ -50,12 +49,8 @@ H5aiJs.factory.PathCache = function () {
|
|||
return path;
|
||||
};
|
||||
|
||||
pathCache = {
|
||||
splitPathname: splitPathname,
|
||||
pathEndsWithSlash: pathEndsWithSlash,
|
||||
getPath: getPath,
|
||||
cache: cache
|
||||
};
|
||||
|
||||
return pathCache;
|
||||
this.splitPathname = splitPathname;
|
||||
this.pathEndsWithSlash = pathEndsWithSlash;
|
||||
this.getPath = getPath;
|
||||
this.cache = cache;
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
|
||||
// modified
|
||||
$.log = function () {
|
||||
|
||||
$.log.history = $.log.history || [];
|
||||
$.log.history.push(arguments);
|
||||
if (window.console) {
|
||||
|
@ -14,17 +15,17 @@
|
|||
};
|
||||
|
||||
$.timer = (function () {
|
||||
|
||||
var start = $.now(),
|
||||
last = start,
|
||||
timer = {
|
||||
last = start;
|
||||
|
||||
return {
|
||||
log: function (label) {
|
||||
var now = $.now();
|
||||
$.log("timer", label, "+" + (now - last), "=" + (now - start));
|
||||
last = now;
|
||||
}
|
||||
};
|
||||
|
||||
return timer;
|
||||
}());
|
||||
|
||||
}(jQuery));
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
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();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
var H5aiJs = {
|
||||
factory: {},
|
||||
init: function () {
|
||||
|
||||
this.h5ai = new this.factory.H5ai(h5aiOptions, h5aiLangs);
|
||||
|
||||
this.h5ai.init();
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<attribute name="toFile" />
|
||||
<attribute name="args" default="" />
|
||||
<sequential>
|
||||
<exec executable="${wepp}">
|
||||
<exec executable="${tool.wepp}">
|
||||
<arg line="@{args}" />
|
||||
<arg value="--in" />
|
||||
<arg value="@{file}" />
|
||||
|
@ -20,7 +20,7 @@
|
|||
<attribute name="dir" />
|
||||
<attribute name="args" default="" />
|
||||
<sequential>
|
||||
<exec executable="${wepp}">
|
||||
<exec executable="${tool.wepp}">
|
||||
<arg line="@{args}" />
|
||||
<arg value="--inDir" />
|
||||
<arg value="@{dir}" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue