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) { - $("
  • view-iconsicons
  • ") - .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) { - $("
  • view-detailsdetails
  • ") - .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) { + $("
  • view-iconsicons
  • ") + .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) { + $("
  • view-detailsdetails
  • ") + .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 = $("