1
0
mirror of https://github.com/lrsjng/h5ai.git synced 2025-08-30 01:00:07 +02:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Lars Jung
a8f62f187c Added it translation. Switched to wepp. 2011-09-18 19:49:26 +02:00
Lars Jung
8e21a3c038 Fixed security issues. 2011-09-06 20:57:49 +02:00
Lars Jung
df30c67ade Added selection and zipped download. 2011-09-04 21:18:55 +02:00
Lars Jung
2d3b0eed4f Added selection and zipped download. 2011-09-04 21:18:19 +02:00
47 changed files with 3985 additions and 3032 deletions

View File

@@ -10,6 +10,24 @@ It uses the [Faenza icon set](http://tiheum.deviantart.com/art/Faenza-Icons-1733
## Changelog ## Changelog
### v0.15.2 · *2011-09-18*
* added it translation by [Salvo Gentile](http://github.com/SalvoGentile) and [Marco Patriarca](http://github.com/Fexys)
* switched build process from scripp to wepp
### v0.15.1 · *2011-09-06*
* fixed security issues with the zipped download feature
* made zipped download optional (but enabled by default)
### v0.15 · *2011-09-04*
* added zipped download for selected files
* cleaned and refactored
### v0.14.1 · *2011-09-01* ### v0.14.1 · *2011-09-01*
* display meta information in bottom bar (icon view) * display meta information in bottom bar (icon view)

View File

@@ -3,7 +3,7 @@ custom = true
# project # project
project.name = h5ai project.name = h5ai
project.version = 0.14.1 project.version = 0.15.2
# src # src
@@ -15,6 +15,6 @@ build.dir = build
release.dir = release release.dir = release
# libs # tools
lib.scripp.jar = tools/scripp.jar wepp = tools/wepp

View File

@@ -3,8 +3,10 @@
name="h5ai" name="h5ai"
basedir="." basedir="."
default="release" default="release"
xmlns:scripp="antlib:de.larsjung.scripp.ant"
> >
<import file="tools/wepp.ant.xml" />
<target name="init"> <target name="init">
<property file="build.properties" /> <property file="build.properties" />
<tstamp> <tstamp>
@@ -12,20 +14,13 @@
</tstamp> </tstamp>
<property name="build.label" value="${project.name} ${project.version} b${build.stamp}" /> <property name="build.label" value="${project.name} ${project.version} b${build.stamp}" />
<echo>Build: ${build.label}</echo> <echo>Build: ${build.label}</echo>
<taskdef
resource="de/larsjung/scripp/ant/antlib.xml"
uri="antlib:de.larsjung.scripp.ant"
classpath="${lib.scripp.jar}"
/>
</target> </target>
<target name="clean" depends="init"> <target name="clean" depends="init">
<delete dir="${build.dir}" /> <delete dir="${build.dir}" />
<delete dir="${release.dir}" /> <delete dir="${release.dir}" />
</target> </target>
<target name="build-prepare" depends="clean"> <target name="build-prepare" depends="clean">
<mkdir dir="${build.dir}" /> <mkdir dir="${build.dir}" />
<copy todir="${build.dir}"> <copy todir="${build.dir}">
@@ -41,19 +36,16 @@
</replace> </replace>
</target> </target>
<target name="build" depends="build-prepare"> <target name="build" depends="build-prepare">
<scripp.dir dir="${build.dir}/h5ai/css" /> <wepp.dir dir="${build.dir}/h5ai/css" />
<scripp.dir dir="${build.dir}/h5ai/js" /> <wepp.dir dir="${build.dir}/h5ai/js" />
</target> </target>
<target name="build-uncompressed" depends="build-prepare"> <target name="build-uncompressed" depends="build-prepare">
<scripp.dir dir="${build.dir}/h5ai/css" compress="false" /> <wepp.dir dir="${build.dir}/h5ai/css" args="--nc" />
<scripp.dir dir="${build.dir}/h5ai/js" compress="false" /> <wepp.dir dir="${build.dir}/h5ai/js" args="--nc" />
</target> </target>
<target name="release" depends="build"> <target name="release" depends="build">
<mkdir dir="${release.dir}" /> <mkdir dir="${release.dir}" />
<zip destfile="${release.dir}/${project.name}-${project.version}.zip" basedir="${build.dir}" /> <zip destfile="${release.dir}/${project.name}-${project.version}.zip" basedir="${build.dir}" />
@@ -62,20 +54,4 @@
<delete file="${release.dir}/${project.name}-${project.version}.tar" /> <delete file="${release.dir}/${project.name}-${project.version}.tar" />
</target> </target>
<macrodef name="scripp.dir">
<attribute name="dir" />
<attribute name="compress" default="true" />
<sequential>
<scripp:process compress="@{compress}">
<fileset dir="@{dir}" includes="**/*.less,**/*.css,**/*.js" excludes="inc/**/*,**/*.min.css,**/*.min.js" />
<globmapper from="*.less" to="*.css" />
<globmapper from="*.css" to="*.css" />
<globmapper from="*.js" to="*.js" />
</scripp:process>
<delete dir="@{dir}/inc">
<fileset dir="@{dir}" includes="**/*.less" />
</delete>
</sequential>
</macrodef>
</project> </project>

Binary file not shown.

BIN
release/h5ai-0.15.2.tar.gz Normal file

Binary file not shown.

View File

@@ -33,18 +33,22 @@
} }
} }
&.entry { &.entry {
border-bottom: 1px solid #ddd;
a, a:active, a:visited { a, a:active, a:visited {
display: block; display: block;
color: #555; color: #555;
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
border-bottom: 1px solid #ddd;
&:hover, &.hover { &:hover, &.hover {
background-color: #f6f6f6; background-color: #f6f6f6;
color: #e80; color: #e80;
} }
&.selected {
border-color: rgba(240,100,0,0.2);
background-color: rgba(240,100,0,0.2);
}
} }
&.error { &.error {
a, a:active, a:visited { a, a:active, a:visited {
@@ -140,6 +144,17 @@
} }
#selection-rect {
display: none;
position: absolute;
left: 0;
top: 0;
z-index: 2;
border: 1px dashed rgba(240,100,0,0.5);
background-color: rgba(240,100,0,0.2);
}
#extended.icons-view { #extended.icons-view {
display: none; display: none;
padding: 3px; padding: 3px;
@@ -178,6 +193,10 @@
border-color: #eee; border-color: #eee;
background-color: #f6f6f6; background-color: #f6f6f6;
} }
&.selected {
border-color: rgba(240,100,0,0.2);
background-color: rgba(240,100,0,0.2);
}
.icon { .icon {
display: block; display: block;

View File

@@ -87,6 +87,11 @@ body > nav {
float: right; float: right;
border-left: 1px solid rgb(231,231,231); border-left: 1px solid rgb(231,231,231);
} }
#download {
display: none;
float: right;
border-left: 1px solid rgb(231,231,231);
}
} }
@@ -154,14 +159,14 @@ body > footer {
float: right float: right
} }
.status { .status {
.sep {
display: inline-block;
padding: 0 6px;
}
&.default { &.default {
} }
&.dynamic { &.dynamic {
display: none; display: none;
span {
display: inline-block;
padding: 0 6px;
}
} }
} }
#langSelector { #langSelector {

View File

