diff --git a/build.properties b/build.properties index 9ea727a9..061dc895 100644 --- a/build.properties +++ b/build.properties @@ -16,5 +16,5 @@ release.dir = release # tools -wepp = tools/wepp +tool.wepp = tools/wepp diff --git a/src/h5ai/css/inc/extended.less b/src/h5ai/css/inc/extended.less index 6aa5b6d0..a89a2c1b 100644 --- a/src/h5ai/css/inc/extended.less +++ b/src/h5ai/css/inc/extended.less @@ -45,7 +45,7 @@ background-color: #f6f6f6; color: #e80; } - &.selected { + &.selected:not(.selecting), &.selecting:not(.selected) { border-color: rgba(240,100,0,0.2); background-color: rgba(240,100,0,0.2); } @@ -193,7 +193,7 @@ border-color: #eee; background-color: #f6f6f6; } - &.selected { + &.selected:not(.selecting), &.selecting:not(.selected) { border-color: rgba(240,100,0,0.2); background-color: rgba(240,100,0,0.2); } diff --git a/src/h5ai/footer.html b/src/h5ai/footer.html index 1d81b3f8..07167e41 100644 --- a/src/h5ai/footer.html +++ b/src/h5ai/footer.html @@ -27,9 +27,7 @@ - - - + diff --git a/src/h5ai/header.html b/src/h5ai/header.html index 7764bd33..11cd52a7 100644 --- a/src/h5ai/header.html +++ b/src/h5ai/header.html @@ -14,7 +14,7 @@ - +
diff --git a/src/h5ai/header.php b/src/h5ai/header.php index 79ec5817..6e645106 100644 --- a/src/h5ai/header.php +++ b/src/h5ai/header.php @@ -15,7 +15,7 @@ - +
@@ -60,9 +60,7 @@ - - - +
diff --git a/src/h5ai/js/inc/tree.js b/src/h5ai/js/inc/Connector.js similarity index 81% rename from src/h5ai/js/inc/tree.js rename to src/h5ai/js/inc/Connector.js index fa2dc0f9..ab644855 100644 --- a/src/h5ai/js/inc/tree.js +++ b/src/h5ai/js/inc/Connector.js @@ -1,13 +1,13 @@ -/*global $, Objects */ +/*global $, H5aiJs */ -Objects.Tree = function (pathCache, h5ai) { +H5aiJs.factory.Connector = function () { var contentTypeRegEx = /^text\/html;h5ai=/, pathnameStatusCache = {}, fetchStatus = function (pathname, callback) { - if (h5ai.settings.folderStatus[pathname]) { - callback(h5ai.settings.folderStatus[pathname]); + if (H5aiJs.h5ai.settings.folderStatus[pathname]) { + callback(H5aiJs.h5ai.settings.folderStatus[pathname]); return; } else if (pathnameStatusCache[pathname]) { callback(pathnameStatusCache[pathname]); @@ -37,14 +37,14 @@ Objects.Tree = function (pathCache, h5ai) { if (status !== "h5ai") { path.status = status; } - path.updateHtml(); - h5ai.linkHoverStates(); + H5aiJs.html.updateHtml(path); + H5aiJs.h5ai.linkHoverStates(); }); } }, updatePaths = function () { - $.each(pathCache.cache, function (ref, cached) { + $.each(H5aiJs.pathCache.cache, function (ref, cached) { updatePath(cached); }); }, @@ -76,7 +76,7 @@ Objects.Tree = function (pathCache, h5ai) { $(html).find("#table td").closest("tr").each(function () { - var path = pathCache.getPath(pathname, this); + var path = H5aiJs.pathCache.getPath(pathname, this); if (path.isFolder && (!path.isParentFolder || includeParent)) { content[path.absHref] = path; @@ -92,7 +92,7 @@ Objects.Tree = function (pathCache, h5ai) { fetchStatusAndContent(pathname, false, function (status, content) { - var path = pathCache.getPath(pathname); + var path = H5aiJs.pathCache.getPath(pathname); path.status = status; path.content = content; @@ -103,7 +103,7 @@ Objects.Tree = function (pathCache, h5ai) { fetchPath(pathname, function (path) { - var parent = pathCache.splitPathname(pathname)[0]; + var parent = H5aiJs.pathCache.splitPathname(pathname)[0]; path.treeOpen = true; if (childPath) { @@ -120,25 +120,24 @@ Objects.Tree = function (pathCache, h5ai) { fetchTree(document.location.pathname, function (path) { $("#tree") - .append(path.updateTreeHtml()) + .append(H5aiJs.html.updateTreeHtml(path)) .scrollpanel() .show(); - h5ai.shiftTree(false, true); - h5ai.linkHoverStates(); + H5aiJs.h5ai.shiftTree(false, true); + H5aiJs.h5ai.linkHoverStates(); setTimeout(function () { $("#tree").get(0).updateScrollbar(); }, 1); }); }, init = function () { - if (h5ai.settings.showTree) { + if (H5aiJs.h5ai.settings.showTree) { updatePaths(); populateTree(); } - }, - tree = { - fetchStatusAndContent: fetchStatusAndContent, - init: init }; - return tree; + return { + fetchStatusAndContent: fetchStatusAndContent, + init: init + }; }; diff --git a/src/h5ai/js/inc/extended.js b/src/h5ai/js/inc/Extended.js similarity index 81% rename from src/h5ai/js/inc/extended.js rename to src/h5ai/js/inc/Extended.js index e741865d..1de1bec1 100644 --- a/src/h5ai/js/inc/extended.js +++ b/src/h5ai/js/inc/Extended.js @@ -1,6 +1,6 @@ -/*global $, Objects */ +/*global $, H5aiJs */ -Objects.Extended = function (pathCache, h5ai) { +H5aiJs.factory.Extended = function () { var settings = { customHeader: "h5ai.header.html", @@ -17,15 +17,15 @@ Objects.Extended = function (pathCache, h5ai) { var $ul = $("body > nav ul"), pathname = "/", - path = pathCache.getPath(pathname), + path = H5aiJs.pathCache.getPath(pathname), pathnameParts = document.location.pathname.split("/"); - $ul.append(path.updateCrumbHtml()); + $ul.append(H5aiJs.html.updateCrumbHtml(path)); $.each(pathnameParts, function (idx, part) { if (part !== "") { pathname += part + "/"; - $ul.append(pathCache.getPath(pathname).updateCrumbHtml()); + $ul.append(H5aiJs.html.updateCrumbHtml(H5aiJs.pathCache.getPath(pathname))); } }); }, @@ -37,8 +37,8 @@ Objects.Extended = function (pathCache, h5ai) { $size = $ths.eq(3).find("a"), sortquery = document.location.search, order = { - column: (sortquery.indexOf("C=N") >= 0) ? "name" : (sortquery.indexOf("C=M") >= 0) ? "date" : (sortquery.indexOf("C=S") >= 0) ? "size" : h5ai.settings.sortorder.column, - ascending: (sortquery.indexOf("O=A") >= 0) ? true : (sortquery.indexOf("O=D") >= 0) ? false : h5ai.settings.sortorder.ascending + column: (sortquery.indexOf("C=N") >= 0) ? "name" : (sortquery.indexOf("C=M") >= 0) ? "date" : (sortquery.indexOf("C=S") >= 0) ? "size" : H5aiJs.h5ai.settings.sortorder.column, + ascending: (sortquery.indexOf("O=A") >= 0) ? true : (sortquery.indexOf("O=D") >= 0) ? false : H5aiJs.h5ai.settings.sortorder.ascending }, $icon, $ul, $li; @@ -66,8 +66,8 @@ Objects.Extended = function (pathCache, h5ai) { // entries $("#table td").closest("tr").each(function () { - var path = pathCache.getPath(document.location.pathname, this); - $ul.append(path.updateExtendedHtml()); + var path = H5aiJs.pathCache.getPath(document.location.pathname, this); + $ul.append(H5aiJs.html.updateExtendedHtml(path)); }); $("#extended").append($ul); @@ -95,22 +95,18 @@ Objects.Extended = function (pathCache, h5ai) { } }); }, - initCounts = function () { + initTotals = function () { $(".folderCount").text($("#extended .entry.folder:not(.parentfolder)").size()); $(".fileCount").text($("#extended .entry.file").size()); - }, - init = function () { - - initTitle(); - initBreadcrumb(); - initExtendedView(); - customize(); - initCounts(); - }, - extended = { - init: init }; - return extended; + this.init = function () { + + initTitle(); + initBreadcrumb(); + initExtendedView(); + customize(); + initTotals(); + }; }; diff --git a/src/h5ai/js/inc/h5ai.js b/src/h5ai/js/inc/H5ai.js similarity index 73% rename from src/h5ai/js/inc/h5ai.js rename to src/h5ai/js/inc/H5ai.js index 56cfcfc6..6b3d1adb 100644 --- a/src/h5ai/js/inc/h5ai.js +++ b/src/h5ai/js/inc/H5ai.js @@ -1,11 +1,13 @@ -/*global window, $, Objects, localStorage */ -Objects.H5ai = function (options, langs) { +H5aiJs.factory.H5ai = function (options, langs) { + /*global window, $, amplify*/ - var defaults = { + var $window = $(window), + $document = $(document), + defaults = { store: { - viewmode: "h5ai.viewmode", - lang: "h5ai.lang" + viewmode: "h5ai.pref.viewmode", + lang: "h5ai.pref.lang" }, callbacks: { pathClick: [] @@ -41,19 +43,19 @@ Objects.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 () { - var viewmode = localStorage.getItem(settings.store.viewmode); + var viewmode = amplify.store(settings.store.viewmode); return $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0]; }, applyViewmode = function (viewmode) { if (viewmode) { - localStorage.setItem(settings.store.viewmode, viewmode); + amplify.store(settings.store.viewmode, viewmode); } viewmode = getViewmode(); @@ -82,7 +84,7 @@ Objects.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 +105,7 @@ Objects.H5ai = function (options, langs) { } catch (err) {} }; - $(window).resize(function () { + $window.resize(function () { adjustTopSpace(); }); adjustTopSpace(); @@ -141,7 +143,7 @@ Objects.H5ai = function (options, langs) { $(".status.default").show(); $(".status.dynamic").empty().hide(); } - ); + ); }, shiftTree = function (forceVisible, dontAnimate) { @@ -168,7 +170,7 @@ Objects.H5ai = function (options, langs) { function () { shiftTree(true); }, function () { shiftTree(); } ); - $(window).resize(function () { shiftTree(); }); + $window.resize(function () { shiftTree(); }); shiftTree(false, true); }, linkHoverStates = function () { @@ -188,7 +190,7 @@ Objects.H5ai = function (options, langs) { }, localize = function (langs, lang, useBrowserLang) { - var storedLang = localStorage.getItem(settings.store.lang), + var storedLang = amplify.store(settings.store.lang), browserLang, selected, key; if (langs[storedLang]) { @@ -218,7 +220,7 @@ Objects.H5ai = function (options, langs) { }, initLangSelector = function (langs) { - var idx, lang, + var $langOptions = $(".langOptions"), sortedLangsKeys = [], $ul; @@ -234,18 +236,22 @@ Objects.H5ai = function (options, langs) { .text(lang + " - " + langs[lang].lang) .appendTo($ul) .click(function () { - localStorage.setItem(settings.store.lang, lang); + amplify.store(settings.store.lang, lang); localize(langs, lang, false); }); }); $("#langSelector .langOptions").append($ul); $("#langSelector").hover( function () { - var $ele = $(".langOptions"); - $ele.css("top", "-" + $ele.outerHeight() + "px").stop(true, true).fadeIn(); + $langOptions + .css("top", "-" + $langOptions.outerHeight() + "px") + .stop(true, true) + .fadeIn(); }, function () { - $(".langOptions").stop(true, true).fadeOut(); + $langOptions + .stop(true, true) + .fadeOut(); } ); }, @@ -256,7 +262,7 @@ Objects.H5ai = function (options, langs) { if ($indicator.hasClass("unknown")) { $.get("/h5ai/php/treecontent.php", { "href": $entry.find("> a").attr("href") }, function (html) { - + var $content = $(html); $indicator.removeClass("unknown"); @@ -266,7 +272,9 @@ Objects.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,24 +293,31 @@ Objects.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) { + ctrl = false, + updateDownloadBtn = function () { - var query, idx; - $.each(hrefs, function (idx, href) { - query = query ? query + ":" + href : href; - }); - query = "/h5ai/php/zipcontent.php?hrefs=" + query; - $("#download").show().find("a").attr("href", query); + var query, + href, + $selected = $("#extended a.selected"); + + if ($selected.size() > 0) { + $selected.each(function () { + href = $(this).attr("href"); + query = query ? query + ":" + href : href; + }); + query = "/h5ai/php/zipcontent.php?hrefs=" + query; + $("#download").show().find("a").attr("href", query); + } else { + $("#download").hide().find("a").attr("href", "#"); + } }, selectionUpdate = function (event) { @@ -316,41 +331,45 @@ Objects.H5ai = function (options, langs) { $("#selection-rect").css({left: l, top: t, width: w, height: h}); sel = $("#selection-rect").fracs("rect"); - $("#extended a").removeClass("selected").each(function () { + $("#extended a").removeClass("selecting").each(function () { var $a = $(this), rect = $a.fracs("rect"), inter = sel.intersection(rect); if (inter && !$a.closest(".entry").hasClass("folder-parent")) { - $a.addClass("selected"); + $a.addClass("selecting"); } }); }, selectionEnd = function (event) { event.preventDefault(); + $document.unbind("mousemove", selectionUpdate); $("#selection-rect").hide().css({left: 0, top: 0, width: 0, height: 0}); - - $window.unbind("mousemove", selectionUpdate); - - var hrefs = []; - $("#extended a.selected").each(function () { - hrefs.push($(this).attr("href")); - }); - if (hrefs.length > 0) { - selected(hrefs); - } + $("#extended a.selecting.selected").removeClass("selecting").removeClass("selected"); + $("#extended a.selecting").removeClass("selecting").addClass("selected"); + updateDownloadBtn(); }, selectionStart = function (event) { - event.preventDefault(); + var view = $.fracs.viewport(); + x = event.pageX; y = event.pageY; - $("#download").hide().find("a").attr("href", "#"); - $("#extended a").removeClass("selected"); - $("#selection-rect").show().css({left: x, top: y, width: 0, height: 0}); + if (x >= view.right || y >= view.bottom) { + // don't block the scrollbars + return; + } - $window + event.preventDefault(); + if (!ctrl) { + $("#extended a").removeClass("selected"); + updateDownloadBtn(); + } + $("#selection-rect").show().css({left: x, top: y, width: 0, height: 0}); + selectionUpdate(event); + + $document .bind("mousemove", selectionUpdate) .one("mouseup", selectionEnd); }, @@ -358,12 +377,29 @@ Objects.H5ai = function (options, langs) { event.stopPropagation(); return false; + }, + noSelectionUnlessCtrl = function (event) { + + if (!ctrl) { + noSelection(event); + } }; if (settings.zippedDownload) { - $("body>nav,body>footer,#tree,#extended a").bind("mousedown", noSelection); - $("#extended a").live("mousedown", noSelection); - $window.bind("mousedown", selectionStart); + $("body>nav,body>footer,#tree").bind("mousedown", noSelection); + $("#extended .entry a").bind("mousedown", noSelectionUnlessCtrl).live("mousedown", noSelectionUnlessCtrl); + $document + .bind("mousedown", selectionStart) + .keydown(function (event) { + if (event.keyCode === 17) { + ctrl = true; + } + }) + .keyup(function (event) { + if (event.keyCode === 17) { + ctrl = false; + } + }); } }, init = function () { @@ -377,16 +413,15 @@ Objects.H5ai = function (options, langs) { localize(langs, settings.lang, settings.useBrowserLang); initIndicators(); initZippedDownload(); - }, - h5ai = { - settings: settings, - shiftTree: shiftTree, - linkHoverStates: linkHoverStates, - pathClick: pathClick, - triggerPathClick: triggerPathClick, - initIndicators: initIndicators, - init: init }; - return h5ai; + return { + settings: settings, + shiftTree: shiftTree, + linkHoverStates: linkHoverStates, + pathClick: pathClick, + triggerPathClick: triggerPathClick, + initIndicators: initIndicators, + init: init + }; }; diff --git a/src/h5ai/js/inc/Html.js b/src/h5ai/js/inc/Html.js new file mode 100644 index 00000000..79e5977e --- /dev/null +++ b/src/h5ai/js/inc/Html.js @@ -0,0 +1,260 @@ +/*global $, H5aiJs */ + +H5aiJs.factory.Html = function () { + + var imagesPath = "/h5ai/images", + iconsPath = "/h5ai/icons", + image = function (id) { + + return imagesPath + "/" + id + ".png"; + }, + icon = function (id, big) { + + return iconsPath + "/" + (big ? "48x48" : "16x16") + "/" + id + ".png"; + }, + onClick = function (path, context) { + + H5aiJs.h5ai.triggerPathClick(path, context); + }, + updateCrumbHtml = function (path) { + + var $html, $a; + + if (path.html.$crumb && path.html.$crumb.data("status") === path.status) { + return path.html.$crumb; + } + + $html = $("
  • ") + .data("path", path) + .addClass(path.isFolder ? "folder" : "file"); + + if (path.status) { + $html.data("status", path.status); + } + + $a = $(">" + path.label + "") + .appendTo($html) + .attr("href", path.absHref) + .click(function() { onClick(path, "crumb"); }); + + if (path.isDomain) { + $html.addClass("domain"); + $a.find("img").attr("src", image("home")); + } + + if (path.isCurrentFolder) { + $html.addClass("current"); + } + + if (!isNaN(path.status)) { + if (path.status === 200) { + $("not listable").appendTo($a); + } else { + $("(" + path.status + ")").appendTo($a); + } + } + + if (path.html.$crumb) { + path.html.$crumb.replaceWith($html); + } + path.html.$crumb = $html; + + return $html; + }, + updateExtendedHtml = function (path) { + + var $html, $a, $label; + + if (path.html.$extended && path.html.$extended.data("status") === path.status) { + return path.html.$extended; + } + + $html = $("
  • ") + .data("path", path) + .addClass(path.isFolder ? "folder" : "file"); + + if (path.status) { + $html.data("status", path.status); + } + + $label = $("" + path.label + ""); + $a = $("") + .attr("href", path.absHref) + .click(function() { onClick(path, "extended"); }) + .appendTo($html) + .append($("" + path.alt + "")) + .append($("" + path.alt + "")) + .append($label) + .append($("" + path.date + "")) + .append($("" + path.size + "")); + + $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 (!H5aiJs.h5ai.settings.setParentFolderLabels) { + $label.addClass("l10n-parentDirectory"); + } + $html.addClass("folder-parent"); + } + + if (!isNaN(path.status)) { + if (path.status === 200) { + $html.addClass("page"); + $a.find(".icon.small img").attr("src", icon("folder-page")); + $a.find(".icon.big img").attr("src", icon("folder-page", true)); + } else { + $html.addClass("error"); + $label.append($(" " + path.status + " ")); + } + } + + if (path.html.$extended) { + path.html.$extended.replaceWith($html); + } + path.html.$extended = $html; + + return $html; + }, + updateTreeHtml = function (path) { + + var $html, $blank, $a, $indicator, $ul, idx; + + $html = $("
    ") + .data("path", path) + .addClass(path.isFolder ? "folder" : "file"); + + $blank = $("").appendTo($html); + + $a = $("") + .attr("href", path.absHref) + .click(function() { path.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")) { + H5aiJs.connector.fetchStatusAndContent(path.absHref, false, function (status, content) { + + path.status = status; + path.content = content; + path.treeOpen = true; + $("#tree").get(0).updateScrollbar(true); + updateTreeHtml(path); + $("#tree").get(0).updateScrollbar(); + }); + } else if ($indicator.hasClass("open")) { + path.treeOpen = false; + $indicator.removeClass("open"); + $("#tree").get(0).updateScrollbar(true); + $entry.find("> ul.content").slideUp(function() { + + $("#tree").get(0).updateScrollbar(); + }); + } else { + path.treeOpen = true; + $indicator.addClass("open"); + $("#tree").get(0).updateScrollbar(true); + $entry.find("> ul.content").slideDown(function() { + + $("#tree").get(0).updateScrollbar(); + }); + } + + }); + + if (path.status === undefined) { + $indicator.addClass("unknown"); + } else if (path.treeOpen) { + $indicator.addClass("open"); + } + + $blank.replaceWith($indicator); + } + + // is path the domain? + if (path.isDomain) { + $html.addClass("domain"); + $a.find(".icon img").attr("src", icon("folder-home")); + } + + // is path the current folder? + if (path.isCurrentFolder) { + $html.addClass("current"); + $a.find(".icon img").attr("src", icon("folder-open")); + } + + // does it have subfolders? + if (!path.isEmpty()) { + $ul = $("