diff --git a/src/_h5ai/js/inc/Connector.js b/src/_h5ai/js/inc/Connector.js
index ceaa0619..f5c57a68 100644
--- a/src/_h5ai/js/inc/Connector.js
+++ b/src/_h5ai/js/inc/Connector.js
@@ -1,115 +1,112 @@
(function ($, H5AI) {
- H5AI.connector = (function () {
+ var cache = {},
+ pathnameStatusCache = {},
+ contentTypeRegEx = /^text\/html;h5ai=/,
+ getPath = function (folder, tableRow) {
- var cache = {},
- pathnameStatusCache = {},
- contentTypeRegEx = /^text\/html;h5ai=/,
- getPath = function (folder, tableRow) {
+ var absHref = H5AI.util.getAbsHref(folder, tableRow),
+ path = cache[absHref];
- var absHref = H5AI.util.getAbsHref(folder, tableRow),
- path = cache[absHref];
-
- if (!path) {
- path = H5AI.Path(folder, tableRow);
- if (!path.isParentFolder) {
- cache[path.absHref] = path;
- }
+ if (!path) {
+ path = H5AI.Path(folder, tableRow);
+ if (!path.isParentFolder) {
+ cache[path.absHref] = path;
}
+ }
- return path;
- },
- fetchStatus = function (pathname, callback) {
+ return path;
+ },
+ fetchStatus = function (pathname, callback) {
- if (H5AI.core.settings.folderStatus[pathname]) {
- callback(H5AI.core.settings.folderStatus[pathname]);
- return;
- } else if (pathnameStatusCache[pathname]) {
- callback(pathnameStatusCache[pathname]);
+ if (H5AI.core.settings.folderStatus[pathname]) {
+ callback(H5AI.core.settings.folderStatus[pathname]);
+ return;
+ } else if (pathnameStatusCache[pathname]) {
+ callback(pathnameStatusCache[pathname]);
+ return;
+ }
+
+ $.ajax({
+ url: pathname,
+ type: "HEAD",
+ complete: function (xhr) {
+
+ var status = xhr.status;
+
+ if (status === 200 && contentTypeRegEx.test(xhr.getResponseHeader("Content-Type"))) {
+ status = "h5ai";
+ }
+ pathnameStatusCache[pathname] = status;
+ callback(status);
+ }
+ });
+ },
+ updatePath = function (path) {
+
+ if (path.isFolder && !path.isParentFolder && path.status === undefined) {
+ fetchStatus(path.absHref, function (status) {
+
+ if (status !== "h5ai") {
+ path.status = status;
+ }
+ H5AI.html.updateHtml(path);
+ H5AI.core.linkHoverStates();
+ });
+ }
+ },
+ updatePaths = function () {
+
+ $.each(cache, function (ref, cached) {
+ updatePath(cached);
+ });
+ },
+ fetchStatusAndContent = function (pathname, includeParent, callback) {
+
+ fetchStatus(pathname, function (status) {
+
+ if (status !== "h5ai") {
+ callback(status, {});
return;
}
$.ajax({
url: pathname,
- type: "HEAD",
- complete: function (xhr) {
+ type: "GET",
+ dataType: "html",
+ error: function (xhr) {
- var status = xhr.status;
+ callback(xhr.status, {}); // since it was checked before this should never happen
+ },
+ success: function (html, status, xhr) {
- if (status === 200 && contentTypeRegEx.test(xhr.getResponseHeader("Content-Type"))) {
- status = "h5ai";
- }
- pathnameStatusCache[pathname] = status;
- callback(status);
- }
- });
- },
- updatePath = function (path) {
-
- if (path.isFolder && !path.isParentFolder && path.status === undefined) {
- fetchStatus(path.absHref, function (status) {
-
- if (status !== "h5ai") {
- path.status = status;
- }
- H5AI.html.updateHtml(path);
- H5AI.core.linkHoverStates();
- });
- }
- },
- updatePaths = function () {
-
- $.each(cache, function (ref, cached) {
- updatePath(cached);
- });
- },
- fetchStatusAndContent = function (pathname, includeParent, callback) {
-
- fetchStatus(pathname, function (status) {
-
- if (status !== "h5ai") {
- callback(status, {});
- return;
- }
-
- $.ajax({
- url: pathname,
- type: "GET",
- dataType: "html",
- error: function (xhr) {
+ var content = {};
+ if (!contentTypeRegEx.test(xhr.getResponseHeader("Content-Type"))) {
callback(xhr.status, {}); // since it was checked before this should never happen
- },
- success: function (html, status, xhr) {
-
- var content = {};
-
- if (!contentTypeRegEx.test(xhr.getResponseHeader("Content-Type"))) {
- callback(xhr.status, {}); // since it was checked before this should never happen
- return;
- }
-
- $(html).find("#table td").closest("tr").each(function () {
-
- var path = getPath(pathname, this);
-
- if (path.isFolder && (!path.isParentFolder || includeParent)) {
- content[path.absHref] = path;
- updatePath(path);
- }
- });
- callback("h5ai", content);
+ return;
}
- });
- });
- };
- return {
- getPath: getPath,
- updatePaths: updatePaths,
- fetchStatusAndContent: fetchStatusAndContent
+ $(html).find("#table td").closest("tr").each(function () {
+
+ var path = getPath(pathname, this);
+
+ if (path.isFolder && (!path.isParentFolder || includeParent)) {
+ content[path.absHref] = path;
+ updatePath(path);
+ }
+ });
+ callback("h5ai", content);
+ }
+ });
+ });
};
- }());
+
+ H5AI.connector = {
+ getPath: getPath,
+ updatePaths: updatePaths,
+ fetchStatusAndContent: fetchStatusAndContent
+ };
}(jQuery, H5AI));
diff --git a/src/_h5ai/js/inc/Context.js b/src/_h5ai/js/inc/Context.js
index 0c169696..eb856923 100644
--- a/src/_h5ai/js/inc/Context.js
+++ b/src/_h5ai/js/inc/Context.js
@@ -1,55 +1,51 @@
(function ($, H5AI) {
- H5AI.context = (function () {
+ var $context,
+ qrCodesSize,
+ showQrCode = function ($a) {
- var $context,
- qrCodesSize,
- showQrCode = function ($a) {
+ var absHref = $a.attr('href'),
+ url = 'http://' + document.domain + absHref;
- var absHref = $a.attr('href'),
- url = 'http://' + document.domain + absHref;
+ $context.find('.qrcode').empty().qrcode({
+ render: Modernizr.canvas ? 'canvas' : 'div',
+ width: qrCodesSize,
+ height: qrCodesSize,
+ color: '#333',
+ text: url
+ });
+ },
+ init = function () {
- $context.find('.qrcode').empty().qrcode({
- render: Modernizr.canvas ? 'canvas' : 'div',
- width: qrCodesSize,
- height: qrCodesSize,
- color: '#333',
- text: url
+ qrCodesSize = H5AI.core.settings.qrCodesSize;
+ if (!qrCodesSize) {
+ return;
+ }
+
+ var hideTimeoutId = null;
+
+ $context = $('
');
+ $context.appendTo('body');
+
+ $('#extended')
+ .on('mouseenter', '.entry.file a', function () {
+
+ showQrCode($(this));
+ clearTimeout(hideTimeoutId);
+ $context.stop(true, true).fadeIn(400);
+ })
+ .on('mouseleave', '.entry.file a', function () {
+
+ hideTimeoutId = setTimeout(function () {
+
+ $context.stop(true, true).fadeOut(400);
+ }, 200);
});
- },
- init = function () {
-
- qrCodesSize = H5AI.core.settings.qrCodesSize;
- if (!qrCodesSize) {
- return;
- }
-
- var hideTimeoutId = null;
-
- $context = $('');
- $context.appendTo('body');
-
- $('#extended')
- .on('mouseenter', '.entry.file a', function () {
-
- showQrCode($(this));
- clearTimeout(hideTimeoutId);
- $context.stop(true, true).fadeIn(400);
- })
- .on('mouseleave', '.entry.file a', function () {
-
- hideTimeoutId = setTimeout(function () {
-
- $context.stop(true, true).fadeOut(400);
- }, 200);
- });
- };
-
-
- return {
- init: init
};
- }());
+
+ H5AI.context = {
+ init: init
+ };
}(jQuery, H5AI));
\ No newline at end of file
diff --git a/src/_h5ai/js/inc/Core.js b/src/_h5ai/js/inc/Core.js
index 60fd1001..e3a9ab7b 100644
--- a/src/_h5ai/js/inc/Core.js
+++ b/src/_h5ai/js/inc/Core.js
@@ -1,441 +1,438 @@
(function (window, $, H5AI, config) {
- H5AI.core = (function () {
-
- var $window = $(window),
- defaults = {
- store: {
- viewmode: "h5ai.pref.viewmode",
- lang: "h5ai.pref.lang"
- },
- callbacks: {
- pathClick: []
- },
-
- rootAbsHref: "/",
- h5aiAbsHref: "/_h5ai/",
- customHeader: null,
- customFooter: null,
- viewmodes: ["details", "icons"],
- sortorder: "na",
- showTree: true,
- slideTree: true,
- folderStatus: {},
- lang: "en",
- useBrowserLang: true,
- setParentFolderLabels: true,
- linkHoverStates: true,
- dateFormat: "yyyy-MM-dd HH:mm",
- showThumbs: false,
- thumbTypes: ["bmp", "gif", "ico", "image", "jpg", "png", "tiff"],
- zippedDownload: false,
- qrCodesSize: null,
- showFilter: false
+ var $window = $(window),
+ defaults = {
+ store: {
+ viewmode: "h5ai.pref.viewmode",
+ lang: "h5ai.pref.lang"
+ },
+ callbacks: {
+ pathClick: []
},
- settings = $.extend({}, defaults, config.options),
- currentDateFormat = settings.dateFormat,
- extToFileType = (function (types) {
- var map = {};
- $.each(types, function (type, exts) {
- $.each(exts, function (idx, ext) {
- map[ext] = type;
- });
- });
- return map;
- }(config.types)),
- hash = function (obj) {
- if ($.isPlainObject(obj)) {
- var hashStr = '';
- $.each($.extend({}, hash(), obj), function (key, value) {
- if (value) {
- hashStr += '/' + encodeURIComponent(key) + '=' + encodeURIComponent(value);
+ rootAbsHref: "/",
+ h5aiAbsHref: "/_h5ai/",
+ customHeader: null,
+ customFooter: null,
+ viewmodes: ["details", "icons"],
+ sortorder: "na",
+ showTree: true,
+ slideTree: true,
+ folderStatus: {},
+ lang: "en",
+ useBrowserLang: true,
+ setParentFolderLabels: true,
+ linkHoverStates: true,
+ dateFormat: "yyyy-MM-dd HH:mm",
+ showThumbs: false,
+ thumbTypes: ["bmp", "gif", "ico", "image", "jpg", "png", "tiff"],
+ zippedDownload: false,
+ qrCodesSize: null,
+ showFilter: false
+ },
+ settings = $.extend({}, defaults, config.options),
+ currentDateFormat = settings.dateFormat,
+ extToFileType = (function (types) {
+ var map = {};
+ $.each(types, function (type, exts) {
+ $.each(exts, function (idx, ext) {
+ map[ext] = type;
+ });
+ });
+ return map;
+ }(config.types)),
+ hash = function (obj) {
+
+ if ($.isPlainObject(obj)) {
+ var hashStr = '';
+ $.each($.extend({}, hash(), obj), function (key, value) {
+ if (value) {
+ hashStr += '/' + encodeURIComponent(key) + '=' + encodeURIComponent(value);
+ }
+ });
+ hashStr = '#!' + hashStr;
+ window.location.hash = hashStr;
+ return hashStr;
+ } else {
+ var result = {},
+ parts = document.location.hash.split('/');
+
+ if (parts.length >= 2 || parts[0] === '#!') {
+ parts.shift();
+ $.each(parts, function (idx, part) {
+
+ var match = /^([^=]*)=(.*?)$/.exec(part);
+ if (match) {
+ result[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
}
});
- hashStr = '#!' + hashStr;
- window.location.hash = hashStr;
- return hashStr;
- } else {
- var result = {},
- parts = document.location.hash.split('/');
-
- if (parts.length >= 2 || parts[0] === '#!') {
- parts.shift();
- $.each(parts, function (idx, part) {
-
- var match = /^([^=]*)=(.*?)$/.exec(part);
- if (match) {
- result[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
- }
- });
- }
- return typeof obj === 'string' ? result[obj] : result;
}
- },
- api = function () {
+ return typeof obj === 'string' ? result[obj] : result;
+ }
+ },
+ api = function () {
- return settings.h5aiAbsHref + "php/api.php";
- },
- image = function (id, noPngExt) {
+ return settings.h5aiAbsHref + "php/api.php";
+ },
+ image = function (id, noPngExt) {
- return settings.h5aiAbsHref + "images/" + id + (noPngExt ? "" : ".png");
- },
- icon = function (id, big) {
+ return settings.h5aiAbsHref + "images/" + id + (noPngExt ? "" : ".png");
+ },
+ icon = function (id, big) {
- return settings.h5aiAbsHref + "icons/" + (big ? "48x48" : "16x16") + "/" + id + ".png";
- },
- viewmode = function (viewmode) {
+ return settings.h5aiAbsHref + "icons/" + (big ? "48x48" : "16x16") + "/" + id + ".png";
+ },
+ viewmode = function (viewmode) {
- var $viewDetails = $("#viewdetails"),
- $viewIcons = $("#viewicons"),
- $extended = $("#extended");
+ var $viewDetails = $("#viewdetails"),
+ $viewIcons = $("#viewicons"),
+ $extended = $("#extended");
- if (viewmode) {
- amplify.store(settings.store.viewmode, viewmode);
- } else {
- viewmode = amplify.store(settings.store.viewmode);
- }
- viewmode = $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0];
- H5AI.core.hash({view: viewmode});
+ if (viewmode) {
+ amplify.store(settings.store.viewmode, viewmode);
+ } else {
+ viewmode = amplify.store(settings.store.viewmode);
+ }
+ viewmode = $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0];
+ H5AI.core.hash({view: viewmode});
- $viewDetails.add($viewIcons).removeClass("current");
- if (viewmode === "details") {
- $viewDetails.addClass("current");
- $extended.addClass("details-view").removeClass("icons-view").show();
- } else if (viewmode === "icons") {
- $viewIcons.addClass("current");
- $extended.removeClass("details-view").addClass("icons-view").show();
- } else {
- $extended.hide();
- }
- },
- initTopSpace = function () {
+ $viewDetails.add($viewIcons).removeClass("current");
+ if (viewmode === "details") {
+ $viewDetails.addClass("current");
+ $extended.addClass("details-view").removeClass("icons-view").show();
+ } else if (viewmode === "icons") {
+ $viewIcons.addClass("current");
+ $extended.removeClass("details-view").addClass("icons-view").show();
+ } else {
+ $extended.hide();
+ }
+ },
+ initTopSpace = function () {
- var $body = $("body"),
- $tree = $("#tree"),
- adjustTopSpace = function () {
+ var $body = $("body"),
+ $tree = $("#tree"),
+ adjustTopSpace = function () {
- var winHeight = $window.height(),
- navHeight = $("body > nav").outerHeight(),
- footerHeight = $("body > footer").outerHeight(),
- contentSpacing = 50,
- treeSpacing = 0;
+ var winHeight = $window.height(),
+ navHeight = $("body > nav").outerHeight(),
+ footerHeight = $("body > footer").outerHeight(),
+ contentSpacing = 50,
+ treeSpacing = 0;
- $body.css({
- "margin-top": navHeight + contentSpacing,
- "margin-bottom": footerHeight + contentSpacing
- });
+ $body.css({
+ "margin-top": navHeight + contentSpacing,
+ "margin-bottom": footerHeight + contentSpacing
+ });
- $tree.css({
- top: navHeight + treeSpacing,
- height: winHeight - navHeight - footerHeight - 16 - 2 * treeSpacing
- });
+ $tree.css({
+ top: navHeight + treeSpacing,
+ height: winHeight - navHeight - footerHeight - 16 - 2 * treeSpacing
+ });
- try {
- $tree.get(0).updateScrollbar();
- } catch (err) {}
- };
+ try {
+ $tree.get(0).updateScrollbar();
+ } catch (err) {}
+ };
- $window.resize(function () {
- adjustTopSpace();
- });
+ $window.resize(function () {
adjustTopSpace();
- },
- initViews = function () {
+ });
+ adjustTopSpace();
+ },
+ initViews = function () {
- var $navbar = $("#navbar"),
- $extended = $("#extended");
+ var $navbar = $("#navbar"),
+ $extended = $("#extended");
- $("#table").remove();
+ $("#table").remove();
- if (settings.viewmodes.length > 1) {
- if ($.inArray("icons", settings.viewmodes) >= 0) {
- $("
icons")
- .find("img").attr("src", image("view-icons")).end()
- .find("a").click(function (event) {
- viewmode("icons");
- event.preventDefault();
- }).end()
- .appendTo($navbar);
- }
- if ($.inArray("details", settings.viewmodes) >= 0) {
- $("
details")
- .find("img").attr("src", image("view-details")).end()
- .find("a").click(function (event) {
- viewmode("details");
- event.preventDefault();
- }).end()
- .appendTo($navbar);
- }
+ if (settings.viewmodes.length > 1) {
+ if ($.inArray("icons", settings.viewmodes) >= 0) {
+ $("
icons")
+ .find("img").attr("src", image("view-icons")).end()
+ .find("a").click(function (event) {
+ viewmode("icons");
+ event.preventDefault();
+ }).end()
+ .appendTo($navbar);
}
+ if ($.inArray("details", settings.viewmodes) >= 0) {
+ $("
details")
+ .find("img").attr("src", image("view-details")).end()
+ .find("a").click(function (event) {
+ viewmode("details");
+ event.preventDefault();
+ }).end()
+ .appendTo($navbar);
+ }
+ }
- // status update
- $extended.find(".entry a").hover(
- function () {
- if ($extended.hasClass("icons-view")) {
- var $this = $(this);
- $(".status.default").hide();
+ // status update
+ $extended.find(".entry a").hover(
+ function () {
+ if ($extended.hasClass("icons-view")) {
+ var $this = $(this);
+ $(".status.default").hide();
+ $(".status.dynamic")
+ .empty()
+ .append($this.find(".label").clone())
+ .append($("·"))
+ .append($this.find(".date").clone())
+ .show();
+
+ if (!$this.closest(".entry").hasClass("folder")) {
$(".status.dynamic")
- .empty()
- .append($this.find(".label").clone())
.append($("·"))
- .append($this.find(".date").clone())
- .show();
-
- if (!$this.closest(".entry").hasClass("folder")) {
- $(".status.dynamic")
- .append($("·"))
- .append($this.find(".size").clone());
- }
+ .append($this.find(".size").clone());
}
- },
- function () {
- $(".status.default").show();
- $(".status.dynamic").empty().hide();
}
- );
- },
- shiftTree = function (forceVisible, dontAnimate) {
+ },
+ function () {
+ $(".status.default").show();
+ $(".status.dynamic").empty().hide();
+ }
+ );
+ },
+ shiftTree = function (forceVisible, dontAnimate) {
- var $tree = $("#tree"),
- $extended = $("#extended");
+ var $tree = $("#tree"),
+ $extended = $("#extended");
- if ((settings.slideTree && $tree.outerWidth() < $extended.offset().left) || forceVisible) {
- if (dontAnimate) {
- $tree.stop().css({ left: 0 });
- } else {
- $tree.stop().animate({ left: 0 });
- }
+ if ((settings.slideTree && $tree.outerWidth() < $extended.offset().left) || forceVisible) {
+ if (dontAnimate) {
+ $tree.stop().css({ left: 0 });
} else {
- if (dontAnimate) {
- $tree.stop().css({ left: 18 - $tree.outerWidth() });
- } else {
- $tree.stop().animate({ left: 18 - $tree.outerWidth() });
- }
+ $tree.stop().animate({ left: 0 });
}
- },
- initTree = function () {
-
- $("#tree").hover(
- function () { shiftTree(true); },
- function () { shiftTree(); }
- );
- $window.resize(function () { shiftTree(); });
- shiftTree(false, true);
- },
- selectLinks = function (href) {
-
- var elements = [];
- $("a[href^='/']").each(function () {
-
- if ($(this).attr("href") === href) {
- elements.push(this);
- }
- });
- return $(elements);
- },
- linkHoverStates = function () {
-
- if (settings.linkHoverStates) {
- $("a[href^='/']:not(.linkedHoverStates)").each(function () {
-
- var $a = $(this).addClass("linkedHoverStates"),
- href = $a.attr("href");
-
- $a.hover(
- function () { selectLinks(href).addClass("hover"); },
- function () { selectLinks(href).removeClass("hover"); }
- );
- });
- }
- },
- formatDates = function (dateFormat) {
-
- if (dateFormat) {
- currentDateFormat = dateFormat;
- }
-
- $("#extended .entry .date").each(function () {
-
- var $this = $(this),
- time = $this.data("time"),
- formattedDate = time ? new Date(time).toString(currentDateFormat) : "";
-
- $this.text(formattedDate);
- });
- },
- localize = function (langs, lang, useBrowserLang) {
-
- var storedLang = amplify.store(settings.store.lang),
- browserLang, selected, key;
-
- if (langs[storedLang]) {
- lang = storedLang;
- } else if (useBrowserLang) {
- browserLang = navigator.language || navigator.browserLanguage;
- if (browserLang) {
- if (langs[browserLang]) {
- lang = browserLang;
- } else if (browserLang.length > 2 && langs[browserLang.substr(0, 2)]) {
- lang = browserLang.substr(0, 2);
- }
- }
- }
-
- if (!langs[lang]) {
- lang = "en";
- }
-
- selected = langs[lang];
- if (selected) {
- $.each(selected, function (key, value) {
- $(".l10n-" + key).text(value);
- });
- $(".lang").text(lang);
- $(".langOption").removeClass("current");
- $(".langOption." + lang).addClass("current");
- H5AI.core.hash({lang: lang});
- }
-
- formatDates(selected.dateFormat || settings.dateFormat);
- },
- initLangSelector = function (langs) {
-
- var $langOptions = $("#langSelector .langOptions"),
- sortedLangsKeys = [],
- $ul;
-
- $.each(langs, function (lang) {
- sortedLangsKeys.push(lang);
- });
- sortedLangsKeys.sort();
-
- $ul = $("");
- $.each(sortedLangsKeys, function (idx, lang) {
- $("")
- .addClass(lang)
- .text(lang + " - " + langs[lang].lang)
- .appendTo($ul)
- .click(function () {
- amplify.store(settings.store.lang, lang);
- localize(langs, lang, false);
- });
- });
- $langOptions
- .append($ul)
- .scrollpanel();
-
- $("#langSelector").hover(
- function () {
- $langOptions
- .css("top", "-" + $langOptions.outerHeight() + "px")
- .stop(true, true)
- .fadeIn();
- $langOptions.get(0).updateScrollbar();
- },
- function () {
- $langOptions
- .stop(true, true)
- .fadeOut();
- }
- );
- },
- onIndicatorClick = function (event) {
-
- var $indicator = $(this),
- $entry = $indicator.closest(".entry"),
- updateTreeScrollbar = $("#tree").get(0).updateScrollbar;
-
- if ($indicator.hasClass("unknown")) {
- $.get(api(), { "action": "tree", "href": $entry.find("> a").attr("href") }, function (html) {
-
- var $content = $(html);
-
- $indicator.removeClass("unknown");
- if ($content.find("> li").size() === 0) {
- $indicator.replaceWith($(""));
- } else {
- $indicator.addClass("open");
- $entry.find("> .content").replaceWith($content);
- updateTreeScrollbar();
- $content.find(".indicator:not(.initiated)")
- .click(onIndicatorClick)
- .addClass("initiated");
- }
- });
- } else if ($indicator.hasClass("open")) {
- $indicator.removeClass("open");
- updateTreeScrollbar(true);
- $entry.find("> .content").slideUp(function () {
- updateTreeScrollbar();
- });
+ } else {
+ if (dontAnimate) {
+ $tree.stop().css({ left: 18 - $tree.outerWidth() });
} else {
- $indicator.addClass("open");
- updateTreeScrollbar(true);
- $entry.find("> .content").slideDown(function () {
- updateTreeScrollbar();
- });
+ $tree.stop().animate({ left: 18 - $tree.outerWidth() });
}
- },
- initIndicators = function () {
+ }
+ },
+ initTree = function () {
- $("#tree .entry.folder .indicator:not(.initiated)")
- .click(onIndicatorClick)
- .addClass("initiated");
- },
- getFileType = function (filename) {
+ $("#tree").hover(
+ function () { shiftTree(true); },
+ function () { shiftTree(); }
+ );
+ $window.resize(function () { shiftTree(); });
+ shiftTree(false, true);
+ },
+ selectLinks = function (href) {
- var dotidx = filename.lastIndexOf('.'),
- ext = dotidx >= 0 ? filename.substr(dotidx) : filename;
+ var elements = [];
+ $("a[href^='/']").each(function () {
- return extToFileType[ext.toLowerCase()] || "unknown";
- },
- formatSizes = function () {
+ if ($(this).attr("href") === href) {
+ elements.push(this);
+ }
+ });
+ return $(elements);
+ },
+ linkHoverStates = function () {
- $("#extended .entry .size").each(function () {
+ if (settings.linkHoverStates) {
+ $("a[href^='/']:not(.linkedHoverStates)").each(function () {
- var $this = $(this),
- bytes = $this.data("bytes"),
- formattedSize = bytes >= 0 ? H5AI.util.formatSize(bytes) : "";
+ var $a = $(this).addClass("linkedHoverStates"),
+ href = $a.attr("href");
- $this.text(formattedSize);
+ $a.hover(
+ function () { selectLinks(href).addClass("hover"); },
+ function () { selectLinks(href).removeClass("hover"); }
+ );
});
- },
- setTotals = function () {
+ }
+ },
+ formatDates = function (dateFormat) {
- var $extended = $("#extended");
+ if (dateFormat) {
+ currentDateFormat = dateFormat;
+ }
- $(".folderTotal").text($extended.find(".entry.folder:not(.folder-parent)").length);
- $(".fileTotal").text($extended.find(".entry.file").length);
- },
- init = function () {
+ $("#extended .entry .date").each(function () {
- initViews();
- viewmode();
- initTopSpace();
- initTree();
- linkHoverStates();
- initLangSelector(config.langs);
- localize(config.langs, settings.lang, settings.useBrowserLang);
- formatSizes();
- setTotals();
- initIndicators();
- };
+ var $this = $(this),
+ time = $this.data("time"),
+ formattedDate = time ? new Date(time).toString(currentDateFormat) : "";
- return {
- settings: settings,
- hash: hash,
- api: api,
- image: image,
- icon: icon,
- shiftTree: shiftTree,
- linkHoverStates: linkHoverStates,
- initIndicators: initIndicators,
- formatDates: formatDates,
- getFileType: getFileType,
- init: init
+ $this.text(formattedDate);
+ });
+ },
+ localize = function (langs, lang, useBrowserLang) {
+
+ var storedLang = amplify.store(settings.store.lang),
+ browserLang, selected, key;
+
+ if (langs[storedLang]) {
+ lang = storedLang;
+ } else if (useBrowserLang) {
+ browserLang = navigator.language || navigator.browserLanguage;
+ if (browserLang) {
+ if (langs[browserLang]) {
+ lang = browserLang;
+ } else if (browserLang.length > 2 && langs[browserLang.substr(0, 2)]) {
+ lang = browserLang.substr(0, 2);
+ }
+ }
+ }
+
+ if (!langs[lang]) {
+ lang = "en";
+ }
+
+ selected = langs[lang];
+ if (selected) {
+ $.each(selected, function (key, value) {
+ $(".l10n-" + key).text(value);
+ });
+ $(".lang").text(lang);
+ $(".langOption").removeClass("current");
+ $(".langOption." + lang).addClass("current");
+ H5AI.core.hash({lang: lang});
+ }
+
+ formatDates(selected.dateFormat || settings.dateFormat);
+ },
+ initLangSelector = function (langs) {
+
+ var $langOptions = $("#langSelector .langOptions"),
+ sortedLangsKeys = [],
+ $ul;
+
+ $.each(langs, function (lang) {
+ sortedLangsKeys.push(lang);
+ });
+ sortedLangsKeys.sort();
+
+ $ul = $("");
+ $.each(sortedLangsKeys, function (idx, lang) {
+ $("")
+ .addClass(lang)
+ .text(lang + " - " + langs[lang].lang)
+ .appendTo($ul)
+ .click(function () {
+ amplify.store(settings.store.lang, lang);
+ localize(langs, lang, false);
+ });
+ });
+ $langOptions
+ .append($ul)
+ .scrollpanel();
+
+ $("#langSelector").hover(
+ function () {
+ $langOptions
+ .css("top", "-" + $langOptions.outerHeight() + "px")
+ .stop(true, true)
+ .fadeIn();
+ $langOptions.get(0).updateScrollbar();
+ },
+ function () {
+ $langOptions
+ .stop(true, true)
+ .fadeOut();
+ }
+ );
+ },
+ onIndicatorClick = function (event) {
+
+ var $indicator = $(this),
+ $entry = $indicator.closest(".entry"),
+ updateTreeScrollbar = $("#tree").get(0).updateScrollbar;
+
+ if ($indicator.hasClass("unknown")) {
+ $.get(api(), { "action": "tree", "href": $entry.find("> a").attr("href") }, function (html) {
+
+ var $content = $(html);
+
+ $indicator.removeClass("unknown");
+ if ($content.find("> li").size() === 0) {
+ $indicator.replaceWith($(""));
+ } else {
+ $indicator.addClass("open");
+ $entry.find("> .content").replaceWith($content);
+ updateTreeScrollbar();
+ $content.find(".indicator:not(.initiated)")
+ .click(onIndicatorClick)
+ .addClass("initiated");
+ }
+ });
+ } else if ($indicator.hasClass("open")) {
+ $indicator.removeClass("open");
+ updateTreeScrollbar(true);
+ $entry.find("> .content").slideUp(function () {
+ updateTreeScrollbar();
+ });
+ } else {
+ $indicator.addClass("open");
+ updateTreeScrollbar(true);
+ $entry.find("> .content").slideDown(function () {
+ updateTreeScrollbar();
+ });
+ }
+ },
+ initIndicators = function () {
+
+ $("#tree .entry.folder .indicator:not(.initiated)")
+ .click(onIndicatorClick)
+ .addClass("initiated");
+ },
+ getFileType = function (filename) {
+
+ var dotidx = filename.lastIndexOf('.'),
+ ext = dotidx >= 0 ? filename.substr(dotidx) : filename;
+
+ return extToFileType[ext.toLowerCase()] || "unknown";
+ },
+ formatSizes = function () {
+
+ $("#extended .entry .size").each(function () {
+
+ var $this = $(this),
+ bytes = $this.data("bytes"),
+ formattedSize = bytes >= 0 ? H5AI.util.formatSize(bytes) : "";
+
+ $this.text(formattedSize);
+ });
+ },
+ setTotals = function () {
+
+ var $extended = $("#extended");
+
+ $(".folderTotal").text($extended.find(".entry.folder:not(.folder-parent)").length);
+ $(".fileTotal").text($extended.find(".entry.file").length);
+ },
+ init = function () {
+
+ initViews();
+ viewmode();
+ initTopSpace();
+ initTree();
+ linkHoverStates();
+ initLangSelector(config.langs);
+ localize(config.langs, settings.lang, settings.useBrowserLang);
+ formatSizes();
+ setTotals();
+ initIndicators();
};
- }());
+
+ H5AI.core = {
+ settings: settings,
+ hash: hash,
+ api: api,
+ image: image,
+ icon: icon,
+ shiftTree: shiftTree,
+ linkHoverStates: linkHoverStates,
+ initIndicators: initIndicators,
+ formatDates: formatDates,
+ getFileType: getFileType,
+ init: init
+ };
}(window, jQuery, H5AI, H5AI_CONFIG));
diff --git a/src/_h5ai/js/inc/Extended.js b/src/_h5ai/js/inc/Extended.js
index 93fb62c0..9fb3a9df 100644
--- a/src/_h5ai/js/inc/Extended.js
+++ b/src/_h5ai/js/inc/Extended.js
@@ -1,132 +1,129 @@
(function (document, $, H5AI) {
- H5AI.extended = (function () {
+ var initBreadcrumb = function () {
- var initBreadcrumb = function () {
+ var $ul = $("body > nav ul"),
+ pathname = "/",
+ path = H5AI.connector.getPath(pathname),
+ pathnameParts = document.location.pathname.split("/"),
+ lastPart = "",
+ title = document.domain;
- var $ul = $("body > nav ul"),
- pathname = "/",
- path = H5AI.connector.getPath(pathname),
- pathnameParts = document.location.pathname.split("/"),
- lastPart = "",
- title = document.domain;
+ $ul.append(H5AI.html.updateCrumbHtml(path));
- $ul.append(H5AI.html.updateCrumbHtml(path));
+ $.each(pathnameParts, function (idx, part) {
+ if (part !== "") {
+ pathname += part + "/";
+ $ul.append(H5AI.html.updateCrumbHtml(H5AI.connector.getPath(pathname)));
+ lastPart = part + " - ";
+ title += " > " + part;
+ }
+ });
- $.each(pathnameParts, function (idx, part) {
- if (part !== "") {
- pathname += part + "/";
- $ul.append(H5AI.html.updateCrumbHtml(H5AI.connector.getPath(pathname)));
- lastPart = part + " - ";
- title += " > " + part;
+ document.title = H5AI.util.checkedDecodeUri(lastPart + title);
+ },
+ initExtendedView = function () {
+
+ var $ul, $li;
+
+ $ul = $("");
+ $li = $("")
+ .appendTo($ul)
+ .append($(""))
+ .append($(""))
+ .append($(""))
+ .append($(""));
+
+ // entries
+ $("#table td").closest("tr").each(function () {
+ var path = H5AI.connector.getPath(document.location.pathname, this);
+ $ul.append(H5AI.html.updateExtendedHtml(path));
+ });
+
+ $("#extended").append($ul);
+
+ // empty
+ if ($ul.children(".entry:not(.folder-parent)").size() === 0) {
+ $("#extended").append($("empty
"));
+ }
+ $("#extended").append($("no match
"));
+ },
+ customize = function () {
+
+ if (H5AI.core.settings.customHeader) {
+ $.ajax({
+ url: H5AI.core.settings.customHeader,
+ dataType: "html",
+ success: function (data) {
+ $("#content > header").append($(data)).show();
}
});
+ }
- document.title = H5AI.util.checkedDecodeUri(lastPart + title);
- },
- initExtendedView = function () {
-
- var $ul, $li;
-
- $ul = $("");
- $li = $("")
- .appendTo($ul)
- .append($(""))
- .append($(""))
- .append($(""))
- .append($(""));
-
- // entries
- $("#table td").closest("tr").each(function () {
- var path = H5AI.connector.getPath(document.location.pathname, this);
- $ul.append(H5AI.html.updateExtendedHtml(path));
+ if (H5AI.core.settings.customFooter) {
+ $.ajax({
+ url: H5AI.core.settings.customFooter,
+ dataType: "html",
+ success: function (data) {
+ $("#content > footer").prepend($(data)).show();
+ }
});
+ }
+ },
+ fetchPath = function (pathname, callback) {
- $("#extended").append($ul);
+ H5AI.connector.fetchStatusAndContent(pathname, false, function (status, content) {
- // empty
- if ($ul.children(".entry:not(.folder-parent)").size() === 0) {
- $("#extended").append($("empty
"));
+ var path = H5AI.connector.getPath(pathname);
+
+ path.status = status;
+ path.content = content;
+ callback(path);
+ });
+ },
+ fetchTree = function (pathname, callback, childPath) {
+
+ fetchPath(pathname, function (path) {
+
+ var parent = H5AI.util.splitPath(pathname).parent;
+
+ path.treeOpen = true;
+ if (childPath) {
+ path.content[childPath.absHref] = childPath;
}
- $("#extended").append($("no match
"));
- },
- customize = function () {
-
- if (H5AI.core.settings.customHeader) {
- $.ajax({
- url: H5AI.core.settings.customHeader,
- dataType: "html",
- success: function (data) {
- $("#content > header").append($(data)).show();
- }
- });
- }
-
- if (H5AI.core.settings.customFooter) {
- $.ajax({
- url: H5AI.core.settings.customFooter,
- dataType: "html",
- success: function (data) {
- $("#content > footer").prepend($(data)).show();
- }
- });
- }
- },
- fetchPath = function (pathname, callback) {
-
- H5AI.connector.fetchStatusAndContent(pathname, false, function (status, content) {
-
- var path = H5AI.connector.getPath(pathname);
-
- path.status = status;
- path.content = content;
+ if (parent === null) {
callback(path);
- });
- },
- fetchTree = function (pathname, callback, childPath) {
-
- fetchPath(pathname, function (path) {
-
- var parent = H5AI.util.splitPath(pathname).parent;
-
- path.treeOpen = true;
- if (childPath) {
- path.content[childPath.absHref] = childPath;
- }
- if (parent === null) {
- callback(path);
- } else {
- fetchTree(parent, callback, path);
- }
- });
- },
- populateTree = function () {
-
- fetchTree(document.location.pathname, function (path) {
- $("#tree")
- .append(H5AI.html.updateTreeHtml(path))
- .scrollpanel()
- .show();
- H5AI.core.shiftTree(false, true);
- H5AI.core.linkHoverStates();
- setTimeout(function () { $("#tree").get(0).updateScrollbar(); }, 1);
- });
- },
- init = function () {
-
- initBreadcrumb();
- initExtendedView();
- customize();
- H5AI.connector.updatePaths();
- if (H5AI.core.settings.showTree) {
- populateTree();
+ } else {
+ fetchTree(parent, callback, path);
}
- };
+ });
+ },
+ populateTree = function () {
- return {
- init: init
+ fetchTree(document.location.pathname, function (path) {
+ $("#tree")
+ .append(H5AI.html.updateTreeHtml(path))
+ .scrollpanel()
+ .show();
+ H5AI.core.shiftTree(false, true);
+ H5AI.core.linkHoverStates();
+ setTimeout(function () { $("#tree").get(0).updateScrollbar(); }, 1);
+ });
+ },
+ init = function () {
+
+ initBreadcrumb();
+ initExtendedView();
+ customize();
+ H5AI.connector.updatePaths();
+ if (H5AI.core.settings.showTree) {
+ populateTree();
+ }
};
- }());
+
+ H5AI.extended = {
+ init: init
+ };
}(document, jQuery, H5AI));
diff --git a/src/_h5ai/js/inc/Finder.js b/src/_h5ai/js/inc/Finder.js
index 060fc2e6..ceb059f9 100644
--- a/src/_h5ai/js/inc/Finder.js
+++ b/src/_h5ai/js/inc/Finder.js
@@ -1,111 +1,107 @@
(function ($, H5AI) {
- H5AI.finder = (function () {
+ var filter = function (re) {
- var filter = function (re) {
+ var match = [],
+ noMatch = [];
- var match = [],
- noMatch = [];
+ if (re) {
+ $('#extended .entry').each(function () {
- if (re) {
- $('#extended .entry').each(function () {
+ var label = $(this).find('.label').text();
- var label = $(this).find('.label').text();
-
- if (label.match(re)) {
- match.push(this);
- } else {
- noMatch.push(this);
- }
- });
- } else {
- match = $('#extended .entry');
- }
-
- if ($(match).length) {
- $('#extended .no-match').hide();
- } else {
- setTimeout(function () {
-
- $('#extended .no-match').show();
- }, 200);
- }
- $(match).fadeIn(200);
- $(noMatch).fadeOut(200);
- },
- checkState = function (focus) {
-
- var $filter = $('#filter'),
- $input = $filter.find('input'),
- val = $input.val();
-
- if (val || focus) {
- $filter.addClass('current');
- } else {
- $filter.removeClass('current');
- }
- H5AI.core.hash({filter: val});
- },
- parseFilterSequence = function (sequence) {
-
- if (sequence.substr(0,3) === 're:') {
- return new RegExp(sequence.substr(3));
- }
-
- sequence = $.map($.trim(sequence).split(/\s+/), function (part) {
-
- return H5AI.util.reEscape(part);
- }).join('|');
- return new RegExp(sequence);
- },
- init = function () {
-
- if (H5AI.core.settings.showFilter) {
- $("
")
- .on('click', function () {
-
- var $input = $(this).find('input');
- $input.focus();
- })
- .find("img").attr("src", H5AI.core.image("filter")).end()
- .find("input")
- .on('focus', function () {
-
- checkState(true);
- })
- .on('blur', function () {
-
- checkState(false);
- })
- .on('keyup', function () {
-
- var $input = $(this),
- val = $input.val();
-
- if (val) {
- filter(parseFilterSequence(val));
- } else {
- filter();
- }
- checkState($input.is(':focus'));
- })
- .end()
- .appendTo($("#navbar"));
-
- var initialFilter = H5AI.core.hash('filter');
- if (initialFilter) {
- $('#filter input').val(initialFilter);
- checkState(false);
+ if (label.match(re)) {
+ match.push(this);
+ } else {
+ noMatch.push(this);
}
+ });
+ } else {
+ match = $('#extended .entry');
+ }
+
+ if ($(match).length) {
+ $('#extended .no-match').hide();
+ } else {
+ setTimeout(function () {
+
+ $('#extended .no-match').show();
+ }, 200);
+ }
+ $(match).fadeIn(200);
+ $(noMatch).fadeOut(200);
+ },
+ checkState = function (focus) {
+
+ var $filter = $('#filter'),
+ $input = $filter.find('input'),
+ val = $input.val();
+
+ if (val || focus) {
+ $filter.addClass('current');
+ } else {
+ $filter.removeClass('current');
+ }
+ H5AI.core.hash({filter: val});
+ },
+ parseFilterSequence = function (sequence) {
+
+ if (sequence.substr(0,3) === 're:') {
+ return new RegExp(sequence.substr(3));
+ }
+
+ sequence = $.map($.trim(sequence).split(/\s+/), function (part) {
+
+ return H5AI.util.reEscape(part);
+ }).join('|');
+ return new RegExp(sequence);
+ },
+ init = function () {
+
+ if (H5AI.core.settings.showFilter) {
+ $("
")
+ .on('click', function () {
+
+ var $input = $(this).find('input');
+ $input.focus();
+ })
+ .find("img").attr("src", H5AI.core.image("filter")).end()
+ .find("input")
+ .on('focus', function () {
+
+ checkState(true);
+ })
+ .on('blur', function () {
+
+ checkState(false);
+ })
+ .on('keyup', function () {
+
+ var $input = $(this),
+ val = $input.val();
+
+ if (val) {
+ filter(parseFilterSequence(val));
+ } else {
+ filter();
+ }
+ checkState($input.is(':focus'));
+ })
+ .end()
+ .appendTo($("#navbar"));
+
+ var initialFilter = H5AI.core.hash('filter');
+ if (initialFilter) {
+ $('#filter input').val(initialFilter);
+ checkState(false);
}
- };
-
-
- return {
- init: init,
- filter: filter
+ }
};
- }());
+
+ H5AI.finder = {
+ init: init,
+ filter: filter
+ };
}(jQuery, H5AI));
\ No newline at end of file
diff --git a/src/_h5ai/js/inc/Html.js b/src/_h5ai/js/inc/Html.js
index 12bd1b6d..64e7ce9e 100644
--- a/src/_h5ai/js/inc/Html.js
+++ b/src/_h5ai/js/inc/Html.js
@@ -1,264 +1,261 @@
(function ($, H5AI) {
- H5AI.html = (function () {
+ var onClick = function (path, context) {
- var onClick = function (path, context) {
+ },
+ updateCrumbHtml = function (path) {
- },
- updateCrumbHtml = function (path) {
+ var $html, $a;
- var $html, $a;
+ if (path.html.$crumb && path.html.$crumb.data("status") === path.status) {
+ return path.html.$crumb;
+ }
- if (path.html.$crumb && path.html.$crumb.data("status") === path.status) {
- return path.html.$crumb;
+ $html = $("
")
+ .addClass(path.isFolder ? "folder" : "file");
+
+ if (path.status) {
+ $html.data("status", path.status);
+ }
+
+ $a = $html.find("a")
+ .attr("href", path.absHref)
+ .click(function() { onClick(path, "crumb"); })
+ .find("img").attr("src", H5AI.core.image("crumb")).end()
+ .find("span").text(path.label).end();
+
+ if (path.isDomain) {
+ $html.addClass("domain");
+ $a.find("img").attr("src", H5AI.core.image("home"));
+ }
+
+ if (path.isCurrentFolder) {
+ $html.addClass("current");
+ }
+
+ if (!isNaN(path.status)) {
+ if (path.status === 200) {
+ $a.append($("
"));
+ } else {
+ $a.append($("(" + path.status + ")"));
+ }
+ }
+
+ if (path.html.$crumb) {
+ path.html.$crumb.replaceWith($html);
+ }
+ path.html.$crumb = $html;
+
+ return $html;
+ },
+ updateExtendedHtml = function (path) {
+
+ var $html, $a, $label,
+ formattedDate = path.date ? path.date.toString(H5AI.core.settings.dateFormat) : "",
+ imgClass = "",
+ icon16 = H5AI.core.icon(path.type),
+ icon48 = H5AI.core.icon(path.type, true);
+
+ if (path.html.$extended && path.html.$extended.data("status") === path.status) {
+ return path.html.$extended;
+ }
+
+ $html = $("")
+ .data("path", path)
+ .addClass(path.isFolder ? "folder" : "file");
+
+ if (path.status) {
+ $html.data("status", path.status);
+ }
+
+ if (H5AI.core.settings.showThumbs === true && $.inArray(path.type, H5AI.core.settings.thumbTypes) >= 0) {
+ imgClass = "class='thumb'";
+ var escapedHref = path.absHref.replace(/'/g, "%27").replace(/"/g, "%22");
+ icon16 = H5AI.core.api() + "?action=thumb&href=" + escapedHref + "&width=16&height=16&mode=square";
+ icon48 = H5AI.core.api() + "?action=thumb&href=" + escapedHref + "&width=96&height=46&mode=rational";
+ }
+
+ $label = $("" + path.label + "");
+ $a = $("")
+ .attr("href", path.absHref)
+ .click(function() { onClick(path, "extended"); })
+ .appendTo($html)
+ .append($("
"))
+ .append($("
"))
+ .append($label)
+ .append($(""))
+ .append($(""));
+
+ $a.hover(
+ function () {
+ if ($("#extended").hasClass("icons-view")) {
+ var $this = $(this);
+ $(".status.default").hide();
+ $(".status.dynamic")
+ .empty()
+ .append($this.find(".label").clone())
+ .append($("·"))
+ .append($this.find(".date").clone())
+ .show();
+
+ if (!$this.closest(".entry").hasClass("folder")) {
+ $(".status.dynamic")
+ .append($("·"))
+ .append($this.find(".size").clone());
+ }
+ }
+ },
+ function () {
+ $(".status.default").show();
+ $(".status.dynamic").empty().hide();
+ }
+ );
+
+ if (path.isParentFolder) {
+ if (!H5AI.core.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.core.icon("folder-page"));
+ $a.find(".icon.big img").attr("src", H5AI.core.icon("folder-page", true));
+ } else {
+ $html.addClass("error");
+ $label.append($(" " + path.status + " "));
+ }
+ }
+
+ if (path.html.$extended) {
+ path.html.$extended.replaceWith($html);
+ H5AI.core.formatDates();
+ }
+ path.html.$extended = $html;
+
+ return $html;
+ },
+ updateTreeHtml = function (path) {
+
+ var $html, $blank, $a, $indicator, $ul, idx;
+
+ $html = $("")
+ .data("path", path)
+ .addClass(path.isFolder ? "folder" : "file");
+
+ $blank = $("").appendTo($html);
+
+ $a = $("")
+ .attr("href", path.absHref)
+ .click(function() { onClick(path, "tree"); })
+ .appendTo($html)
+ .append($("
"))
+ .append($("" + path.label + ""));
+
+ if (path.isFolder) {
+ // indicator
+ if (path.status === undefined || !path.isEmpty()) {
+ $indicator = $("
")
+ .click(function (event) {
+
+ var $entry = $indicator.closest(".entry"); // $html
+
+ if ($indicator.hasClass("unknown")) {
+ H5AI.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);
}
- $html = $("
")
- .addClass(path.isFolder ? "folder" : "file");
-
- if (path.status) {
- $html.data("status", path.status);
- }
-
- $a = $html.find("a")
- .attr("href", path.absHref)
- .click(function() { onClick(path, "crumb"); })
- .find("img").attr("src", H5AI.core.image("crumb")).end()
- .find("span").text(path.label).end();
-
+ // is path the domain?
if (path.isDomain) {
$html.addClass("domain");
- $a.find("img").attr("src", H5AI.core.image("home"));
+ $a.find(".icon img").attr("src", H5AI.core.icon("folder-home"));
}
+ // is path the current folder?
if (path.isCurrentFolder) {
$html.addClass("current");
+ $a.find(".icon img").attr("src", H5AI.core.icon("folder-open"));
}
+ // does it have subfolders?
+ if (!path.isEmpty()) {
+ $ul = $("").appendTo($html);
+ $.each(path.content, function (idx, entry) {
+ $("").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.append($("
"));
- } else {
- $a.append($("(" + path.status + ")"));
- }
- }
-
- if (path.html.$crumb) {
- path.html.$crumb.replaceWith($html);
- }
- path.html.$crumb = $html;
-
- return $html;
- },
- updateExtendedHtml = function (path) {
-
- var $html, $a, $label,
- formattedDate = path.date ? path.date.toString(H5AI.core.settings.dateFormat) : "",
- imgClass = "",
- icon16 = H5AI.core.icon(path.type),
- icon48 = H5AI.core.icon(path.type, true);
-
- if (path.html.$extended && path.html.$extended.data("status") === path.status) {
- return path.html.$extended;
- }
-
- $html = $("")
- .data("path", path)
- .addClass(path.isFolder ? "folder" : "file");
-
- if (path.status) {
- $html.data("status", path.status);
- }
-
- if (H5AI.core.settings.showThumbs === true && $.inArray(path.type, H5AI.core.settings.thumbTypes) >= 0) {
- imgClass = "class='thumb'";
- var escapedHref = path.absHref.replace(/'/g, "%27").replace(/"/g, "%22");
- icon16 = H5AI.core.api() + "?action=thumb&href=" + escapedHref + "&width=16&height=16&mode=square";
- icon48 = H5AI.core.api() + "?action=thumb&href=" + escapedHref + "&width=96&height=46&mode=rational";
- }
-
- $label = $("" + path.label + "");
- $a = $("")
- .attr("href", path.absHref)
- .click(function() { onClick(path, "extended"); })
- .appendTo($html)
- .append($("
"))
- .append($("
"))
- .append($label)
- .append($(""))
- .append($(""));
-
- $a.hover(
- function () {
- if ($("#extended").hasClass("icons-view")) {
- var $this = $(this);
- $(".status.default").hide();
- $(".status.dynamic")
- .empty()
- .append($this.find(".label").clone())
- .append($("·"))
- .append($this.find(".date").clone())
- .show();
-
- if (!$this.closest(".entry").hasClass("folder")) {
- $(".status.dynamic")
- .append($("·"))
- .append($this.find(".size").clone());
- }
- }
- },
- function () {
- $(".status.default").show();
- $(".status.dynamic").empty().hide();
- }
- );
-
- if (path.isParentFolder) {
- if (!H5AI.core.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.core.icon("folder-page"));
- $a.find(".icon.big img").attr("src", H5AI.core.icon("folder-page", true));
+ $a.find(".icon img").attr("src", H5AI.core.icon("folder-page"));
+ $a.append($("
"));
} else {
$html.addClass("error");
- $label.append($(" " + path.status + " "));
+ $a.append($("" + path.status + ""));
}
}
+ }
- if (path.html.$extended) {
- path.html.$extended.replaceWith($html);
- H5AI.core.formatDates();
- }
- path.html.$extended = $html;
+ if (path.html.$tree) {
+ path.html.$tree.replaceWith($html);
+ }
+ path.html.$tree = $html;
- return $html;
- },
- updateTreeHtml = function (path) {
+ return $html;
+ },
+ updateHtml = function (path) {
- var $html, $blank, $a, $indicator, $ul, idx;
-
- $html = $("")
- .data("path", path)
- .addClass(path.isFolder ? "folder" : "file");
-
- $blank = $("").appendTo($html);
-
- $a = $("")
- .attr("href", path.absHref)
- .click(function() { onClick(path, "tree"); })
- .appendTo($html)
- .append($("
"))
- .append($("" + path.label + ""));
-
- if (path.isFolder) {
- // indicator
- if (path.status === undefined || !path.isEmpty()) {
- $indicator = $("
")
- .click(function (event) {
-
- var $entry = $indicator.closest(".entry"); // $html
-
- if ($indicator.hasClass("unknown")) {
- H5AI.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", H5AI.core.icon("folder-home"));
- }
-
- // is path the current folder?
- if (path.isCurrentFolder) {
- $html.addClass("current");
- $a.find(".icon img").attr("src", H5AI.core.icon("folder-open"));
- }
-
- // does it have subfolders?
- if (!path.isEmpty()) {
- $ul = $("").appendTo($html);
- $.each(path.content, function (idx, entry) {
- $("").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", H5AI.core.icon("folder-page"));
- $a.append($("
"));
- } else {
- $html.addClass("error");
- $a.append($("" + path.status + ""));
- }
- }
- }
-
- 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
+ updateCrumbHtml(path);
+ updateExtendedHtml(path);
+ updateTreeHtml(path);
};
- }());
+
+ H5AI.html = {
+ updateCrumbHtml: updateCrumbHtml,
+ updateExtendedHtml: updateExtendedHtml,
+ updateTreeHtml: updateTreeHtml,
+ updateHtml: updateHtml
+ };
}(jQuery, H5AI));
diff --git a/src/_h5ai/js/inc/Sort.js b/src/_h5ai/js/inc/Sort.js
index 074ccf0b..9e663966 100644
--- a/src/_h5ai/js/inc/Sort.js
+++ b/src/_h5ai/js/inc/Sort.js
@@ -1,158 +1,155 @@
(function ($, H5AI) {
- H5AI.sort = (function () {
+ var type = function (entry) {
- var type = function (entry) {
+ var $entry = $(entry);
- var $entry = $(entry);
-
- if ($entry.hasClass("folder-parent")) {
- return 0;
- } else if ($entry.hasClass("folder")) {
- return 1;
- }
- return 2;
- },
- cmp = function (entry1, entry2, rev, getVal) {
-
- var res, val1, val2;
-
- res = type(entry1) - type(entry2);
- if (res !== 0) {
- return res;
- }
-
- val1 = getVal(entry1);
- val2 = getVal(entry2);
- if (val1 < val2) {
- return rev ? 1 : -1;
- } else if (val1 > val2) {
- return rev ? -1 : 1;
- }
+ if ($entry.hasClass("folder-parent")) {
return 0;
- },
- cmpName = function (entry1, entry2) {
+ } else if ($entry.hasClass("folder")) {
+ return 1;
+ }
+ return 2;
+ },
+ cmp = function (entry1, entry2, rev, getVal) {
- return cmp(entry1, entry2, false, function (entry) {
- return $(entry).find(".label").text().toLowerCase();
- });
- },
- cmpTime = function (entry1, entry2) {
+ var res, val1, val2;
- return cmp(entry1, entry2, false, function (entry) {
- return $(entry).find(".date").data("time");
- });
- },
- cmpSize = function (entry1, entry2) {
+ res = type(entry1) - type(entry2);
+ if (res !== 0) {
+ return res;
+ }
- return cmp(entry1, entry2, false, function (entry) {
- return $(entry).find(".size").data("bytes");
- });
- },
- cmpNameRev = function (entry1, entry2) {
+ val1 = getVal(entry1);
+ val2 = getVal(entry2);
+ if (val1 < val2) {
+ return rev ? 1 : -1;
+ } else if (val1 > val2) {
+ return rev ? -1 : 1;
+ }
+ return 0;
+ },
+ cmpName = function (entry1, entry2) {
- return cmp(entry1, entry2, true, function (entry) {
- return $(entry).find(".label").text().toLowerCase();
- });
- },
- cmpTimeRev = function (entry1, entry2) {
+ return cmp(entry1, entry2, false, function (entry) {
+ return $(entry).find(".label").text().toLowerCase();
+ });
+ },
+ cmpTime = function (entry1, entry2) {
- return cmp(entry1, entry2, true, function (entry) {
- return $(entry).find(".date").data("time");
- });
- },
- cmpSizeRev = function (entry1, entry2) {
+ return cmp(entry1, entry2, false, function (entry) {
+ return $(entry).find(".date").data("time");
+ });
+ },
+ cmpSize = function (entry1, entry2) {
- return cmp(entry1, entry2, true, function (entry) {
- return $(entry).find(".size").data("bytes");
- });
- },
- sort = function (fn) {
+ return cmp(entry1, entry2, false, function (entry) {
+ return $(entry).find(".size").data("bytes");
+ });
+ },
+ cmpNameRev = function (entry1, entry2) {
- $("#extended .entry").detach().sort(fn).appendTo($("#extended > ul"));
- },
- $all, orders,
- sortBy = function (id) {
+ return cmp(entry1, entry2, true, function (entry) {
+ return $(entry).find(".label").text().toLowerCase();
+ });
+ },
+ cmpTimeRev = function (entry1, entry2) {
- var order = orders[id];
+ return cmp(entry1, entry2, true, function (entry) {
+ return $(entry).find(".date").data("time");
+ });
+ },
+ cmpSizeRev = function (entry1, entry2) {
- $all.removeClass("ascending").removeClass("descending");
- order.head.addClass(order.clas);
- sort(order.fn);
- H5AI.core.hash({sort: id});
- },
- init = function () {
+ return cmp(entry1, entry2, true, function (entry) {
+ return $(entry).find(".size").data("bytes");
+ });
+ },
+ sort = function (fn) {
- var $ascending = $("
"),
- $descending = $("
"),
- initialOrder = H5AI.core.hash('sort'),
- $header = $("#extended li.header"),
- $label = $header.find("a.label"),
- $date = $header.find("a.date"),
- $size = $header.find("a.size");
+ $("#extended .entry").detach().sort(fn).appendTo($("#extended > ul"));
+ },
+ $all, orders,
+ sortBy = function (id) {
- $all = $header.find("a.label,a.date,a.size");
- orders = {
- na: {
- head: $label,
- clas: "ascending",
- fn: cmpName
- },
- nd: {
- head: $label,
- clas: "descending",
- fn: cmpNameRev
- },
- da: {
- head: $date,
- clas: "ascending",
- fn: cmpTime
- },
- dd: {
- head: $date,
- clas: "descending",
- fn: cmpTimeRev
- },
- sa: {
- head: $size,
- clas: "ascending",
- fn: cmpSize
- },
- sd: {
- head: $size,
- clas: "descending",
- fn: cmpSizeRev
- }
- };
+ var order = orders[id];
- sortBy(initialOrder ? initialOrder : H5AI.core.settings.sortorder);
+ $all.removeClass("ascending").removeClass("descending");
+ order.head.addClass(order.clas);
+ sort(order.fn);
+ H5AI.core.hash({sort: id});
+ },
+ init = function () {
- $label
- .append($ascending.clone()).append($descending.clone())
- .click(function (event) {
- sortBy("n" + ($label.hasClass("ascending") ? "d" : "a"));
- event.preventDefault();
- });
+ var $ascending = $("
"),
+ $descending = $("
"),
+ initialOrder = H5AI.core.hash('sort'),
+ $header = $("#extended li.header"),
+ $label = $header.find("a.label"),
+ $date = $header.find("a.date"),
+ $size = $header.find("a.size");
- $date
- .prepend($ascending.clone()).prepend($descending.clone())
- .click(function (event) {
- sortBy("d" + ($date.hasClass("ascending") ? "d" : "a"));
- event.preventDefault();
- });
-
- $size
- .prepend($ascending.clone()).prepend($descending.clone())
- .click(function (event) {
- sortBy("s" + ($size.hasClass("ascending") ? "d" : "a"));
- event.preventDefault();
- });
+ $all = $header.find("a.label,a.date,a.size");
+ orders = {
+ na: {
+ head: $label,
+ clas: "ascending",
+ fn: cmpName
+ },
+ nd: {
+ head: $label,
+ clas: "descending",
+ fn: cmpNameRev
+ },
+ da: {
+ head: $date,
+ clas: "ascending",
+ fn: cmpTime
+ },
+ dd: {
+ head: $date,
+ clas: "descending",
+ fn: cmpTimeRev
+ },
+ sa: {
+ head: $size,
+ clas: "ascending",
+ fn: cmpSize
+ },
+ sd: {
+ head: $size,
+ clas: "descending",
+ fn: cmpSizeRev
+ }
};
- return {
- init: init
+ sortBy(initialOrder ? initialOrder : H5AI.core.settings.sortorder);
+
+ $label
+ .append($ascending.clone()).append($descending.clone())
+ .click(function (event) {
+ sortBy("n" + ($label.hasClass("ascending") ? "d" : "a"));
+ event.preventDefault();
+ });
+
+ $date
+ .prepend($ascending.clone()).prepend($descending.clone())
+ .click(function (event) {
+ sortBy("d" + ($date.hasClass("ascending") ? "d" : "a"));
+ event.preventDefault();
+ });
+
+ $size
+ .prepend($ascending.clone()).prepend($descending.clone())
+ .click(function (event) {
+ sortBy("s" + ($size.hasClass("ascending") ? "d" : "a"));
+ event.preventDefault();
+ });
};
- }());
+
+ H5AI.sort = {
+ init: init
+ };
}(jQuery, H5AI));
diff --git a/src/_h5ai/js/inc/Util.js b/src/_h5ai/js/inc/Util.js
index 3fa02f5d..9f3066d6 100644
--- a/src/_h5ai/js/inc/Util.js
+++ b/src/_h5ai/js/inc/Util.js
@@ -1,120 +1,117 @@
(function ($, H5AI) {
- H5AI.util = (function () {
+ var reSplitPath = /^\/([^\/]+\/?)$/,
+ reSplitPath2 = /^(\/(?:.*\/)*?([^\/]+)\/)([^\/]+\/?)$/,
+ splitPath = function (pathname) {
- var reSplitPath = /^\/([^\/]+\/?)$/,
- reSplitPath2 = /^(\/(?:.*\/)*?([^\/]+)\/)([^\/]+\/?)$/,
- splitPath = function (pathname) {
+ var match;
- var match;
+ if (pathname === "/") {
+ return {
+ parent: null,
+ parentname: null,
+ name: "/"
+ };
+ }
+ match = reSplitPath2.exec(pathname);
+ if (match) {
+ return {
+ parent: match[1],
+ parentname: match[2],
+ name: match[3]
+ };
+ }
+ match = reSplitPath.exec(pathname);
+ if (match) {
+ return {
+ parent: "/",
+ parentname: "/",
+ name: match[1]
+ };
+ }
+ },
+ rePathEndsWithSlash = /\/$/,
+ pathEndsWithSlash = function (pathname) {
- if (pathname === "/") {
- return {
- parent: null,
- parentname: null,
- name: "/"
- };
- }
- match = reSplitPath2.exec(pathname);
- if (match) {
- return {
- parent: match[1],
- parentname: match[2],
- name: match[3]
- };
- }
- match = reSplitPath.exec(pathname);
- if (match) {
- return {
- parent: "/",
- parentname: "/",
- name: match[1]
- };
- }
- },
- rePathEndsWithSlash = /\/$/,
- pathEndsWithSlash = function (pathname) {
+ return rePathEndsWithSlash.test(pathname);
+ },
+ getAbsHref = function (folder, tableRow) {
- return rePathEndsWithSlash.test(pathname);
- },
- getAbsHref = function (folder, tableRow) {
+ var $a, isParentFolder, href;
- 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;
+ },
+ kilo = 1000.0,
+ reParseSize = /^\s*([\.\d]+)\s*([kmg]?)b?\s*$/i,
+ parseSize = function (str) {
- 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;
- },
- kilo = 1000.0,
- reParseSize = /^\s*([\.\d]+)\s*([kmg]?)b?\s*$/i,
- parseSize = function (str) {
+ var match = reParseSize.exec(str),
+ val, unit;
- var match = reParseSize.exec(str),
- val, unit;
+ if (!match) {
+ return -1;
+ }
- if (!match) {
- return -1;
- }
+ val = parseFloat(match[1]);
+ unit = match[2].toLowerCase();
+ if (unit === "k") {
+ val *= kilo;
+ } else if (unit === "m") {
+ val *= kilo * kilo;
+ } else if (unit === "g") {
+ val *= kilo * kilo * kilo;
+ } else if (unit === "t") {
+ val *= kilo * kilo * kilo * kilo;
+ }
+ return val;
+ },
+ sizeUnits = ["B", "KB", "MB", "GB", "TB"],
+ formatSize = function (size) {
- val = parseFloat(match[1]);
- unit = match[2].toLowerCase();
- if (unit === "k") {
- val *= kilo;
- } else if (unit === "m") {
- val *= kilo * kilo;
- } else if (unit === "g") {
- val *= kilo * kilo * kilo;
- } else if (unit === "t") {
- val *= kilo * kilo * kilo * kilo;
- }
- return val;
- },
- sizeUnits = ["B", "KB", "MB", "GB", "TB"],
- formatSize = function (size) {
+ var th = 1000.0,
+ i = 0,
+ maxI = sizeUnits.length - 1;
- var th = 1000.0,
- i = 0,
- maxI = sizeUnits.length - 1;
+ if (isNaN(size)) {
+ return size;
+ }
- if (isNaN(size)) {
- return size;
- }
+ while (size >= th && i < maxI) {
+ size /= kilo;
+ i += 1;
+ }
+ return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + " " + sizeUnits[i];
+ },
+ checkedDecodeUri = function (uri) {
- while (size >= th && i < maxI) {
- size /= kilo;
- i += 1;
- }
- return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + " " + sizeUnits[i];
- },
- checkedDecodeUri = function (uri) {
+ try {
+ return decodeURI(uri);
+ } catch (err) {}
+ return uri;
+ },
+ reEscape = function (sequence) {
- try {
- return decodeURI(uri);
- } catch (err) {}
- return uri;
- },
- reEscape = function (sequence) {
-
- return sequence.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
- };
-
- return {
- splitPath: splitPath,
- pathEndsWithSlash: pathEndsWithSlash,
- getAbsHref: getAbsHref,
- parseSize: parseSize,
- formatSize: formatSize,
- checkedDecodeUri: checkedDecodeUri,
- reEscape: reEscape
+ return sequence.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
};
- }());
+
+ H5AI.util = {
+ splitPath: splitPath,
+ pathEndsWithSlash: pathEndsWithSlash,
+ getAbsHref: getAbsHref,
+ parseSize: parseSize,
+ formatSize: formatSize,
+ checkedDecodeUri: checkedDecodeUri,
+ reEscape: reEscape
+ };
}(jQuery, H5AI));
diff --git a/src/_h5ai/js/inc/ZippedDownload.js b/src/_h5ai/js/inc/ZippedDownload.js
index 45d7c1cc..7c100655 100644
--- a/src/_h5ai/js/inc/ZippedDownload.js
+++ b/src/_h5ai/js/inc/ZippedDownload.js
@@ -1,191 +1,188 @@
(function ($, H5AI) {
- H5AI.zippedDownload = (function () {
+ var x = 0,
+ y = 0,
+ $document = $(document),
+ $selectionRect = $("#selection-rect"),
+ selectedHrefsStr = "",
+ $download, $img, $downloadAuth, $downloadUser, $downloadPassword,
- var x = 0,
- y = 0,
- $document = $(document),
- $selectionRect = $("#selection-rect"),
- selectedHrefsStr = "",
- $download, $img, $downloadAuth, $downloadUser, $downloadPassword,
+ updateDownloadBtn = function () {
- updateDownloadBtn = function () {
+ var $selected = $("#extended a.selected"),
+ $downloadBtn = $("#download");
- var $selected = $("#extended a.selected"),
- $downloadBtn = $("#download");
+ selectedHrefsStr = "";
+ if ($selected.length) {
+ $selected.each(function () {
- selectedHrefsStr = "";
- if ($selected.length) {
- $selected.each(function () {
-
- var href = $(this).attr("href");
- selectedHrefsStr = selectedHrefsStr ? selectedHrefsStr + ":" + href : href;
- });
- $downloadBtn.show();
- } else {
- $downloadBtn.hide();
- $downloadAuth.hide();
- }
- },
- selectionUpdate = function (event) {
-
- var l = Math.min(x, event.pageX),
- t = Math.min(y, event.pageY),
- w = Math.abs(x - event.pageX),
- h = Math.abs(y - event.pageY),
- selRect;
-
- event.preventDefault();
- $selectionRect.css({left: l, top: t, width: w, height: h});
-
- selRect = $selectionRect.fracs("rect");
- $("#extended a").removeClass("selecting").each(function () {
-
- var $a = $(this),
- rect = $a.fracs("rect"),
- inter = selRect.intersection(rect);
- if (inter && !$a.closest(".entry").hasClass("folder-parent")) {
- $a.addClass("selecting");
- }
+ var href = $(this).attr("href");
+ selectedHrefsStr = selectedHrefsStr ? selectedHrefsStr + ":" + href : href;
});
- },
- selectionEnd = function (event) {
+ $downloadBtn.show();
+ } else {
+ $downloadBtn.hide();
+ $downloadAuth.hide();
+ }
+ },
+ selectionUpdate = function (event) {
- event.preventDefault();
- $document.off("mousemove", selectionUpdate);
- $selectionRect.hide().css({left: 0, top: 0, width: 0, height: 0});
- $("#extended a.selecting.selected").removeClass("selecting").removeClass("selected");
- $("#extended a.selecting").removeClass("selecting").addClass("selected");
+ var l = Math.min(x, event.pageX),
+ t = Math.min(y, event.pageY),
+ w = Math.abs(x - event.pageX),
+ h = Math.abs(y - event.pageY),
+ selRect;
+
+ event.preventDefault();
+ $selectionRect.css({left: l, top: t, width: w, height: h});
+
+ selRect = $selectionRect.fracs("rect");
+ $("#extended a").removeClass("selecting").each(function () {
+
+ var $a = $(this),
+ rect = $a.fracs("rect"),
+ inter = selRect.intersection(rect);
+ if (inter && !$a.closest(".entry").hasClass("folder-parent")) {
+ $a.addClass("selecting");
+ }
+ });
+ },
+ selectionEnd = function (event) {
+
+ event.preventDefault();
+ $document.off("mousemove", selectionUpdate);
+ $selectionRect.hide().css({left: 0, top: 0, width: 0, height: 0});
+ $("#extended a.selecting.selected").removeClass("selecting").removeClass("selected");
+ $("#extended a.selecting").removeClass("selecting").addClass("selected");
+ updateDownloadBtn();
+ },
+ selectionStart = function (event) {
+
+ var view = $.fracs.viewport();
+
+ x = event.pageX;
+ y = event.pageY;
+ // only on left button and don't block the scrollbars
+ if (event.button !== 0 || x >= view.right || y >= view.bottom) {
+ return;
+ }
+
+ event.preventDefault();
+ $(':focus').blur();
+ if (!event.ctrlKey) {
+ $("#extended a").removeClass("selected");
updateDownloadBtn();
- },
- selectionStart = function (event) {
+ }
+ $selectionRect.show().css({left: x, top: y, width: 0, height: 0});
- var view = $.fracs.viewport();
+ $document
+ .on("mousemove", selectionUpdate)
+ .one("mouseup", selectionEnd);
+ },
+ noSelection = function (event) {
- x = event.pageX;
- y = event.pageY;
- // only on left button and don't block the scrollbars
- if (event.button !== 0 || x >= view.right || y >= view.bottom) {
- return;
- }
+ event.stopImmediatePropagation();
+ return false;
+ },
+ noSelectionUnlessCtrl = function (event) {
- event.preventDefault();
- $(':focus').blur();
- if (!event.ctrlKey) {
- $("#extended a").removeClass("selected");
- updateDownloadBtn();
- }
- $selectionRect.show().css({left: x, top: y, width: 0, height: 0});
+ if (!event.ctrlKey) {
+ noSelection(event);
+ }
+ },
+ failed = function () {
- $document
- .on("mousemove", selectionUpdate)
- .one("mouseup", selectionEnd);
- },
- noSelection = function (event) {
-
- event.stopImmediatePropagation();
- return false;
- },
- noSelectionUnlessCtrl = function (event) {
-
- if (!event.ctrlKey) {
- noSelection(event);
- }
- },
- failed = function () {
-
- $download.addClass('failed');
- setTimeout(function () {
- $download.removeClass('failed');
- }, 1000);
- },
- handleResponse = function (response) {
+ $download.addClass('failed');
+ setTimeout(function () {
+ $download.removeClass('failed');
+ }, 1000);
+ },
+ handleResponse = function (response) {
- $download.removeClass('current');
- $img.attr('src', H5AI.core.image("download"));
+ $download.removeClass('current');
+ $img.attr('src', H5AI.core.image("download"));
- if (response) {
- if (response.status === 'ok') {
- window.location = H5AI.core.api() + '?action=getzip&id=' + response.id;
- } else {
- if (response.code === 401) {
- $downloadAuth
- .css({
- left: $download.offset().left,
- top: $download.offset().top + $download.outerHeight()
- })
- .show();
- $downloadUser.focus();
- }
- failed();
- }
+ if (response) {
+ if (response.status === 'ok') {
+ window.location = H5AI.core.api() + '?action=getzip&id=' + response.id;
} else {
+ if (response.code === 401) {
+ $downloadAuth
+ .css({
+ left: $download.offset().left,
+ top: $download.offset().top + $download.outerHeight()
+ })
+ .show();
+ $downloadUser.focus();
+ }
failed();
}
- },
- requestZipping = function (hrefsStr) {
+ } else {
+ failed();
+ }
+ },
+ requestZipping = function (hrefsStr) {
- $download.addClass('current');
- $img.attr('src', H5AI.core.image("loading.gif", true));
- $.ajax({
- url: H5AI.core.api(),
- data: {
- action: 'zip',
- hrefs: selectedHrefsStr
- },
- type: 'POST',
- dataType: 'json',
- beforeSend: function (xhr) {
+ $download.addClass('current');
+ $img.attr('src', H5AI.core.image("loading.gif", true));
+ $.ajax({
+ url: H5AI.core.api(),
+ data: {
+ action: 'zip',
+ hrefs: selectedHrefsStr
+ },
+ type: 'POST',
+ dataType: 'json',
+ beforeSend: function (xhr) {
- var user = $downloadUser.val(),
- password = $downloadPassword.val();
+ var user = $downloadUser.val(),
+ password = $downloadPassword.val();
- if (user) {
- xhr.setRequestHeader ('Authorization', 'Basic ' + Base64.encode(user + ':' + password));
- }
- },
- success: function (response) {
-
- handleResponse(response);
- },
- failed: function () {
-
- handleResponse();
+ if (user) {
+ xhr.setRequestHeader ('Authorization', 'Basic ' + Base64.encode(user + ':' + password));
}
- });
- },
- init = function () {
+ },
+ success: function (response) {
- if (H5AI.core.settings.zippedDownload) {
- $("
download")
- .find("img").attr("src", H5AI.core.image("download")).end()
- .find("a").click(function (event) {
+ handleResponse(response);
+ },
+ failed: function () {
- event.preventDefault();
- $downloadAuth.hide();
- requestZipping(selectedHrefsStr);
- }).end()
- .appendTo($("#navbar"));
- $("")
- .appendTo($("body"));
-
- $download = $('#download');
- $downloadAuth = $('#download-auth');
- $downloadUser = $('#download-auth-user');
- $downloadPassword = $('#download-auth-password');
- $img = $download.find('img');
-
- $("body>nav,body>footer,#tree,input").on("mousedown", noSelection);
- $("#content").on("mousedown", "a", noSelectionUnlessCtrl);
- $document.on("mousedown", selectionStart);
+ handleResponse();
}
- };
+ });
+ },
+ init = function () {
- return {
- init: init
+ if (H5AI.core.settings.zippedDownload) {
+ $("
download")
+ .find("img").attr("src", H5AI.core.image("download")).end()
+ .find("a").click(function (event) {
+
+ event.preventDefault();
+ $downloadAuth.hide();
+ requestZipping(selectedHrefsStr);
+ }).end()
+ .appendTo($("#navbar"));
+ $("")
+ .appendTo($("body"));
+
+ $download = $('#download');
+ $downloadAuth = $('#download-auth');
+ $downloadUser = $('#download-auth-user');
+ $downloadPassword = $('#download-auth-password');
+ $img = $download.find('img');
+
+ $("body>nav,body>footer,#tree,input").on("mousedown", noSelection);
+ $("#content").on("mousedown", "a", noSelectionUnlessCtrl);
+ $document.on("mousedown", selectionStart);
+ }
};
- }());
+
+ H5AI.zippedDownload = {
+ init: init
+ };
}(jQuery, H5AI));
diff --git a/src/_h5ai/js/inc/main.js b/src/_h5ai/js/inc/main.js
index 9fa0b7f1..5b169f34 100644
--- a/src/_h5ai/js/inc/main.js
+++ b/src/_h5ai/js/inc/main.js
@@ -2,7 +2,7 @@
(function ($) {
'use strict';
/*jslint browser: true, confusion: true, regexp: true, vars: true, white: true */
-/*global Modernizr, jQuery, amplify, H5AI_CONFIG */
+/*global Modernizr, jQuery, amplify, Base64, H5AI_CONFIG */
var H5AI = {};