@@ -5,9 +5,11 @@
#table { #table {
display: none; display: none;
} }
#tree, #content > header, #content > footer { #tree, #content > header, #content > footer {
display: block; display: block;
} }
html.no-js { html.no-js {
#extended.details-view, #extended.icons-view { #extended.details-view, #extended.icons-view {
display: block; display: block;

View File

@@ -1,6 +1,6 @@
<!-- generated code ends here --> <!-- generated code ends here -->
</section> </section>
<section id="extended"></section> <section id="extended" class="clearfix"></section>
<footer></footer> <footer></footer>
</section> </section>
<section id="tree"></section> <section id="tree"></section>
@@ -19,7 +19,7 @@
<span class="hideOnNoJs"> <span class="hideOnNoJs">
<span class="status default"> <span class="status default">
<span class="folderCount"></span> <span class="l10n-folders">folders</span> <span class="folderCount"></span> <span class="l10n-folders">folders</span>
· <span class='sep'>·</span>
<span class="fileCount"></span> <span class="l10n-files">files</span> <span class="fileCount"></span> <span class="l10n-files">files</span>
</span> </span>
<span class="status dynamic"> <span class="status dynamic">

View File

@@ -13,6 +13,7 @@
<script src="/h5ai/js/lib/modernizr.min.js"></script> <script src="/h5ai/js/lib/modernizr.min.js"></script>
</head> </head>
<body> <body>
<div id="selection-rect"></div>
<nav class="clearfix"> <nav class="clearfix">
<ul> <ul>
<li id="viewicons" class="view hideOnNoJs"> <li id="viewicons" class="view hideOnNoJs">
@@ -21,6 +22,9 @@
<li id="viewdetails" class="view hideOnNoJs" > <li id="viewdetails" class="view hideOnNoJs" >
<a href="#"><img src="/h5ai/images/view-details.png" alt="view-details" /><span class="l10n-details">details</span></a> <a href="#"><img src="/h5ai/images/view-details.png" alt="view-details" /><span class="l10n-details">details</span></a>
</li> </li>
<li id="download" class="hideOnNoJs">
<a href="#"><img src="/h5ai/images/download.png" alt="download" /><span class="l10n-download">download</span></a>
</li>
</ul> </ul>
</nav> </nav>
<section id="content"> <section id="content">

View File

@@ -14,6 +14,7 @@
<script src="/h5ai/js/lib/modernizr.min.js"></script> <script src="/h5ai/js/lib/modernizr.min.js"></script>
</head> </head>
<body> <body>
<div id="selection-rect"></div>
<nav class="clearfix"> <nav class="clearfix">
<ul> <ul>
<?php echo $crumb->toHtml(); ?> <?php echo $crumb->toHtml(); ?>
@@ -23,6 +24,9 @@
<li id="viewdetails" class="view hideOnNoJs" > <li id="viewdetails" class="view hideOnNoJs" >
<a href="#"><img src="/h5ai/images/view-details.png" alt="view-details" /><span class="l10n-details">details</span></a> <a href="#"><img src="/h5ai/images/view-details.png" alt="view-details" /><span class="l10n-details">details</span></a>
</li> </li>
<li id="download" class="hideOnNoJs">
<a href="#"><img src="/h5ai/images/download.png" alt="download" /><span class="l10n-download">download</span></a>
</li>
</ul> </ul>
</nav> </nav>
<?php echo $tree->toHtml(); ?> <?php echo $tree->toHtml(); ?>
@@ -45,7 +49,7 @@
<span class="center"> <span class="center">
<span class="status default"> <span class="status default">
<?php echo $extended->getFolderCount(); ?> <span class="l10n-folders">folders</span> <?php echo $extended->getFolderCount(); ?> <span class="l10n-folders">folders</span>
· <span class='sep'>·</span>
<?php echo $extended->getFileCount(); ?> <span class="l10n-files">files</span> <?php echo $extended->getFileCount(); ?> <span class="l10n-files">files</span>
</span> </span>
<span class="status dynamic"> <span class="status dynamic">

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

View File

@@ -1,129 +1,89 @@
var Extended = function (pathCache, h5ai) { var Extended = function (pathCache, h5ai) {
"use strict";
/*global $*/
var settings = {
/*******************************
* config
*******************************/
this.config = {
customHeader: "h5ai.header.html", customHeader: "h5ai.header.html",
customFooter: "h5ai.footer.html" customFooter: "h5ai.footer.html"
}; },
initTitle = function () {
/*******************************
* init
*******************************/
this.init = function () {
try {
document.title = decodeURI( document.domain + document.location.pathname );
} catch ( err ) {
document.title = document.domain + document.location.pathname; document.title = document.domain + document.location.pathname;
}; try {
document.title = decodeURI(document.title);
} catch (err) {}
},
initBreadcrumb = function () {
this.initBreadcrumb(); var idx, part,
this.initExtendedView(); $ul = $("body > nav ul"),
this.customize(); pathname = "/",
this.initCounts(); path = pathCache.getPath(pathname),
}; pathnameParts = document.location.pathname.split("/");
/*******************************
* breadcrumb
*******************************/
this.initBreadcrumb = function () {
var $ul = $( "body > nav ul" );
var pathname = "/";
var path = pathCache.getPathForFolder( pathname );
$ul.append(path.updateCrumbHtml()); $ul.append(path.updateCrumbHtml());
var pathnameParts = document.location.pathname.split( "/" );
for (idx in pathnameParts) { for (idx in pathnameParts) {
var part = pathnameParts[idx]; part = pathnameParts[idx];
if (part !== "") { if (part !== "") {
pathname += part + "/"; pathname += part + "/";
var path = pathCache.getPathForFolder( pathname ); $ul.append(pathCache.getPath(pathname).updateCrumbHtml());
$ul.append( path.updateCrumbHtml() ); }
}; }
}; },
}; initExtendedView = function () {
var $ths = $("#table th"),
$label = $ths.eq(1).find("a"),
$date = $ths.eq(2).find("a"),
$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
},
$icon, $ul, $li;
$ul = $("<ul/>");
/******************************* $li = $("<li class='header' />")
* extended view .appendTo($ul)
*******************************/ .append($("<a class='icon'></a>"))
.append($("<a class='label' href='" + $label.attr("href") + "'><span class='l10n-name'>" + $label.text() + "</span></a>"))
this.initExtendedView = function () { .append($("<a class='date' href='" + $date.attr("href") + "'><span class='l10n-lastModified'>" + $date.text() + "</span></a>"))
.append($("<a class='size' href='" + $size.attr("href") + "'><span class='l10n-size'>" + $size.text() + "</span></a>"));
var $ul = $( "<ul/>" );
// headers
var $ths = $( "#table th" );
var $label = $ths.eq( 1 ).find( "a" );
var $date = $ths.eq( 2 ).find( "a" );
var $size = $ths.eq( 3 ).find( "a" );
var $li = $( "<li class='header' />" ).appendTo( $ul );
$( "<a class='icon'></a>" ).appendTo( $li );
$( "<a class='label' href='" + $label.attr( "href" ) + "'><span class='l10n-name'>" + $label.text() + "</span></a>" ).appendTo( $li );
$( "<a class='date' href='" + $date.attr( "href" ) + "'><span class='l10n-lastModified'>" + $date.text() + "</span></a>" ).appendTo( $li );
$( "<a class='size' href='" + $size.attr( "href" ) + "'><span class='l10n-size'>" + $size.text() + "</span></a>" ).appendTo( $li );
// header sort icons // header sort icons
var sortquery = document.location.search;
var order = {
column: ( sortquery.indexOf( "C=N" ) >= 0 ) ? "name" : ( sortquery.indexOf( "C=M" ) >= 0 ) ? "date" : ( sortquery.indexOf( "C=S" ) >= 0 ) ? "size" : h5ai.config.sortorder.column,
ascending: ( sortquery.indexOf( "O=A" ) >= 0 ) ? true : ( sortquery.indexOf( "O=D" ) >= 0 ) ? false : h5ai.config.sortorder.ascending
};
var $icon;
if (order.ascending) { if (order.ascending) {
$icon = $("<img src='/h5ai/images/ascending.png' class='sort' alt='ascending' />"); $icon = $("<img src='/h5ai/images/ascending.png' class='sort' alt='ascending' />");
} else { } else {
$icon = $("<img src='/h5ai/images/descending.png' class='sort' alt='descending' />"); $icon = $("<img src='/h5ai/images/descending.png' class='sort' alt='descending' />");
}; }
if (order.column === "date") { if (order.column === "date") {
$li.find("a.date").prepend($icon); $li.find("a.date").prepend($icon);
} else if (order.column === "size") { } else if (order.column === "size") {
$li.find("a.size").prepend($icon); $li.find("a.size").prepend($icon);
} else { } else {
$li.find("a.label").append($icon); $li.find("a.label").append($icon);
}; }
// entries // entries
$("#table td").closest("tr").each(function () { $("#table td").closest("tr").each(function () {
var path = pathCache.getPathForTableRow( document.location.pathname, this ); var path = pathCache.getPath(document.location.pathname, this);
$ul.append(path.updateExtendedHtml()); $ul.append(path.updateExtendedHtml());
}); });
$("#extended").append($ul); $("#extended").append($ul);
$.log( document.location.pathname, "folders:", $( "#extended .folder" ).size() , "files:", $( "#extended .file" ).size() );
// empty // empty
if ($ul.children(".entry:not(.parentfolder)").size() === 0) { if ($ul.children(".entry:not(.parentfolder)").size() === 0) {
$("#extended").append($("<div class='empty l10n-empty'>empty</div>")); $("#extended").append($("<div class='empty l10n-empty'>empty</div>"));
}; }
},
// in case of floats customize = function () {
$( "#extended" ).addClass( "clearfix" );
};
/*******************************
* customize
*******************************/
this.customize = function () {
$.ajax({ $.ajax({
url: this.config.customHeader, url: settings.customHeader,
dataType: "html", dataType: "html",
success: function (data) { success: function (data) {
$("#content > header").append($(data)).show(); $("#content > header").append($(data)).show();
@@ -131,23 +91,29 @@ var Extended = function ( pathCache, h5ai ) {
}); });
$.ajax({ $.ajax({
url: this.config.customFooter, url: settings.customFooter,
dataType: "html", dataType: "html",
success: function (data) { success: function (data) {
$("#content > footer").prepend($(data)).show(); $("#content > footer").prepend($(data)).show();
} }
}); });
}; },
initCounts = function () {
/*******************************
* init counts
*******************************/
this.initCounts = function () {
$(".folderCount").text($("#extended .entry.folder:not(.parentfolder)").size()); $(".folderCount").text($("#extended .entry.folder:not(.parentfolder)").size());
$(".fileCount").text($("#extended .entry.file").size()); $(".fileCount").text($("#extended .entry.file").size());
},
init = function () {
initTitle();
initBreadcrumb();
initExtendedView();
customize();
initCounts();
},
extended = {
init: init
}; };
return extended;
}; };

View File

@@ -1,10 +1,7 @@
var H5ai = function (options, langs) { var H5ai = function (options, langs) {
"use strict";
/*global $, window, localStorage*/
/*******************************
* config
*******************************/
var defaults = { var defaults = {
store: { store: {
@@ -22,90 +19,57 @@ var H5ai = function ( options, langs ) {
}, },
showTree: true, showTree: true,
slideTree: true, slideTree: true,
folderStatus: { folderStatus: {},
},
lang: null, lang: null,
useBrowserLang: true, useBrowserLang: true,
setParentFolderLabels: true, setParentFolderLabels: true,
linkHoverStates: true linkHoverStates: true,
};
this.config = $.extend( {}, defaults, options );
dateFormat: "Y-m-d H:i",
ignore: ["h5ai", "h5ai.header.html", "h5ai.footer.html"],
ignoreRE: ["/^\\./"],
showThumbs: true,
zippedDownload: true
/******************************* },
* public api settings = $.extend({}, defaults, options),
*******************************/ pathClick = function (fn) {
this.pathClick = function ( fn ) {
if ($.isFunction(fn)) { if ($.isFunction(fn)) {
this.config.callbacks.pathClick.push( fn ); settings.callbacks.pathClick.push(fn);
}; }
return this; },
}; triggerPathClick = function (path, context) {
var i, l, a = settings.callbacks.pathClick;
for (i = 0, l = a.length; i < l; i++) {
a[i].call(window, path, context);
}
},
getViewmode = function () {
/******************************* var viewmode = localStorage.getItem(settings.store.viewmode);
* init
*******************************/
this.init = function () { return $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0];
},
applyViewmode = function (viewmode) {
this.applyViewmode(); if (viewmode) {
this.initTopSpace(); localStorage.setItem(settings.store.viewmode, viewmode);
this.initViews(); }
this.initTree(); viewmode = getViewmode();
this.linkHoverStates();
this.initLangSelector( langs );
this.localize( langs, this.config.lang, this.config.useBrowserLang );
this.initIndicators();
};
/*******************************
* callback triggers
*******************************/
this.triggerPathClick = function ( path, context ) {
for ( idx in this.config.callbacks.pathClick ) {
this.config.callbacks.pathClick[idx].call( window, path, context );
};
};
/*******************************
* local stored viewmode
*******************************/
this.getViewmode = function () {
var viewmode = localStorage.getItem( this.config.store.viewmode );
return $.inArray( viewmode, this.config.viewmodes ) >= 0 ? viewmode : this.config.viewmodes[0];
};
this.applyViewmode = function ( viewmode ) {
if ( viewmode !== undefined ) {
localStorage.setItem( this.config.store.viewmode, viewmode );
};
viewmode = this.getViewmode();
$("#viewdetails,#viewicons").hide().removeClass("current"); $("#viewdetails,#viewicons").hide().removeClass("current");
if ( this.config.viewmodes.length > 1 ) { if (settings.viewmodes.length > 1) {
if ( $.inArray( "details", this.config.viewmodes ) >= 0 ) { if ($.inArray("details", settings.viewmodes) >= 0) {
$("#viewdetails").show(); $("#viewdetails").show();
}; }
if ( $.inArray( "icons", this.config.viewmodes ) >= 0 ) { if ($.inArray("icons", settings.viewmodes) >= 0) {
$("#viewicons").show(); $("#viewicons").show();
}; }
}; }
if (viewmode === "details") { if (viewmode === "details") {
$("#viewdetails").closest("li").addClass("current"); $("#viewdetails").closest("li").addClass("current");
@@ -115,184 +79,171 @@ var H5ai = function ( options, langs ) {
$("#extended").removeClass("details-view").addClass("icons-view").show(); $("#extended").removeClass("details-view").addClass("icons-view").show();
} else { } else {
$("#extended").hide(); $("#extended").hide();
}; }
}; },
initTopSpace = function () {
var adjustTopSpace = function () {
var winHeight = $(window).height(),
navHeight = $("body > nav").outerHeight(),
footerHeight = $("body > footer").outerHeight(),
contentSpacing = 50,
treeSpacing = 50;
/******************************* $("body").css({
* top space, depending on nav height "margin-top": navHeight + contentSpacing,
*******************************/ "margin-bottom": footerHeight + contentSpacing
});
this.initTopSpace = function () { $("#tree").css({
top: navHeight + treeSpacing,
height: winHeight - navHeight - footerHeight - 36 - 2 * treeSpacing
});
function adjustTopSpace() {
var winHeight = $( window ).height();
var navHeight = $( "body > nav" ).outerHeight();
var footerHeight = $( "body > footer" ).outerHeight();
var contentSpacing = 50;
var treeSpacing = 50;
$( "body" )
.css( "margin-top", "" + ( navHeight + contentSpacing ) + "px" )
.css( "margin-bottom", "" + ( footerHeight + contentSpacing ) + "px" );
$( "#tree" )
.css( "top", "" + ( navHeight + treeSpacing ) + "px" )
.css( "height", "" + ( winHeight - navHeight - footerHeight - 36 - 2 * treeSpacing ) + "px" );
try { try {
$("#tree").get(0).updateScrollbar(); $("#tree").get(0).updateScrollbar();
} catch ( err ) {}; } catch (err) {}
}; };
$(window).resize(function () { $(window).resize(function () {
adjustTopSpace(); adjustTopSpace();
}); });
adjustTopSpace(); adjustTopSpace();
}; },
initViews = function () {
/*******************************
* init views
*******************************/
this.initViews = function () {
$("#table").remove(); $("#table").remove();
$("#viewdetails").closest("li") $("#viewdetails").closest("li")
.click( $.proxy( function () { .click(function () { applyViewmode("details"); });
this.applyViewmode( "details" );
}, this ) );
$("#viewicons").closest("li") $("#viewicons").closest("li")
.click( $.proxy( function () { .click(function () { applyViewmode("icons"); });
this.applyViewmode( "icons" );
}, this ) );
$( "#extended .entry" ).hover( // status update
$("#extended .entry a").hover(
function () { function () {
if ($("#extended").hasClass("icons-view")) { if ($("#extended").hasClass("icons-view")) {
$this = $( this ); var $this = $(this);
$(".status.default").hide(); $(".status.default").hide();
$(".status.dynamic") $(".status.dynamic")
.empty() .empty()
.append($this.find(".label").clone()) .append($this.find(".label").clone())
.append( " · " ) .append($("<span class='sep'>·</span>"))
.append($this.find(".date").clone()) .append($this.find(".date").clone())
.show(); .show();
if ( ! $this.hasClass( "folder" ) ) { if (!$this.closest(".entry").hasClass("folder")) {
$(".status.dynamic") $(".status.dynamic")
.append( " · " ) .append($("<span class='sep'>·</span>"))
.append($this.find(".size").clone()); .append($this.find(".size").clone());
} }
}; }
}, },
function () { function () {
$(".status.default").show(); $(".status.default").show();
$( ".status.dynamic" ) $(".status.dynamic").empty().hide();
.empty()
.hide();
} }
); );
}; },
shiftTree = function (forceVisible, dontAnimate) {
var $tree = $("#tree"),
$extended = $("#extended");
if (settings.slideTree && $tree.outerWidth() < $extended.offset().left || forceVisible) {
/******************************* if (dontAnimate) {
* init tree
*******************************/
this.shiftTree = function ( forceVisible, dontAnimate ) {
var $tree = $( "#tree" );
var $extended = $( "#extended" );
if ( this.config.slideTree && $tree.outerWidth() < $extended.offset().left || forceVisible === true ) {
if ( dontAnimate === true ) {
$tree.stop().css({ left: 0 }); $tree.stop().css({ left: 0 });
} else { } else {
$tree.stop().animate({ left: 0 }); $tree.stop().animate({ left: 0 });
}; }
} else { } else {
if ( dontAnimate === true ) { if (dontAnimate) {
$tree.stop().css({ left: 18 - $tree.outerWidth() }); $tree.stop().css({ left: 18 - $tree.outerWidth() });
} else { } else {
$tree.stop().animate({ left: 18 - $tree.outerWidth() }); $tree.stop().animate({ left: 18 - $tree.outerWidth() });
}; }
}; }
}; },
initTree = function () {
this.initTree = function () {
$("#tree").hover( $("#tree").hover(
$.proxy( function () { this.shiftTree( true ); }, this ), function () { shiftTree(true); },
$.proxy( function () { this.shiftTree(); }, this ) function () { shiftTree(); }
); );
$( window ).resize( $.proxy( function () { this.shiftTree(); }, this ) ); $(window).resize(function () { shiftTree(); });
this.shiftTree( false, true ); shiftTree(false, true);
}; },
linkHoverStates = function () {
/*******************************
* link hover states
*******************************/
this.linkHoverStates = function () {
if ( !this.config.linkHoverStates ) {
return;
};
if (settings.linkHoverStates) {
$("a[href^='/']:not(.linkedHoverStates)").each(function () { $("a[href^='/']:not(.linkedHoverStates)").each(function () {
var $a = $( this ).addClass( "linkedHoverStates" ); var $a = $(this).addClass("linkedHoverStates"),
var href = $a.attr( "href" ); href = $a.attr("href");
$a.hover( $a.hover(
function () { function () { $("a[href='" + href + "']").addClass("hover"); },
$( "a[href='" + href + "']" ).addClass( "hover" ); function () { $("a[href='" + href + "']").removeClass("hover"); }
},
function () {
$( "a[href='" + href + "']" ).removeClass( "hover" );
}
); );
}); });
}; }
},
localize = function (langs, lang, useBrowserLang) {
var storedLang = localStorage.getItem(settings.store.lang),
browserLang, selected, key;
if (langs[storedLang]) {
lang = storedLang;
} else if (useBrowserLang) {
browserLang = navigator.language;
if (langs[browserLang]) {
lang = browserLang;
} else if (browserLang.length > 2 && langs[browserLang.substr(0, 2)]) {
lang = browserLang.substr(0, 2);
}
}
/******************************* if (!langs[lang]) {
* localization lang = "en";
*******************************/ }
this.initLangSelector = function ( langs ) { selected = langs[lang];
if (selected) {
for (key in selected) {
$(".l10n-" + key).text(selected[key]);
}
$(".lang").text(lang);
$(".langOption").removeClass("current");
$(".langOption." + lang).addClass("current");
}
},
initLangSelector = function (langs) {
var idx, lang,
sortedLangsKeys = [],
$ul;
var sortedLangsKeys = [];
for (lang in langs) { for (lang in langs) {
sortedLangsKeys.push(lang); sortedLangsKeys.push(lang);
}; }
sortedLangsKeys.sort(); sortedLangsKeys.sort();
var THIS = this; $ul = $("<ul />");
var $ul = $( "<ul />" );
for (idx in sortedLangsKeys) { for (idx in sortedLangsKeys) {
(function (lang) { (function (lang) {
$("<li class='langOption' />") $("<li class='langOption' />")
.addClass(lang) .addClass(lang)
.text( lang + " - " + langs[lang]["lang"] ) .text(lang + " - " + langs[lang].lang)
.appendTo($ul) .appendTo($ul)
.click(function () { .click(function () {
localStorage.setItem( THIS.config.store.lang, lang ); localStorage.setItem(settings.store.lang, lang);
THIS.localize( langs, lang, false ); localize(langs, lang, false);
}); });
})(sortedLangsKeys[idx]); })(sortedLangsKeys[idx]);
}; }
$( "#langSelector .langOptions" ) $("#langSelector .langOptions").append($ul);
.append( $ul );
$("#langSelector").hover( $("#langSelector").hover(
function () { function () {
var $ele = $(".langOptions"); var $ele = $(".langOptions");
@@ -302,51 +253,18 @@ var H5ai = function ( options, langs ) {
$(".langOptions").stop(true, true).fadeOut(); $(".langOptions").stop(true, true).fadeOut();
} }
); );
}; },
initIndicators = function () {
this.localize = function ( langs, lang, useBrowserLang ) {
if ( useBrowserLang === true ) {
var browserLang = navigator.language;
if ( langs[ browserLang ] !== undefined ) {
lang = browserLang;
} else if ( browserLang.length > 2 && langs[ browserLang.substr( 0, 2 ) ] !== undefined ) {
lang = browserLang.substr( 0, 2 );
};
};
if ( langs[ lang ] === undefined ) {
lang = "en";
};
var storedLang = localStorage.getItem( this.config.store.lang );
if ( langs[ storedLang ] !== undefined ) {
lang = storedLang;
};
var selected = langs[ lang ];
for ( key in selected ) {
$( ".l10n-" + key ).text( selected[key] );
};
$( ".lang" ).text( lang );
$( ".langOption" ).removeClass( "current" );
$( ".langOption." + lang ).addClass( "current" );
};
/*******************************
* initiate tree indicators
*******************************/
this.initIndicators = function () {
var THIS = this;
$("#tree .entry.folder:not(.initiatedIndicator)").each(function () { $("#tree .entry.folder:not(.initiatedIndicator)").each(function () {
var $entry = $( this ).addClass( "initiatedIndicator" ); var $entry = $(this).addClass("initiatedIndicator"),
var $indicator = $entry.find( "> .indicator" ); $indicator = $entry.find("> .indicator");
$indicator.click(function (event) { $indicator.click(function (event) {
var $content;
if ($indicator.hasClass("unknown")) { if ($indicator.hasClass("unknown")) {
$.get("/h5ai/php/treecontent.php", { "href": $entry.find("> a").attr("href") }, function (html) { $.get("/h5ai/php/treecontent.php", { "href": $entry.find("> a").attr("href") }, function (html) {
$content = $(html); $content = $(html);
@@ -357,8 +275,8 @@ var H5ai = function ( options, langs ) {
$indicator.addClass("open"); $indicator.addClass("open");
$entry.find("> .content").replaceWith($content); $entry.find("> .content").replaceWith($content);
$("#tree").get(0).updateScrollbar(); $("#tree").get(0).updateScrollbar();
THIS.initIndicators(); initIndicators();
}; }
}); });
} else if ($indicator.hasClass("open")) { } else if ($indicator.hasClass("open")) {
$indicator.removeClass("open"); $indicator.removeClass("open");
@@ -372,8 +290,106 @@ var H5ai = function ( options, langs ) {
$entry.find("> .content").slideDown(function () { $entry.find("> .content").slideDown(function () {
$("#tree").get(0).updateScrollbar(); $("#tree").get(0).updateScrollbar();
}); });
}; }
}); });
}); });
},
initZippedDownload = function () {
var x = 0,
y = 0,
$window = $(window),
selected = function (hrefs) {
var query, idx;
for (idx in hrefs) {
query = query ? query + ":" + hrefs[idx] : hrefs[idx];
}
query = "/h5ai/php/zipcontent.php?hrefs=" + query;
$("#download").show().find("a").attr("href", query);
},
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),
sel;
event.preventDefault();
$("#selection-rect").css({left: l, top: t, width: w, height: h});
sel = $("#selection-rect").fracs("rect");
$("#extended a").removeClass("selected").each(function () {
var $a = $(this),
rect = $a.fracs("rect"),
inter = sel.intersection(rect);
if (inter && !$a.closest(".entry").hasClass("folder-parent")) {
$a.addClass("selected");
}
});
},
selectionEnd = function (event) {
event.preventDefault();
$("#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);
}
},
selectionStart = function (event) {
event.preventDefault();
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});
$window
.bind("mousemove", selectionUpdate)
.one("mouseup", selectionEnd);
},
noSelection = function (event) {
event.stopPropagation();
return false;
}; };
if (settings.zippedDownload) {
$("body>nav,body>footer,#tree,#extended a").bind("mousedown", noSelection);
$("#extended a").live("mousedown", noSelection);
$window.bind("mousedown", selectionStart);
}
},
init = function () {
applyViewmode();
initTopSpace();
initViews();
initTree();
linkHoverStates();
initLangSelector(langs);
localize(langs, settings.lang, settings.useBrowserLang);
initIndicators();
initZippedDownload();
},
h5ai = {
settings: settings,
shiftTree: shiftTree,
linkHoverStates: linkHoverStates,
pathClick: pathClick,
triggerPathClick: triggerPathClick,
init: init
};
return h5ai;
}; };

View File

@@ -0,0 +1,871 @@
/*
* jQuery.fracs 0.10
* http://larsjung.de/fracs
*
* provided under the terms of the MIT License
*/
/*
* ModPlug 0.4
* http://larsjung.de/modplug
*
* provided under the terms of the MIT License
*/
(function ($) {
"use strict";
/*globals jQuery */
/*jslint confusion: true */
var reference = "_mp_api";
$.ModPlug = $.ModPlug || {
plugin: function (namespace, options) {
if (!namespace || $[namespace] || $.fn[namespace]) {
// $.error("No namespace specified, or a plugin already exists on 'jQuery." + namespace + "'");
return !namespace ? 1 : ($[namespace] ? 2 : 3);
}
var defaults = {
statics: {},
methods: {},
defaultStatic: undefined,
defaultMethod: undefined
},
settings = $.extend({}, defaults, options),
staticPlug = function () {
var args, defaultMethod;
args = Array.prototype.slice.call(arguments);
defaultMethod = settings.defaultStatic instanceof Function ? settings.defaultStatic.apply(this, args) : settings.defaultStatic;
if (staticPlug[defaultMethod] instanceof Function) {
return staticPlug[defaultMethod].apply(this, args);
}
$.error("Static method defaulted to '" + defaultMethod + "' does not exist on 'jQuery." + namespace + "'");
},
methods = {},
methodPlug = function (method) {
var args, defaultMethod;
if (methods[method] instanceof Function) {
args = Array.prototype.slice.call(arguments, 1);
return methods[method].apply(this, args);
}
args = Array.prototype.slice.call(arguments);
defaultMethod = settings.defaultMethod instanceof Function ? settings.defaultMethod.apply(this, args) : settings.defaultMethod;
if (methods[defaultMethod] instanceof Function) {
return methods[defaultMethod].apply(this, args);
}
$.error("Method '" + method + "' defaulted to '" + defaultMethod + "' does not exist on 'jQuery." + namespace + "'");
},
api = {
addStatics: function (newStatics) {
$.extend(staticPlug, newStatics);
staticPlug[reference] = api;
return this;
},
addMethods: function (newMethods) {
$.extend(methods, newMethods);
return this;
}
};
api.addStatics(settings.statics).addMethods(settings.methods);
$[namespace] = staticPlug;
$.fn[namespace] = methodPlug;
return 0;
},
module: function (namespace, options) {
if (!$[namespace] || !$[namespace][reference]) {
// $.error("No ModPlug plugin exists on 'jQuery." + namespace + "'");
return !$[namespace] ? 1 : 2;
}
var defaults = {
statics: {},
methods: {}
},
settings = $.extend({}, defaults, options);
$[namespace][reference].addStatics(settings.statics).addMethods(settings.methods);
return 0;
}
};
}(jQuery));
/*
* jQuery.fracs - Core API
*/
(function ($) {
"use strict";
/*globals jQuery, HTMLElement */
/*jslint browser: true, vars: true */
var FracsData = function (htmlElementOrRect) {
var target = htmlElementOrRect,
callbacks = [],
prevFracs;
this.size = function () {
return callbacks.length;
};
this.bind = function (callback) {
if (callback instanceof Function && $.inArray(callback, callbacks) === -1) {
callbacks.push(callback);
}
};
this.unbind = function (callback) {
if (callback instanceof Function) {
var idx = $.inArray(callback, callbacks);
if (idx >= 0) {
callbacks.splice(idx, 1);
}
} else {
callbacks = [];
}
};
this.check = function () {
var rect = target instanceof HTMLElement ? $.fracs.rect(target) : target,
fracs = $.fracs.fracs(rect, $.fracs.viewport());
if (!prevFracs || !prevFracs.equals(fracs)) {
$.each(callbacks, function (idx, callback) {
callback.call(target, fracs, prevFracs);
});
prevFracs = fracs;
}
};
};
var Rect = function (left, top, width, height) {
var fracsData;
this.left = Math.round(left);
this.top = Math.round(top);
this.width = Math.round(width);
this.height = Math.round(height);
this.right = this.left + this.width;
this.bottom = this.top + this.height;
this.equals = function (that) {
return this.left === that.left && this.top === that.top && this.width === that.width && this.height === that.height;
};
this.area = function () {
return this.width * this.height;
};
this.intersection = function (rect) {
var left = Math.max(this.left, rect.left),
right = Math.min(this.right, rect.right),
top = Math.max(this.top, rect.top),
bottom = Math.min(this.bottom, rect.bottom),
width = right - left,
height = bottom - top;
return (width >= 0 && height >= 0) ? new Rect(left, top, width, height) : undefined;
};
this.envelope = function (rect) {
var left = Math.min(this.left, rect.left),
right = Math.max(this.right, rect.right),
top = Math.min(this.top, rect.top),
bottom = Math.max(this.bottom, rect.bottom),
width = right - left,
height = bottom - top;
return new Rect(left, top, width, height);
};
this.bind = function (callback) {
if (!fracsData) {
fracsData = new FracsData(this);
$(window).bind("scroll resize", fracsData.check);
}
fracsData.bind(callback);
};
this.unbind = function (callback) {
if (fracsData) {
fracsData.unbind(callback);
if (fracsData.size() === 0) {
$(window).unbind("scroll resize", fracsData.check);
fracsData = undefined;
}
}
};
this.check = function () {
if (fracsData) {
fracsData.check();
}
};
this.fracs = function () {
$.fracs.fracs(this);
};
};
var FracsResult = function (rectDocument, rectElement, rectViewport, visible, viewport, possible) {
/*jslint confusion: true */
if (!rectDocument || !rectElement || !rectViewport || !visible || !viewport || !possible) {
this.rects = undefined;
this.visible = 0;
this.viewport = 0;
this.possible = 0;
} else {
this.rects = {
document: rectDocument,
element: rectElement,
viewport: rectViewport
};
this.visible = visible;
this.viewport = viewport;
this.possible = possible;
}
this.equals = function (that) {
return this.fracsEqual(that) && this.rectsEqual(that);
};
this.fracsEqual = function (that) {
return this.visible === that.visible && this.viewport === that.viewport && this.possible === that.possible;
};
this.rectsEqual = function (that) {
if (!this.rects || !that.rects) {
return this.rects === that.rects;
}
return this.rects.document.equals(that.rects.document)
&& this.rects.element.equals(that.rects.element)
&& this.rects.viewport.equals(that.rects.viewport);
};
};
var ScrollState = function () {
var document = $.fracs.document(),
viewport = $.fracs.viewport(),
width = document.width - viewport.width,
height = document.height - viewport.height;
this.width = width <= 0 ? undefined : viewport.left / width;
this.height = height <= 0 ? undefined : viewport.top / height;
this.left = viewport.left;
this.top = viewport.top;
this.right = document.right - viewport.right;
this.bottom = document.bottom - viewport.bottom;
this.equals = function (that) {
return this.width === that.width && this.height === that.height
&& this.left === that.left && this.top === that.top
&& this.right === that.right && this.bottom === that.bottom;
};
};
var ScrollStateTracker = function () {
var prevState,
callbacks = [],
check = function () {
var state = new ScrollState();
if (!prevState || !prevState.equals(state)) {
$.each(callbacks, function (idx, callback) {
callback.call(window, state, prevState);
});
prevState = state;
}
};
$(window).bind("resize scroll load", check);
this.bind = function (callback) {
callbacks.push(callback);
};
};
// @beta
var FracsElement = function (htmlElement, fracs) {
this.element = htmlElement;
this.fracs = fracs;
this.update = function () {
var fracs = $.fracs.fracs(this.element),
changed = !this.fracs || !this.fracs.equals(fracs);
this.fracs = fracs;
return changed;
};
};
// @beta
var FracsGroup = function (htmlElements, property, callback) {
var THIS = this,
targets = [],
prevBest = null;
$.each(htmlElements, function (idx, element) {
if (element instanceof HTMLElement) {
targets.push(new FracsElement(element));
}
});
this.check = function () {
var best,
viewport = $.fracs.viewport();
$.each(targets, function (idx, target) {
target.update();
if (!best || target.fracs[property] > best.fracs[property]) {
best = target;
}
});
if (best && best.fracs[property] === 0) {
best = null;
}
if (prevBest !== best) {
callback.call(THIS, best, prevBest);
prevBest = best;
}
};
};
var $document = $(document),
$window = $(window),
$htmlBody = $("html,body"),
scrollStateTracker,
dataNs = "fracs",
statics = {
document: function () {
/*jslint confusion: true */
return new Rect(0, 0, $document.width(), $document.height());
},
viewport: function () {
/*jslint confusion: true */
return new Rect($window.scrollLeft(), $window.scrollTop(), $window.width(), $window.height());
},
rect: function (htmlElement) {
var $target = $(htmlElement),
offset = $target.offset();
if (!$target.is(":visible")) {
return new Rect(0, 0, 0, 0);
}
return new Rect(offset.left, offset.top, $target.outerWidth(), $target.outerHeight());
},
fracs: function (rect, viewport) {
var intersection, intersectionElementSpace, intersectionViewportSpace, intersectionArea, possibleArea;
rect = rect instanceof HTMLElement ? statics.rect(rect) : rect;
viewport = viewport || statics.viewport();
intersection = rect.intersection(viewport);
if (!intersection) {
return new FracsResult();
}
intersectionElementSpace = new Rect(intersection.left - rect.left, intersection.top - rect.top, intersection.width, intersection.height);
intersectionViewportSpace = new Rect(intersection.left - viewport.left, intersection.top - viewport.top, intersection.width, intersection.height);
intersectionArea = intersection.area();
possibleArea = Math.min(rect.width, viewport.width) * Math.min(rect.height, viewport.height);
return new FracsResult(
intersection,
intersectionElementSpace,
intersectionViewportSpace,
intersectionArea / rect.area(),
intersectionArea / viewport.area(),
intersectionArea / possibleArea
);
},
round: function (value, decs) {
if (isNaN(decs) || decs <= 0) {
return Math.round(value);
}
return Math.round(value * Math.pow(10, decs)) / Math.pow(10, decs);
},
scrollTo: function (left, top, duration) {
duration = isNaN(duration) ? 1000 : duration;
$htmlBody.stop(true).animate({ scrollLeft: left, scrollTop: top }, duration);
},
scroll: function (left, top, duration) {
duration = isNaN(duration) ? 1000 : duration;
$htmlBody.stop(true).animate({ scrollLeft: $window.scrollLeft() + left, scrollTop: $window.scrollTop() + top }, duration);
},
scrollState: function (callback) {
if (callback instanceof Function) {
scrollStateTracker = scrollStateTracker || new ScrollStateTracker();
scrollStateTracker.bind(callback);
} else {
return new ScrollState();
}
}
},
methods = {
bind: function (callback) {
return this.each(function () {
var $this = $(this),
data = $this.data(dataNs);
if (!data) {
data = new FracsData(this);
$this.data(dataNs, data);
$window.bind("scroll resize", data.check);
}
data.bind(callback);
});
},
unbind: function (callback) {
return this.each(function () {
var $this = $(this),
data = $this.data(dataNs);
if (data) {
data.unbind(callback);
if (data.size() === 0) {
$this.removeData(dataNs);
$window.unbind("scroll resize", data.check);
}
}
});
},
check: function () {
return this.each(function () {
var data = $(this).data(dataNs);
if (data) {
data.check();
}
});
},
fracs: function () {
return statics.fracs(statics.rect(this.get(0)), statics.viewport());
},
rect: function () {
return statics.rect(this.get(0));
},
max: function (property, callback) {
if (callback instanceof Function) {
var data = new FracsGroup(this, property, callback);
$window.bind("scroll resize", data.check);
data.check();
return this;
} else {
var obj, elements, maxValue;
if ($.inArray(property, [ "possible", "visible", "viewport" ]) >= 0) {
obj = "fracs";
} else if ($.inArray(property, [ "width", "height", "left", "right", "top", "bottom" ]) >= 0) {
obj = "rect";
} else {
return this;
}
this.each(function () {
var fracs = statics[obj](this);
if (!maxValue || fracs[property] > maxValue) {
elements = [ this ];
maxValue = fracs[property];
} else if (fracs[property] === maxValue) {
elements.push(this);
}
});
return $(elements);
}
},
min: function (property) {
var obj, elements, minValue;
if ($.inArray(property, [ "possible", "visible", "viewport" ]) >= 0) {
obj = "fracs";
} else if ($.inArray(property, [ "width", "height", "left", "right", "top", "bottom" ]) >= 0) {
obj = "rect";
} else {
return this;
}
this.each(function () {
var fracs = statics[obj](this);
if (!minValue || fracs[property] < minValue) {
elements = [ this ];
minValue = fracs[property];
} else if (fracs[property] === minValue) {
elements.push(this);
}
});
return $(elements);
},
envelope: function () {
var envelope, rect;
this.each(function () {
rect = statics.rect(this);
envelope = !envelope ? rect : envelope.envelope(rect);
});
return envelope;
},
scrollTo: function (paddingLeft, paddingTop, duration) {
var rect;
paddingLeft = paddingLeft || 0;
paddingTop = paddingTop || 0;
rect = statics.rect(this.get(0));
statics.scrollTo(rect.left - paddingLeft, rect.top - paddingTop, duration);
return this;
},
softLink: function (paddingLeft, paddingTop, duration) {
return this.filter("a[href^=#]").each(function () {
var $a = $(this),
href = $a.attr("href");
$a.click(function () {
$(href).fracs("scrollTo", paddingLeft, paddingTop, duration);
});
});
}
},
defaultStatic = function () {
return "fracs";
},
defaultMethod = function () {
if (arguments.length === 0) {
return "fracs";
} else if (arguments[0] instanceof Function) {
return "bind";
}
};
$.ModPlug.plugin("fracs", {
statics: statics,
methods: methods,
defaultStatic: defaultStatic,
defaultMethod: defaultMethod
});
}(jQuery));
/*
* jQuery.fracs - Outline API
*/
(function ($) {
"use strict";
/*globals jQuery */
/*jslint browser: true, vars: true */
var Outline = function (canvas, options) {
if (!(canvas instanceof HTMLElement && canvas.nodeName.toLowerCase() === "canvas")) {
return undefined;
}
var defaults = {
crop: false,
duration: 0,
focusWidth: 0.5,
focusHeight: 0.5,
autoFocus: true,
styles: [ {
selector: "header,footer,section,article",
fillStyle: "rgb(230,230,230)"
}, {
selector: "h1",
fillStyle: "rgb(240,140,060)"
}, {
selector: "h2",
fillStyle: "rgb(200,100,100)"
}, {
selector: "h3",
fillStyle: "rgb(100,200,100)"
}, {
selector: "h4",
fillStyle: "rgb(100,100,200)"
} ],
viewportStyle: {
fillStyle: "rgba(228,77,38,0.3)"
},
viewportDragStyle: {
fillStyle: "rgba(228,77,38,0.6)"
},
invertViewport: false
},
settings = $.extend({}, defaults, options),
$window = $(window),
$htmlBody = $("html,body"),
$canvas = $(canvas),
width = $canvas.attr("width"),
height = $canvas.attr("height"),
context = canvas.getContext("2d"),
docRect,
vpRect,
scale,
drag = false,
focusWidth,
focusHeight,
scroll = function (event) {
var r, x, y;
r = $canvas.fracs("rect");
x = event.pageX - r.left;
y = event.pageY - r.top;
$.fracs.scrollTo(x / scale - vpRect.width * focusWidth, y / scale - vpRect.height * focusHeight, settings.duration);
},
drawRect = function (context, rect, strokeWidth, strokeStyle, fillStyle, invert) {
if (strokeWidth !== undefined && scale) {
strokeWidth = strokeWidth > 0.2 / scale ? strokeWidth : 0.2 / scale;
}
if (strokeStyle || fillStyle) {
if (invert !== true) {
context.beginPath();
context.rect(rect.left, rect.top, rect.width, rect.height);
if (fillStyle) {
context.fillStyle = fillStyle;
context.fill();
}
if (strokeStyle) {
context.lineWidth = strokeWidth;
context.strokeStyle = strokeStyle;
context.stroke();
}
} else {
if (fillStyle) {
context.beginPath();
context.rect(0, 0, docRect.width, rect.top);
context.rect(0, rect.top, rect.left, rect.height);
context.rect(rect.right, rect.top, docRect.right - rect.right, rect.height);
context.rect(0, rect.bottom, docRect.width, docRect.bottom - rect.bottom);
context.fillStyle = fillStyle;
context.fill();
}
if (strokeStyle) {
context.beginPath();
context.rect(rect.left, rect.top, rect.width, rect.height);
context.lineWidth = strokeWidth;
context.strokeStyle = strokeStyle;
context.stroke();
}
}
}
},
drawElement = function (context, htmlElement, strokeWidth, strokeStyle, fillStyle) {
var $element = $(htmlElement),
rect = $element.fracs("rect");
if ($element.css("visibility") === "hidden") {
return;
}
strokeWidth = strokeWidth === "auto" ? $element.css("border-top-width") : strokeWidth;
strokeStyle = strokeStyle === "auto" ? $element.css("border-top-color") : strokeStyle;
fillStyle = fillStyle === "auto" ? $element.css("background-color") : fillStyle;
drawRect(context, rect, strokeWidth, strokeStyle, fillStyle);
},
drawViewport = function () {
var strokeWidth, strokeStyle, fillStyle;
if (drag && settings.viewportDragStyle) {
strokeWidth = settings.viewportDragStyle.storkeWidth;
strokeStyle = settings.viewportDragStyle.strokeStyle;
fillStyle = settings.viewportDragStyle.fillStyle;
} else {
strokeWidth = settings.viewportStyle.storkeWidth;
strokeStyle = settings.viewportStyle.strokeStyle;
fillStyle = settings.viewportStyle.fillStyle;
}
drawRect(context, vpRect, strokeWidth, strokeStyle, fillStyle, settings.invertViewport);
},
applyStyles = function (context) {
$.each(settings.styles, function (idx, style) {
$(style.selector).each(function () {
drawElement(context, this, style.strokeWidth, style.strokeStyle, style.fillStyle);
});
});
},
draw = function () {
/*jslint confusion: true */
var scaleX, scaleY;
docRect = $.fracs.document();
vpRect = $.fracs.viewport();
scaleX = width / docRect.width;
scaleY = height / docRect.height;
scale = scaleX < scaleY ? scaleX : scaleY;
if (settings.crop) {
$canvas.attr("width", docRect.width * scale).attr("height", docRect.height * scale);
}
context.clearRect(0, 0, $canvas.width(), $canvas.height());
context.scale(scale, scale);
applyStyles(context);
drawViewport();
context.scale(1 / scale, 1 / scale);
},
init = function () {
$canvas
.css("cursor", "pointer")
.mousedown(function (event) {
var r;
event.preventDefault();
drag = true;
if (settings.autoFocus) {
r = $canvas.fracs("rect");
focusWidth = (((event.pageX - r.left) / scale) - vpRect.left) / vpRect.width;
focusHeight = (((event.pageY - r.top) / scale) - vpRect.top) / vpRect.height;
}
if (!settings.autoFocus || focusWidth < 0 || focusWidth > 1 || focusHeight < 0 || focusHeight > 1) {
focusWidth = settings.focusWidth;
focusHeight = settings.focusHeight;
}
scroll(event);
$canvas.css("cursor", "crosshair").addClass("dragOn");
$htmlBody.css("cursor", "crosshair");
$window
.bind("mousemove", scroll)
.one("mouseup", function (event) {
event.preventDefault();
$canvas.css("cursor", "pointer").removeClass("dragOn");
$htmlBody.css("cursor", "auto");
$window.unbind("mousemove", scroll);
drag = false;
draw();
});
});
canvas.onselectstart = function () {
return false;
};
$window.bind("load resize scroll", draw);
draw();
};
init();
this.draw = draw;
};
var dataNs = "outline",
methods = {
outline: function (options) {
return this.each(function () {
var outline;
if (options === "redraw") {
outline = $(this).data(dataNs);
if (outline) {
outline.draw();
}
} else {
outline = new Outline(this, options);
if (outline) {
$(this).data(dataNs, outline);
}
}
});
}
};
$.ModPlug.module("fracs", {
methods: methods
});
}(jQuery));

View File

@@ -1,31 +0,0 @@
// v2.2
(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);

View File

@@ -2,36 +2,40 @@
var init = function (htmlElement) { var init = function (htmlElement) {
var $element = $( htmlElement ); var $element = $(htmlElement),
$scrollbar, $drag, $wrapper, $content, mouseOffsetY, updateId,
update, scroll;
if ( $element.css( "position" ) === undefined || $element.css( "position" ) === "static" ) { if (!$element.css("position") || $element.css("position") === "static") {
$element.css("position", "relative"); $element.css("position", "relative");
}; }
var $scrollbar = $( "<div class='scrollbar' />" ); $scrollbar = $("<div class='scrollbar' />");
var $drag = $( "<div class='drag' />" ).appendTo( $scrollbar ); $drag = $("<div class='drag' />").appendTo($scrollbar);
$element $element
.wrapInner("<div class='wrapper'><div class='content' /></div>") .wrapInner("<div class='wrapper'><div class='content' /></div>")
.append($scrollbar); .append($scrollbar);
var $wrapper = $element.find( "> .wrapper" ); $wrapper = $element.find("> .wrapper");
var $content = $wrapper.find( "> .content" ); $content = $wrapper.find("> .content");
var mouseOffsetY = 0; mouseOffsetY = 0;
var updateId = undefined;
var update = function ( repeat ) { update = function (repeat) {
if ( updateId !== undefined && !repeat ) {
var visibleHeight, contentHeight, scrollTop, scrollTopFrac, visVertFrac;
if (updateId && !repeat) {
clearInterval(updateId); clearInterval(updateId);
updateId = undefined; updateId = undefined;
} else if ( updateId === undefined && repeat ) { } else if (!updateId && repeat) {
updateId = setInterval(function() { update(true); }, 50); updateId = setInterval(function() { update(true); }, 50);
}; }
$wrapper.css("height", $element.height()); $wrapper.css("height", $element.height());
var visibleHeight = $element.height(); visibleHeight = $element.height();
var contentHeight = $content.outerHeight(); contentHeight = $content.outerHeight();
var scrollTop = $wrapper.scrollTop(); scrollTop = $wrapper.scrollTop();
var scrollTopFrac = scrollTop / contentHeight; scrollTopFrac = scrollTop / contentHeight;
var visVertFrac = Math.min( visibleHeight / contentHeight, 1 ); visVertFrac = Math.min(visibleHeight / contentHeight, 1);
if (visVertFrac < 1) { if (visVertFrac < 1) {
$scrollbar $scrollbar
@@ -46,17 +50,21 @@
}); });
} else { } else {
$scrollbar.fadeOut(50); $scrollbar.fadeOut(50);
}
}; };
};
var scroll = function ( event ) { scroll = function (event) {
event.preventDefault();
var clickFrac = (event.pageY - $scrollbar.offset().top - mouseOffsetY) / $scrollbar.height(); var clickFrac = (event.pageY - $scrollbar.offset().top - mouseOffsetY) / $scrollbar.height();
$wrapper.scrollTop($content.outerHeight() * clickFrac); $wrapper.scrollTop($content.outerHeight() * clickFrac);
update(); update();
event.preventDefault();
}; };
$element $element
.mousewheel(function (event, delta) { .mousewheel(function (event, delta) {
$wrapper.scrollTop($wrapper.scrollTop() - 50 * delta); $wrapper.scrollTop($wrapper.scrollTop() - 50 * delta);
update(); update();
event.stopPropagation(); event.stopPropagation();
@@ -79,12 +87,14 @@
cursor: "pointer" cursor: "pointer"
}) })
.mousedown(function (event) { .mousedown(function (event) {
mouseOffsetY = $drag.outerHeight() / 2; mouseOffsetY = $drag.outerHeight() / 2;
scroll(event); scroll(event);
$scrollbar.addClass("dragOn"); $scrollbar.addClass("dragOn");
$(window) $(window)
.bind("mousemove", scroll) .bind("mousemove", scroll)
.one("mouseup", function (event) { .one("mouseup", function (event) {
$scrollbar.removeClass("dragOn"); $scrollbar.removeClass("dragOn");
$(window).unbind("mousemove", scroll); $(window).unbind("mousemove", scroll);
scroll(event); scroll(event);
@@ -93,7 +103,9 @@
event.preventDefault(); event.preventDefault();
}) })
.each(function () { .each(function () {
this.onselectstart = function () { this.onselectstart = function () {
return false; return false;
}; };
}); });
@@ -104,12 +116,14 @@
width: "100%" width: "100%"
}) })
.mousedown(function (event) { .mousedown(function (event) {
mouseOffsetY = event.pageY - $drag.offset().top; mouseOffsetY = event.pageY - $drag.offset().top;
scroll(event); scroll(event);
$scrollbar.addClass("dragOn"); $scrollbar.addClass("dragOn");
$(window) $(window)
.bind("mousemove", scroll) .bind("mousemove", scroll)
.one("mouseup", function (event) { .one("mouseup", function (event) {
$scrollbar.removeClass("dragOn"); $scrollbar.removeClass("dragOn");
$(window).unbind("mousemove", scroll); $(window).unbind("mousemove", scroll);
scroll(event); scroll(event);

View File

@@ -1,4 +1,6 @@
(function ($) { (function ($) {
"use strict";
/*global jQuery, window*/
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ // http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
// modified // modified
@@ -7,18 +9,21 @@
$.log.history.push(arguments); $.log.history.push(arguments);
if (window.console) { if (window.console) {
window.console.log(Array.prototype.slice.call(arguments)); window.console.log(Array.prototype.slice.call(arguments));
}; }
}; };
var Timer = function () { $.timer = (function () {
this.start = new Date().getTime();; var start = $.now(),
this.last = this.start; last = start,
this.log = function ( label ) { timer = {
var now = new Date().getTime(); log: function (label) {
$.log( "timer", label, "+" + (now - this.last), "=" + (now - this.start) ); var now = $.now();
this.last = now; $.log("timer", label, "+" + (now - last), "=" + (now - start));
last = now;
}
}; };
};
$.timer = new Timer(); return timer;
}());
})(jQuery); })(jQuery);

View File

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

View File

@@ -1,149 +1,147 @@
var Tree = function (pathCache, h5ai) { var Tree = function (pathCache, h5ai) {
"use strict";
/*global $*/
var contentTypeRegEx = /^text\/html;h5ai=/,
pathnameStatusCache = {},
fetchStatus = function (pathname, callback) {
this.init = function () { if (h5ai.settings.folderStatus[pathname]) {
callback(h5ai.settings.folderStatus[pathname]);
return;
} else if (pathnameStatusCache[pathname]) {
callback(pathnameStatusCache[pathname]);
return;
}
if ( h5ai.config.showTree ) { $.ajax({
this.updatePaths(); url: pathname,
this.populateTree(); type: "HEAD",
}; complete: function (xhr) {
};
var status = xhr.status;
this.updatePath = function ( path ) { 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) { if (path.isFolder && !path.isParentFolder && path.status === undefined) {
this.fetchStatus( path.absHref, function ( status ) { fetchStatus(path.absHref, function (status) {
if (status !== "h5ai") { if (status !== "h5ai") {
path.status = status; path.status = status;
}; }
path.updateHtml(); path.updateHtml();
h5ai.linkHoverStates(); h5ai.linkHoverStates();
}); });
}; }
}; },
updatePaths = function () {
var ref;
this.updatePaths = function () { for (ref in pathCache.cache) {
updatePath(pathCache.cache[ref]);
}
},
fetchStatusAndContent = function (pathname, includeParent, callback) {
for ( var ref in pathCache.cache ) { fetchStatus(pathname, function (status) {
this.updatePath( pathCache.cache[ref] );
};
};
this.populateTree = function () {
this.fetchTree( document.location.pathname, function( path ) {
$( "#tree" )
.append( path.updateTreeHtml() )
.scrollpanel()
.show();
h5ai.shiftTree( false, true );
h5ai.linkHoverStates();
pathCache.storeCache();
setTimeout( function () {
$( "#tree" ).get( 0 ).updateScrollbar();
}, 1 );
} );
};
this.fetchTree = function ( pathname, callback, childPath ) {
this.fetchPath( pathname, $.proxy( function ( path ) {
path.treeOpen = true;
if ( childPath !== undefined ) {
path.content[ childPath.absHref ] = childPath;
};
var parent = pathCache.splitPathname( pathname )[0];
if ( parent === "" ) {
callback( path );
} else {
this.fetchTree( parent, callback, path );
};
}, this ) );
};
this.fetchPath = function ( pathname, callback ) {
this.fetchStatusAndContent( pathname, false, function ( status, content ) {
var path = pathCache.getPathForFolder( pathname );
path.status = status;
path.content = content;
callback( path );
} );
};
var THIS = this;
var contentTypeRegEx = /^text\/html;h5ai=/;
var pathnameStatusCache = {};
this.fetchStatusAndContent = function ( pathname, includeParent, callback ) {
this.fetchStatus( pathname, function ( status ) {
if (status !== "h5ai") { if (status !== "h5ai") {
callback(status, {}); callback(status, {});
return; return;
}; }
$.ajax({ $.ajax({
url: pathname, url: pathname,
type: "GET", type: "GET",
dataType: "html", dataType: "html",
error: function (xhr) { error: function (xhr) {
callback(xhr.status, {}); // since it was checked before this should never happen callback(xhr.status, {}); // since it was checked before this should never happen
}, },
success: function (html, status, xhr) { success: function (html, status, xhr) {
var content = {};
if (!contentTypeRegEx.test(xhr.getResponseHeader("Content-Type"))) { if (!contentTypeRegEx.test(xhr.getResponseHeader("Content-Type"))) {
callback(xhr.status, {}); // since it was checked before this should never happen callback(xhr.status, {}); // since it was checked before this should never happen
return; return;
}; }
var content = {};
$(html).find("#table td").closest("tr").each(function () { $(html).find("#table td").closest("tr").each(function () {
var path = pathCache.getPathForTableRow( pathname, this );
var path = pathCache.getPath(pathname, this);
if (path.isFolder && (!path.isParentFolder || includeParent)) { if (path.isFolder && (!path.isParentFolder || includeParent)) {
content[path.absHref] = path; content[path.absHref] = path;
THIS.updatePath( path ); updatePath(path);
}; }
}); });
callback("h5ai", content); callback("h5ai", content);
} }
}); });
}); });
}; },
fetchPath = function (pathname, callback) {
fetchStatusAndContent(pathname, false, function (status, content) {
this.fetchStatus = function ( pathname, callback ) { var path = pathCache.getPath(pathname);
if ( h5ai.config.folderStatus[ pathname ] !== undefined ) { path.status = status;
callback( h5ai.config.folderStatus[ pathname ] ); path.content = content;
return; callback(path);
} else if ( pathnameStatusCache[ pathname ] !== undefined ) { });
callback( pathnameStatusCache[ pathname ] ); },
return; fetchTree = function (pathname, callback, childPath) {
};
$.ajax( { fetchPath(pathname, function (path) {
url: pathname,
type: "HEAD", var parent = pathCache.splitPathname(pathname)[0];
complete: function ( xhr ) {
var status = xhr.status; path.treeOpen = true;
if ( status === 200 && contentTypeRegEx.test( xhr.getResponseHeader( "Content-Type" ) ) ) { if (childPath) {
status = "h5ai"; path.content[childPath.absHref] = childPath;
}; }
pathnameStatusCache[ pathname ] = status; if (parent === "") {
callback( status ); callback(path);
} else {
fetchTree(parent, callback, path);
} }
}); });
},
populateTree = function () {
fetchTree(document.location.pathname, function (path) {
$("#tree")
.append(path.updateTreeHtml())
.scrollpanel()
.show();
h5ai.shiftTree(false, true);
h5ai.linkHoverStates();
setTimeout(function () { $("#tree").get(0).updateScrollbar(); }, 1);
});
},
init = function () {
if (h5ai.settings.showTree) {
updatePaths();
populateTree();
}
},
tree = {
fetchStatusAndContent: fetchStatusAndContent,
init: init
}; };
return tree;
}; };

View File

@@ -1,37 +1,25 @@
(function($) { (function($) {
"use strict";
/*global jQuery, h5aiOptions, h5aiLangs*/
// @include "inc/jquery.json.min.js"
// @include "inc/jquery.mousewheel.min.js" // @include "inc/jquery.mousewheel.min.js"
// @include "inc/jquery.scrollpanel.js" // @include "inc/jquery.scrollpanel.js"
// @include "inc/jquery.utils.js" // @include "inc/jquery.utils.js"
// @include "inc/jquery.fracs.js"
// @include "inc/path.js" // @include "inc/path.js"
// @include "inc/extended.js"
// @include "inc/h5ai.js" // @include "inc/h5ai.js"
// @include "inc/extended.js"
// @include "inc/tree.js" // @include "inc/tree.js"
var pathCache = new PathCache(),
/******************************* h5ai = new H5ai(h5aiOptions, h5aiLangs),
* create extended = new Extended(pathCache, h5ai),
*******************************/ tree = new Tree(pathCache, h5ai);
var pathCache = new PathCache();
var h5ai = new H5ai( h5aiOptions, h5aiLangs );
var extended = new Extended( pathCache, h5ai );
var tree = new Tree( pathCache, h5ai );
/*******************************
* register public api
*******************************/
$.h5ai = { $.h5ai = {
click: $.proxy(h5ai.pathClick, h5ai) click: $.proxy(h5ai.pathClick, h5ai)
}; };
/*******************************
* init after dom load
*******************************/
$(function () { $(function () {
extended.init(); extended.init();

View File

@@ -1,32 +1,19 @@
(function($) { (function($) {
"use strict";
/*global jQuery, h5aiOptions, h5aiLangs*/
// @include "inc/jquery.json.min.js"
// @include "inc/jquery.mousewheel.min.js" // @include "inc/jquery.mousewheel.min.js"
// @include "inc/jquery.scrollpanel.js" // @include "inc/jquery.scrollpanel.js"
// @include "inc/jquery.utils.js" // @include "inc/jquery.utils.js"
// @include "inc/jquery.fracs.js"
// @include "inc/h5ai.js" // @include "inc/h5ai.js"
/*******************************
* create
*******************************/
var h5ai = new H5ai(h5aiOptions, h5aiLangs); var h5ai = new H5ai(h5aiOptions, h5aiLangs);
/*******************************
* register public api
*******************************/
$.h5ai = { $.h5ai = {
click: $.proxy(h5ai.pathClick, h5ai) click: $.proxy(h5ai.pathClick, h5ai)
}; };
/*******************************
* init after dom load
*******************************/
$(function () { $(function () {
h5ai.init(); h5ai.init();

View File

@@ -50,12 +50,7 @@ h5aiOptions = {
* as a non auto indexed folder, that means a folder containing an * as a non auto indexed folder, that means a folder containing an
* appropriate default index file. * appropriate default index file.
*/ */
"folderStatus": { "folderStatus": {},
/*
* for example:
* "/some/folder/": 200
*/
},
/* /*
* Localization, for example "en", "de" etc. - see h5aiLangs below for * Localization, for example "en", "de" etc. - see h5aiLangs below for
@@ -102,7 +97,13 @@ h5aiOptions = {
* Only used in PHP implementation. * Only used in PHP implementation.
* Show thumbnails in Icons view. * Show thumbnails in Icons view.
*/ */
"showThumbs": true "showThumbs": true,
/*
* Enable zipped download of selected entries. Requieres
* PHP on the server.
*/
"zippedDownload": true
}; };
@@ -122,7 +123,8 @@ h5aiLangs = {
"parentDirectory": "Parent Directory", "parentDirectory": "Parent Directory",
"empty": "empty", "empty": "empty",
"folders": "folders", "folders": "folders",
"files": "files" "files": "files",
"download": "download"
}, },
"de": { "de": {
@@ -135,7 +137,8 @@ h5aiLangs = {
"parentDirectory": "Übergeordnetes Verzeichnis", "parentDirectory": "Übergeordnetes Verzeichnis",
"empty": "leer", "empty": "leer",
"folders": "Ordner", "folders": "Ordner",
"files": "Dateien" "files": "Dateien",
"download": "Download"
}, },
"fr": { "fr": {
@@ -148,7 +151,8 @@ h5aiLangs = {
"parentDirectory": "Dossier parent", "parentDirectory": "Dossier parent",
"empty": "vide", "empty": "vide",
"folders": "Répertoires", "folders": "Répertoires",
"files": "Fichiers" "files": "Fichiers",
"download": "download"
}, },
"nl": { "nl": {
@@ -160,8 +164,9 @@ h5aiLangs = {
"size": "Grootte", "size": "Grootte",
"parentDirectory": "Bovenliggende map", "parentDirectory": "Bovenliggende map",
"empty": "lege", "empty": "lege",
"folders": "[?folders?]", "folders": "folders",
"files": "[?files?]" "files": "files",
"download": "download"
}, },
"sv": { "sv": {
@@ -173,8 +178,9 @@ h5aiLangs = {
"size": "Filstorlek", "size": "Filstorlek",
"parentDirectory": "Till överordnad mapp", "parentDirectory": "Till överordnad mapp",
"empty": "tom", "empty": "tom",
"folders": "[?folders?]", "folders": "folders",
"files": "[?files?]" "files": "files",
"download": "download"
}, },
"cs": { "cs": {
@@ -187,7 +193,8 @@ h5aiLangs = {
"parentDirectory": "Nadřazený adresář", "parentDirectory": "Nadřazený adresář",
"empty": "prázdný", "empty": "prázdný",
"folders": "složek", "folders": "složek",
"files": "souborů" "files": "souborů",
"download": "download"
}, },
"sk": { "sk": {
@@ -200,7 +207,8 @@ h5aiLangs = {
"parentDirectory": "Nadriadený priečinok", "parentDirectory": "Nadriadený priečinok",
"empty": "prázdny", "empty": "prázdny",
"folders": "priečinkov", "folders": "priečinkov",
"files": "súborov" "files": "súborov",
"download": "download"
}, },
"es": { "es": {
@@ -212,8 +220,9 @@ h5aiLangs = {
"size": "Tamaño", "size": "Tamaño",
"parentDirectory": "Directorio superior", "parentDirectory": "Directorio superior",
"empty": "vacío", "empty": "vacío",
"folders": "[?folders?]", "folders": "folders",
"files": "[?files?]" "files": "files",
"download": "download"
}, },
"tr": { "tr": {
@@ -225,8 +234,9 @@ h5aiLangs = {
"size": "Boyut", "size": "Boyut",
"parentDirectory": "Üst Dizin", "parentDirectory": "Üst Dizin",
"empty": "boş", "empty": "boş",
"folders": "[?folders?]", "folders": "klasörler",
"files": "[?files?]" "files": "dosyalar",
"download": "indir"
}, },
"pt": { "pt": {
@@ -239,7 +249,8 @@ h5aiLangs = {
"parentDirectory": "Diretório superior", "parentDirectory": "Diretório superior",
"empty": "vazio", "empty": "vazio",
"folders": "pastas", "folders": "pastas",
"files": "arquivos" "files": "arquivos",
"download": "download"
}, },
"bg": { "bg": {
@@ -252,7 +263,8 @@ h5aiLangs = {
"parentDirectory": "Предходна директория", "parentDirectory": "Предходна директория",
"empty": "празно", "empty": "празно",
"folders": "папки", "folders": "папки",
"files": "файлове" "files": "файлове",
"download": "download"
}, },
"lv": { "lv": {
@@ -265,7 +277,8 @@ h5aiLangs = {
"parentDirectory": "Vecākdirektorijs", "parentDirectory": "Vecākdirektorijs",
"empty": "tukšs", "empty": "tukšs",
"folders": "mapes", "folders": "mapes",
"files": "faili" "files": "faili",
"download": "lejupielādēt"
}, },
"zh-cn": { "zh-cn": {
@@ -278,7 +291,8 @@ h5aiLangs = {
"parentDirectory": "上层文件夹", "parentDirectory": "上层文件夹",
"empty": "空文件夹", "empty": "空文件夹",
"folders": "文件夹", "folders": "文件夹",
"files": "文件" "files": "文件",
"download": "download"
}, },
"pl": { "pl": {
@@ -291,7 +305,8 @@ h5aiLangs = {
"parentDirectory": "Katalog nadrzędny", "parentDirectory": "Katalog nadrzędny",
"empty": "pusty", "empty": "pusty",
"folders": "foldery", "folders": "foldery",
"files": "pliki" "files": "pliki",
"download": "download"
}, },
"ru": { "ru": {
@@ -304,6 +319,21 @@ h5aiLangs = {
"parentDirectory": "Главная директория", "parentDirectory": "Главная директория",
"empty": "пусто", "empty": "пусто",
"folders": "папки", "folders": "папки",
"files": "файлы" "files": "файлы",
"download": "download"
},
"it": {
"lang": "italiano",
"details": "dettagli",
"icons": "icone",
"name": "Nome",
"lastModified": "Ultima modifica",
"size": "Dimensione",
"parentDirectory": "Cartella Superiore",
"empty": "vuota",
"folders": "cartelle",
"files": "file",
"download": "download"
} }
}; };

View File

@@ -96,7 +96,14 @@ class H5ai {
if ($absPath === null) { if ($absPath === null) {
return $this->absHref; return $this->absHref;
} }
return $this->normalizePath( rawurlencode( preg_replace( "!^" . $this->docRoot . "!", "", $absPath ) ), $endWithSlash ); $absHref = preg_replace("!^" . $this->docRoot . "!", "", $absPath);
$parts = explode("/", $absHref);
$encodedParts = array();
foreach ($parts as $part) {
$encodedParts[] = rawurlencode($part);
}
$endodedAbsHref = implode("/", $encodedParts);
return $this->normalizePath($endodedAbsHref, $endWithSlash);
} }
public function getAbsPath($absHref = null) { public function getAbsPath($absHref = null) {

View File

@@ -0,0 +1,28 @@
<?php
if (!array_key_exists("hrefs", $_REQUEST)) {
echo "failed";
exit;
}
require_once "h5ai.php";
require_once "zipit.php";
$h5ai = new H5ai();
$zipit = new ZipIt($h5ai);
$hrefs = explode(":", trim($_REQUEST["hrefs"]));
$zipFile = $zipit->zip($hrefs);
if ($zipFile !== false) {
header("Content-Disposition: attachment; filename=\"h5ai-selection.zip\"");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($zipFile));
header("Connection: close");
readfile($zipFile);
} else {
echo "sorry, something went wrong while building the zip.";
}
?>

63
src/h5ai/php/zipit.php Normal file
View File

@@ -0,0 +1,63 @@
<?php
class ZipIt {
private $h5ai;
public function __construct($h5ai) {
$this->h5ai = $h5ai;
}
public function zip($hrefs) {
$zipFile = tempnam("/tmp", "h5ai-download");
$zip = new ZipArchive();
if (!$zip->open($zipFile, ZIPARCHIVE::CREATE)) {
return false;
}
foreach ($hrefs as $href) {
$d = dirname($href);
$n = basename($href);
if ($this->h5ai->getHttpCode($this->h5ai->getAbsHref($d)) === "h5ai" && !$this->h5ai->ignoreThisFile($n)) {
$localFile = $this->h5ai->getAbsPath($href);
$file = preg_replace("!^" . $this->h5ai->getDocRoot() . "!", "", $localFile);
if (is_dir($localFile)) {
$this->zipDir($zip, $localFile, $file);
} else {
$this->zipFile($zip, $localFile, $file);
}
}
}
$zip->close();
return $zipFile;
}
private function zipFile($zip, $localFile, $file) {
if (is_readable($localFile)) {
$zip->addFile($localFile, $file);
}
}
private function zipDir($zip, $localDir, $dir) {
if ($this->h5ai->getHttpCode($this->h5ai->getAbsHref($localDir)) === "h5ai") {
$zip->addEmptyDir($dir);
$files = $this->h5ai->readDir($localDir);
foreach ($files as $file) {
$localFile = $localDir . "/" . $file;
$file = $dir . "/" . $file;
if (is_dir($localFile)) {
$this->zipDir($zip, $localFile, $file);
} else {
$this->zipFile($zip, $localFile, $file);
}
}
}
}
}
?>

Binary file not shown.

4
tools/wepp Executable file
View File

@@ -0,0 +1,4 @@
#! /usr/bin/env node
// -*- js -*-
require("wepp").processArgs(process.argv);

40
tools/wepp.ant.xml Normal file
View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="wepp.macros" basedir=".">
<macrodef name="wepp">
<attribute name="file" />
<attribute name="toFile" />
<attribute name="args" default="" />
<sequential>
<exec executable="${wepp}">
<arg line="@{args}" />
<arg value="--in" />
<arg value="@{file}" />
<arg value="--out" />
<arg value="@{toFile}" />
</exec>
</sequential>
</macrodef>
<macrodef name="wepp.dir">
<attribute name="dir" />
<attribute name="args" default="" />
<sequential>
<exec executable="${wepp}">
<arg line="@{args}" />
<arg value="--inDir" />
<arg value="@{dir}" />
<arg value="--outDir" />
<arg value="@{dir}" />
</exec>
<delete dir="@{dir}/inc">
<fileset
dir="."
includes="@{dir}/**/*.less"
excludes="@{dir}/inc/**,@{dir}/lib/**"
/>
</delete>
</sequential>
</macrodef>
</project>