mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 20:14:37 -04:00
Added basic options support. Refactored js.
This commit is contained in:
parent
b7387adfc8
commit
b8fba3ac8e
15 changed files with 682 additions and 639 deletions
|
@ -1,4 +1,4 @@
|
|||
# h5ai v0.5.2   ·   a beautified Apache index
|
||||
# h5ai v0.5.3   ·   a beautified Apache index
|
||||
|
||||
|
||||
## Screenshots
|
||||
|
@ -47,6 +47,13 @@ please respect their rights.
|
|||
|
||||
## Changelog
|
||||
|
||||
### v0.5.3
|
||||
*2011-07-04*
|
||||
|
||||
* refactored js
|
||||
* added basic options support
|
||||
|
||||
|
||||
### v0.5.2
|
||||
*2011-07-02*
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ custom = true
|
|||
|
||||
# project
|
||||
project.name = h5ai
|
||||
project.version = 0.5.2
|
||||
project.version = 0.5.3
|
||||
|
||||
|
||||
# src
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
using
|
||||
<a href="http://tiheum.deviantart.com/art/Faenza-Icons-173323228" target="_blank" title="icon theme for Gnome">Faenza icons</a>
|
||||
</footer>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write( '<script src="/h5ai/js/lib/jquery.min.js"><\/script>' )</script>
|
||||
<script src="/h5ai/options.js"></script>
|
||||
<script src="/h5ai/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
99
src/h5ai/js/inc/file.js
Normal file
99
src/h5ai/js/inc/file.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
|
||||
var File = function ( utils, folder, tableRow ) {
|
||||
|
||||
if ( ! /\/$/.test( folder ) ) {
|
||||
folder += "/";
|
||||
};
|
||||
|
||||
if ( tableRow !== undefined ) {
|
||||
var $tds = $( tableRow ).find( "td" );
|
||||
var $img = $( $tds.get( 0 ) ).find( "img" );
|
||||
var $a= $( $tds.get( 1 ) ).find( "a" );
|
||||
|
||||
this.parentFolder = folder;
|
||||
this.icon16 = $img.attr( "src" );
|
||||
this.alt = $img.attr( "alt" );
|
||||
this.label = $a.text();
|
||||
this.href = $a.attr("href");
|
||||
this.date = $( $tds.get(2) ).text();
|
||||
this.size = $( $tds.get(3) ).text();
|
||||
} else {
|
||||
var splits = utils.splitPathname( folder );
|
||||
|
||||
this.parentFolder = splits[0];
|
||||
this.label = splits[1];
|
||||
this.icon16 = "/h5ai/icons/16x16/folder.png";
|
||||
this.alt = "[DIR]";
|
||||
this.href = this.label;
|
||||
this.date = "";
|
||||
this.size = "";
|
||||
if ( this.label === "/" ) {
|
||||
this.label = document.domain + "/";
|
||||
};
|
||||
};
|
||||
|
||||
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.content = undefined;
|
||||
|
||||
|
||||
this.isComplete = function () {
|
||||
|
||||
if ( this.isFolder ) {
|
||||
if ( this.content === undefined ) {
|
||||
return false;
|
||||
} else if ( this.content instanceof Array ) {
|
||||
for ( idx in this.content ) {
|
||||
if ( !this.content[idx].isComplete() ) {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
this.toHtml = function () {
|
||||
|
||||
var $entry = $( "<div class='entry' />" );
|
||||
|
||||
try {
|
||||
var $a = $( "<a href='" + this.absHref + "' />" )
|
||||
.appendTo( $entry )
|
||||
.append( $( "<span class='icon'><img src='" + this.icon16 + "' /></span>" ) )
|
||||
.append( $( "<span class='label'>" + this.label + "</span>" ) );
|
||||
|
||||
if ( this.isFolder ) {
|
||||
$entry.addClass( "folder" );
|
||||
if ( this.absHref === document.location.pathname ) {
|
||||
$a.find( ".icon img" ).attr( "src", "/h5ai/images/folder-open.png" );
|
||||
$entry.addClass( "current" );
|
||||
};
|
||||
if ( this.content instanceof Array ) {
|
||||
var $ul = $( "<ul class='content' />" ).appendTo( $entry );
|
||||
for ( idx in this.content ) {
|
||||
$( "<li />" ).append( this.content[idx].toHtml() ).appendTo( $ul );
|
||||
};
|
||||
} else if ( this.content === undefined ) {
|
||||
$a.append( $( "<span class='hint'><img src='/h5ai/images/loading.png' /></span>" ) );
|
||||
} else if ( this.content === 200 ) {
|
||||
$a.find( ".icon img" ).attr( "src", "/h5ai/images/folder-page.png" );
|
||||
$a.append( $( "<span class='hint'><img src='/h5ai/images/page.png' /></span>" ) );
|
||||
} else {
|
||||
$a.append( $( "<span class='hint error'>" + this.content + "</span>" ) );
|
||||
$entry.addClass( "notListable" );
|
||||
};
|
||||
} else {
|
||||
$entry.addClass( "file" );
|
||||
};
|
||||
|
||||
} catch( err ) {
|
||||
$( "<span class='fail'>fail</span>" ).appendTo( $entry );
|
||||
};
|
||||
|
||||
return $entry;
|
||||
};
|
||||
};
|
|
@ -1,28 +1,13 @@
|
|||
( function( $ ) {
|
||||
|
||||
|
||||
|
||||
/*******************************
|
||||
* init after dom load
|
||||
*******************************/
|
||||
|
||||
$( function() {
|
||||
|
||||
$.h5ai = new H5ai();
|
||||
} );
|
||||
|
||||
|
||||
|
||||
H5ai = function ( options ) {
|
||||
var H5ai = function ( options ) {
|
||||
|
||||
/*******************************
|
||||
* config
|
||||
*******************************/
|
||||
|
||||
var config = {
|
||||
var defaults = {
|
||||
columnClasses: [ "icon", "name", "date", "size" ],
|
||||
defaultSortOrder: "C=N;O=A",
|
||||
viewmodes: [ "details", "icons" ],
|
||||
store: {
|
||||
viewmode: "h5ai.viewmode"
|
||||
},
|
||||
|
@ -36,8 +21,14 @@
|
|||
callbacks: {
|
||||
folderClick: [],
|
||||
fileClick: []
|
||||
},
|
||||
|
||||
viewmodes: [ "details", "icons" ],
|
||||
showTree: false,
|
||||
folderStatus: {
|
||||
}
|
||||
};
|
||||
this.config = $.extend( {}, defaults, options );
|
||||
|
||||
|
||||
|
||||
|
@ -48,7 +39,7 @@
|
|||
this.folderClick = function ( fn ) {
|
||||
|
||||
if ( typeof fn === "function" ) {
|
||||
config.callbacks.folderClick.push( fn );
|
||||
this.config.callbacks.folderClick.push( fn );
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
@ -57,7 +48,7 @@
|
|||
this.fileClick = function ( fn ) {
|
||||
|
||||
if ( typeof fn === "function" ) {
|
||||
config.callbacks.fileClick.push( fn );
|
||||
this.config.callbacks.fileClick.push( fn );
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
@ -65,15 +56,15 @@
|
|||
|
||||
|
||||
/*******************************
|
||||
* init (will be called at the bottom)
|
||||
* init
|
||||
*******************************/
|
||||
|
||||
var init = function () {
|
||||
this.init = function () {
|
||||
|
||||
applyViewmode();
|
||||
initBreadcrumb();
|
||||
initViews();
|
||||
customize();
|
||||
this.applyViewmode();
|
||||
this.initBreadcrumb();
|
||||
this.initViews();
|
||||
this.customize();
|
||||
};
|
||||
|
||||
|
||||
|
@ -82,18 +73,18 @@
|
|||
* callback triggers
|
||||
*******************************/
|
||||
|
||||
var triggerFolderClick = function ( label ) {
|
||||
this.triggerFolderClick = function ( label ) {
|
||||
|
||||
for ( idx in config.callbacks.folderClick ) {
|
||||
config.callbacks.folderClick[idx].call( window, label );
|
||||
for ( idx in this.config.callbacks.folderClick ) {
|
||||
this.config.callbacks.folderClick[idx].call( window, label );
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var triggerFileClick = function ( label ) {
|
||||
this.triggerFileClick = function ( label ) {
|
||||
|
||||
for ( idx in config.callbacks.fileClick ) {
|
||||
config.callbacks.fileClick[idx].call( window, label );
|
||||
for ( idx in this.config.callbacks.fileClick ) {
|
||||
this.config.callbacks.fileClick[idx].call( window, label );
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -103,29 +94,44 @@
|
|||
* local stored viewmode
|
||||
*******************************/
|
||||
|
||||
var getViewmode = function () {
|
||||
this.getViewmode = function () {
|
||||
|
||||
var viewmode = localStorage.getItem( config.store.viewmode );
|
||||
if ( $.inArray( viewmode, config.viewmodes ) ) {
|
||||
var viewmode = localStorage.getItem( this.config.store.viewmode );
|
||||
if ( $.inArray( viewmode, this.config.viewmodes ) >= 0 ) {
|
||||
return viewmode;
|
||||
};
|
||||
return config.viewmodes[0];
|
||||
return this.config.viewmodes[0];
|
||||
};
|
||||
|
||||
|
||||
var applyViewmode = function ( viewmode ) {
|
||||
this.applyViewmode = function ( viewmode ) {
|
||||
|
||||
$( "#table" ).hide();
|
||||
if ( viewmode !== undefined ) {
|
||||
localStorage.setItem( config.store.viewmode, viewmode );
|
||||
localStorage.setItem( this.config.store.viewmode, viewmode );
|
||||
};
|
||||
|
||||
$( "body > nav li.view" ).hide();
|
||||
if ( this.config.viewmodes.length > 1 ) {
|
||||
if ( $.inArray( "details", this.config.viewmodes ) >= 0 ) {
|
||||
$( "#viewdetails" ).show();
|
||||
};
|
||||
if ( $.inArray( "icons", this.config.viewmodes ) >= 0 ) {
|
||||
$( "#viewicons" ).show();
|
||||
};
|
||||
};
|
||||
|
||||
$( "body > nav li.view" ).removeClass( "current" );
|
||||
if ( getViewmode() === "icons" ) {
|
||||
if ( this.getViewmode() === "details" ) {
|
||||
$( "#viewdetails" ).closest( "li" ).addClass( "current" );
|
||||
$( "#table" ).hide();
|
||||
$( "#extended" ).addClass( "details-view" ).removeClass( "icons-view" ).show();
|
||||
} else if ( this.getViewmode() === "icons" ) {
|
||||
$( "#viewicons" ).closest( "li" ).addClass( "current" );
|
||||
$( "#table" ).hide();
|
||||
$( "#extended" ).removeClass( "details-view" ).addClass( "icons-view" ).show();
|
||||
} else {
|
||||
$( "#viewdetails" ).closest( "li" ).addClass( "current" );
|
||||
$( "#extended" ).addClass( "details-view" ).removeClass( "icons-view" ).show();
|
||||
$( "#table" ).show();
|
||||
$( "#extended" ).hide();
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -135,7 +141,7 @@
|
|||
* breadcrumb and doc title
|
||||
*******************************/
|
||||
|
||||
var initBreadcrumb = function () {
|
||||
this.initBreadcrumb = function () {
|
||||
|
||||
$( "#domain span" ).text( document.domain );
|
||||
var pathname = decodeURI( document.location.pathname );
|
||||
|
@ -146,7 +152,7 @@
|
|||
var part = parts[idx];
|
||||
if ( part !== "" ) {
|
||||
path += part + "/";
|
||||
$ul.append( $( "<li class='crumb'><a href='" + path + "'><img src='" + config.icons.crumb + "' alt='>' />" + part + "</a></li>" ) );
|
||||
$ul.append( $( "<li class='crumb'><a href='" + path + "'><img src='" + this.config.icons.crumb + "' alt='>' />" + part + "</a></li>" ) );
|
||||
};
|
||||
};
|
||||
$( "body > nav .crumb:last" ).addClass( "current" );
|
||||
|
@ -160,12 +166,13 @@
|
|||
* table view
|
||||
*******************************/
|
||||
|
||||
var initTableView = function () {
|
||||
this.initTableView = function () {
|
||||
|
||||
var ref = this;
|
||||
function getColumnClass( idx ) {
|
||||
|
||||
if ( idx >= 0 && idx < config.columnClasses.length ) {
|
||||
return config.columnClasses[idx];
|
||||
if ( idx >= 0 && idx < ref.config.columnClasses.length ) {
|
||||
return ref.config.columnClasses[idx];
|
||||
};
|
||||
return "unknown";
|
||||
};
|
||||
|
@ -185,7 +192,7 @@
|
|||
* extended view
|
||||
*******************************/
|
||||
|
||||
var initExtendedView = function () {
|
||||
this.initExtendedView = function () {
|
||||
|
||||
var $ul = $( "<ul/>" );
|
||||
|
||||
|
@ -202,13 +209,13 @@
|
|||
// header sort icons
|
||||
var order = document.location.search;
|
||||
if ( order === "" ) {
|
||||
order = config.defaultSortOrder;
|
||||
order = this.config.defaultSortOrder;
|
||||
};
|
||||
var $icon;
|
||||
if ( order.indexOf( "O=A" ) >= 0 ) {
|
||||
$icon = $( "<img src='" + config.icons.ascending + "' class='sort' alt='ascending' />" );
|
||||
$icon = $( "<img src='" + this.config.icons.ascending + "' class='sort' alt='ascending' />" );
|
||||
} else {
|
||||
$icon = $( "<img src='" + config.icons.descending + "' class='sort' alt='descending' />" );
|
||||
$icon = $( "<img src='" + this.config.icons.descending + "' class='sort' alt='descending' />" );
|
||||
};
|
||||
if ( order.indexOf( "C=N" ) >= 0 ) {
|
||||
$li.find( "a.label" ).append( $icon );
|
||||
|
@ -257,13 +264,14 @@
|
|||
$( "#extended" ).append( $( "<div class='clearfix' />" ) );
|
||||
|
||||
// click callbacks
|
||||
var ref = this;
|
||||
$( "#extended .entry.folder" )
|
||||
.click( function() {
|
||||
triggerFolderClick( $( this ).find( ".label" ).text() );
|
||||
ref.triggerFolderClick( $( this ).find( ".label" ).text() );
|
||||
} );
|
||||
$( "#extended .entry.file" )
|
||||
.click( function() {
|
||||
triggerFileClick( $( this ).find( ".label" ).text() );
|
||||
ref.triggerFileClick( $( this ).find( ".label" ).text() );
|
||||
} );
|
||||
};
|
||||
|
||||
|
@ -272,18 +280,19 @@
|
|||
* init views
|
||||
*******************************/
|
||||
|
||||
var initViews = function () {
|
||||
this.initViews = function () {
|
||||
|
||||
initTableView();
|
||||
initExtendedView();
|
||||
this.initTableView();
|
||||
this.initExtendedView();
|
||||
|
||||
var ref = this;
|
||||
$( "#viewdetails" ).closest( "li" )
|
||||
.click( function () {
|
||||
applyViewmode( "details" );
|
||||
ref.applyViewmode( "details" );
|
||||
} );
|
||||
$( "#viewicons" ).closest( "li" )
|
||||
.click( function () {
|
||||
applyViewmode( "icons" );
|
||||
ref.applyViewmode( "icons" );
|
||||
} );
|
||||
};
|
||||
|
||||
|
@ -293,10 +302,10 @@
|
|||
* customize
|
||||
*******************************/
|
||||
|
||||
var customize = function () {
|
||||
this.customize = function () {
|
||||
|
||||
$.ajax( {
|
||||
url: config.customHeader,
|
||||
url: this.config.customHeader,
|
||||
dataType: "html",
|
||||
success: function ( data ) {
|
||||
$( "#content > header" ).append( $( data ) ).show();
|
||||
|
@ -304,21 +313,11 @@
|
|||
} );
|
||||
|
||||
$.ajax( {
|
||||
url: config.customFooter,
|
||||
url: this.config.customFooter,
|
||||
dataType: "html",
|
||||
success: function ( data ) {
|
||||
$( "#content > footer" ).prepend( $( data ) ).show();
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*******************************
|
||||
* finally run init
|
||||
*******************************/
|
||||
|
||||
init();
|
||||
};
|
||||
|
||||
} )( jQuery );
|
||||
|
|
|
@ -1,312 +0,0 @@
|
|||
|
||||
( function( $ ) {
|
||||
|
||||
|
||||
|
||||
/*******************************
|
||||
* init after dom load
|
||||
*******************************/
|
||||
|
||||
$( function() {
|
||||
|
||||
window.setTimeout( function() {
|
||||
$.h5aiTree = new H5aiTree();
|
||||
}, 1 );
|
||||
} );
|
||||
|
||||
|
||||
H5aiTree = function ( options ) {
|
||||
|
||||
|
||||
var folderRegEx = /\/$/;
|
||||
var pathnameRegEx = /^(\/(.*\/)*)([^\/]+\/?)$/;
|
||||
var contentTypeRegEx = /^text\/html;h5ai=/;
|
||||
|
||||
|
||||
function init() {
|
||||
|
||||
checkCrumb();
|
||||
initShifting();
|
||||
populateTree();
|
||||
};
|
||||
|
||||
|
||||
function splitPathname( pathname ) {
|
||||
|
||||
if ( pathname === "/" ) {
|
||||
return [ "", "/" ];
|
||||
};
|
||||
var match = pathnameRegEx.exec( pathname );
|
||||
return [ match[1], match[3] ];
|
||||
};
|
||||
|
||||
|
||||
function checkCrumb() {
|
||||
|
||||
$( "li.crumb a" ).each( function() {
|
||||
|
||||
var $a = $( this );
|
||||
var pathname = $a.attr( "href" );
|
||||
checkPathname( pathname, function ( status ) {
|
||||
if ( status !== 0 ) {
|
||||
$( "<img class='hint' src='/h5ai/images/page.png' alt='not listable' />" ).appendTo( $a );
|
||||
if ( status !== 200 ) {
|
||||
$( "<span class='hint'>(" + status + ")</span>" ).appendTo( $a );
|
||||
};
|
||||
};
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
function shiftTree( show ) {
|
||||
|
||||
var $tree = $( "#tree" );
|
||||
var $extended = $( "#extended" );
|
||||
var show = show || false;
|
||||
|
||||
if ( $tree.outerWidth() < $extended.offset().left || show ) {
|
||||
$tree.stop().animate( { left: 0 } );
|
||||
} else {
|
||||
//var left = Math.max( 24 - $tree.outerWidth(), $extended.offset().left - $tree.outerWidth() - 16 );
|
||||
var left = 24 - $tree.outerWidth();
|
||||
$tree.stop().animate( { left: left } );
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function initShifting() {
|
||||
|
||||
$( "#tree" ).hover(
|
||||
function () {
|
||||
shiftTree( true );
|
||||
},
|
||||
function () {
|
||||
shiftTree();
|
||||
}
|
||||
);
|
||||
$( window ).resize( function() {
|
||||
shiftTree();
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
function populateTree() {
|
||||
|
||||
var $tree = $( "#tree" );
|
||||
$tree.css( { left: -400 } ).show();
|
||||
shiftTree();
|
||||
var pathname = decodeURI( document.location.pathname );
|
||||
fetchTree( pathname, function( entry ) {
|
||||
$tree.empty().append( entry.toHtml() );
|
||||
shiftTree();
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
function fetchTree( pathname, callback ) {
|
||||
|
||||
walkBack( pathname, function( walkbackedPathname ) {
|
||||
var entry = new Entry( walkbackedPathname );
|
||||
fetchEntriesRecursive( walkbackedPathname, function ( content ) {
|
||||
entry.content = content;
|
||||
callback( entry );
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
function walkBack( pathname, callback ) {
|
||||
|
||||
var splits = splitPathname( pathname );
|
||||
var parent = splits[0];
|
||||
if ( parent === "" ) {
|
||||
callback( pathname );
|
||||
} else {
|
||||
checkPathname( parent, function( state ) {
|
||||
if ( state === 0 ) {
|
||||
walkBack( parent, callback );
|
||||
} else {
|
||||
callback( pathname );
|
||||
};
|
||||
} );
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function fetchEntriesRecursive( pathname, callback ) {
|
||||
|
||||
fetchEntries( pathname, false, function ( entries ) {
|
||||
if ( entries instanceof Array ) {
|
||||
for ( idx in entries ) {
|
||||
( function ( entry ) {
|
||||
if ( entry.isFolder ) {
|
||||
fetchEntriesRecursive( entry.absHref, function( content ) {
|
||||
entry.content = content;
|
||||
callback( entries );
|
||||
} );
|
||||
};
|
||||
} ) ( entries[idx] );
|
||||
};
|
||||
};
|
||||
callback( entries );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
function fetchEntries( pathname, includeParent, callback ) {
|
||||
|
||||
checkPathname( pathname, function ( status ) {
|
||||
console.log( "checkPathname", pathname, status );
|
||||
if ( status !== 0 ) {
|
||||
callback( status );
|
||||
} else {
|
||||
$.ajax( {
|
||||
url: pathname,
|
||||
type: "GET",
|
||||
dataType: "html",
|
||||
error: function ( xhr ) {
|
||||
// since it was checked before this should never happen
|
||||
callback( xhr.status );
|
||||
},
|
||||
success: function ( html, status, xhr ) {
|
||||
if ( !contentTypeRegEx.test( xhr.getResponseHeader( "Content-Type" ) ) ) {
|
||||
// since it was checked before this should never happen
|
||||
callback( xhr.status );
|
||||
} else {
|
||||
var entries = [];
|
||||
$( html ).find( "#table table td" ).closest( "tr" ).each( function () {
|
||||
var entry = new Entry( pathname, this );
|
||||
if ( !entry.isParentFolder || includeParent ) {
|
||||
entries.push( entry );
|
||||
};
|
||||
} );
|
||||
callback( entries );
|
||||
};
|
||||
}
|
||||
} );
|
||||
};
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
function checkPathname( pathname, callback ) {
|
||||
|
||||
$.ajax( {
|
||||
url: pathname,
|
||||
type: "HEAD",
|
||||
complete: function ( xhr ) {
|
||||
if ( xhr.status === 200 && contentTypeRegEx.test( xhr.getResponseHeader( "Content-Type" ) ) ) {
|
||||
callback( 0 );
|
||||
} else {
|
||||
callback( xhr.status );
|
||||
};
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
Entry = function ( folder, tableRow ) {
|
||||
|
||||
if ( !folderRegEx.test( folder ) ) {
|
||||
folder += "/";
|
||||
};
|
||||
|
||||
if ( tableRow !== undefined ) {
|
||||
var $tds = $( tableRow ).find( "td" );
|
||||
var $img = $( $tds.get( 0 ) ).find( "img" );
|
||||
var $a= $( $tds.get( 1 ) ).find( "a" );
|
||||
|
||||
this.parentFolder = folder;
|
||||
this.icon16 = $img.attr( "src" );
|
||||
this.alt = $img.attr( "alt" );
|
||||
this.label = $a.text();
|
||||
this.href = $a.attr("href");
|
||||
this.date = $( $tds.get(2) ).text();
|
||||
this.size = $( $tds.get(3) ).text();
|
||||
} else {
|
||||
var splits = splitPathname( folder );
|
||||
|
||||
this.parentFolder = splits[0];
|
||||
this.label = splits[1];
|
||||
this.icon16 = "/h5ai/icons/16x16/folder.png";
|
||||
this.alt = "[DIR]";
|
||||
this.href = this.label;
|
||||
this.date = "";
|
||||
this.size = "";
|
||||
if ( this.label === "/" ) {
|
||||
this.label = document.domain + "/";
|
||||
};
|
||||
};
|
||||
|
||||
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.content = undefined;
|
||||
|
||||
|
||||
this.isComplete = function () {
|
||||
|
||||
if ( this.isFolder ) {
|
||||
if ( this.content === undefined ) {
|
||||
return false;
|
||||
} else if ( this.content instanceof Array ) {
|
||||
for ( idx in this.content ) {
|
||||
if ( !this.content[idx].isComplete() ) {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
this.toHtml = function () {
|
||||
|
||||
var $entry = $( "<div class='entry' />" );
|
||||
|
||||
try {
|
||||
var $a = $( "<a href='" + this.absHref + "' />" )
|
||||
.appendTo( $entry )
|
||||
.append( $( "<span class='icon'><img src='" + this.icon16 + "' /></span>" ) )
|
||||
.append( $( "<span class='label'>" + this.label + "</span>" ) );
|
||||
|
||||
if ( this.isFolder ) {
|
||||
$entry.addClass( "folder" );
|
||||
if ( this.absHref === document.location.pathname ) {
|
||||
$a.find( ".icon img" ).attr( "src", "/h5ai/images/folder-open.png" );
|
||||
$entry.addClass( "current" );
|
||||
};
|
||||
if ( this.content instanceof Array ) {
|
||||
var $ul = $( "<ul class='content' />" ).appendTo( $entry );
|
||||
for ( idx in this.content ) {
|
||||
$( "<li />" ).append( this.content[idx].toHtml() ).appendTo( $ul );
|
||||
};
|
||||
} else if ( this.content === undefined ) {
|
||||
$a.append( $( "<span class='hint'><img src='/h5ai/images/loading.png' /></span>" ) );
|
||||
} else if ( this.content === 200 ) {
|
||||
$a.find( ".icon img" ).attr( "src", "/h5ai/images/folder-page.png" );
|
||||
$a.append( $( "<span class='hint'><img src='/h5ai/images/page.png' /></span>" ) );
|
||||
} else {
|
||||
$a.append( $( "<span class='hint error'>" + this.content + "</span>" ) );
|
||||
$entry.addClass( "notListable" );
|
||||
};
|
||||
} else {
|
||||
$entry.addClass( "file" );
|
||||
};
|
||||
|
||||
} catch( err ) {
|
||||
$( "<span class='fail'>fail</span>" ).appendTo( $entry );
|
||||
};
|
||||
|
||||
return $entry;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
init()
|
||||
};
|
||||
|
||||
} )( jQuery );
|
183
src/h5ai/js/inc/tree.js
Normal file
183
src/h5ai/js/inc/tree.js
Normal file
|
@ -0,0 +1,183 @@
|
|||
|
||||
var Tree = function ( utils, h5ai ) {
|
||||
|
||||
var thistree = this;
|
||||
var contentTypeRegEx = /^text\/html;h5ai=/;
|
||||
|
||||
this.init = function () {
|
||||
|
||||
if ( h5ai.config.showTree ) {
|
||||
this.checkCrumb();
|
||||
this.initShifting();
|
||||
this.populateTree();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
this.checkCrumb = function () {
|
||||
|
||||
$( "li.crumb a" ).each( function() {
|
||||
|
||||
var $a = $( this );
|
||||
var pathname = $a.attr( "href" );
|
||||
thistree.checkPathname( pathname, function ( status ) {
|
||||
if ( status !== 0 ) {
|
||||
$( "<img class='hint' src='/h5ai/images/page.png' alt='not listable' />" ).appendTo( $a );
|
||||
if ( status !== 200 ) {
|
||||
$( "<span class='hint'>(" + status + ")</span>" ).appendTo( $a );
|
||||
};
|
||||
};
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
this.shiftTree = function ( show ) {
|
||||
|
||||
var $tree = $( "#tree" );
|
||||
var $extended = $( "#extended" );
|
||||
var show = show || false;
|
||||
|
||||
if ( $tree.outerWidth() < $extended.offset().left || show ) {
|
||||
$tree.stop().animate( { left: 0 } );
|
||||
} else {
|
||||
$tree.stop().animate( { left: 24 - $tree.outerWidth() } );
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
this.initShifting = function () {
|
||||
|
||||
$( "#tree" ).hover(
|
||||
function () {
|
||||
thistree.shiftTree( true );
|
||||
},
|
||||
function () {
|
||||
thistree.shiftTree();
|
||||
}
|
||||
);
|
||||
$( window ).resize( function() {
|
||||
thistree.shiftTree();
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
this.populateTree = function () {
|
||||
|
||||
var $tree = $( "#tree" );
|
||||
$tree.css( { left: -400 } ).show();
|
||||
|
||||
this.shiftTree();
|
||||
|
||||
this.fetchTree( decodeURI( document.location.pathname ), function( entry ) {
|
||||
$tree.empty().append( entry.toHtml() );
|
||||
thistree.shiftTree();
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
this.fetchTree = function ( pathname, callback ) {
|
||||
|
||||
this.walkBack( pathname, function( walkbackedPathname ) {
|
||||
var entry = new File( utils, walkbackedPathname );
|
||||
thistree.fetchEntriesRecursive( walkbackedPathname, function ( content ) {
|
||||
entry.content = content;
|
||||
callback( entry );
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
this.walkBack = function ( pathname, callback ) {
|
||||
|
||||
var splits = utils.splitPathname( pathname );
|
||||
var parent = splits[0];
|
||||
if ( parent === "" ) {
|
||||
callback( pathname );
|
||||
} else {
|
||||
this.checkPathname( parent, function( state ) {
|
||||
if ( state === 0 ) {
|
||||
thistree.walkBack( parent, callback );
|
||||
} else {
|
||||
callback( pathname );
|
||||
};
|
||||
} );
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
this.fetchEntriesRecursive = function ( pathname, callback ) {
|
||||
|
||||
this.fetchEntries( pathname, false, function ( entries ) {
|
||||
if ( entries instanceof Array ) {
|
||||
for ( idx in entries ) {
|
||||
( function ( entry ) {
|
||||
if ( entry.isFolder ) {
|
||||
thistree.fetchEntriesRecursive( entry.absHref, function( content ) {
|
||||
entry.content = content;
|
||||
callback( entries );
|
||||
} );
|
||||
};
|
||||
} ) ( entries[idx] );
|
||||
};
|
||||
};
|
||||
callback( entries );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
this.fetchEntries = function ( pathname, includeParent, callback ) {
|
||||
|
||||
this.checkPathname( pathname, function ( status ) {
|
||||
console.log( "checkPathname", pathname, status );
|
||||
if ( status !== 0 ) {
|
||||
callback( status );
|
||||
} else {
|
||||
$.ajax( {
|
||||
url: pathname,
|
||||
type: "GET",
|
||||
dataType: "html",
|
||||
error: function ( xhr ) {
|
||||
// since it was checked before this should never happen
|
||||
callback( xhr.status );
|
||||
},
|
||||
success: function ( html, status, xhr ) {
|
||||
if ( !contentTypeRegEx.test( xhr.getResponseHeader( "Content-Type" ) ) ) {
|
||||
// since it was checked before this should never happen
|
||||
callback( xhr.status );
|
||||
} else {
|
||||
var entries = [];
|
||||
$( html ).find( "#table table td" ).closest( "tr" ).each( function () {
|
||||
var entry = new File( utils, pathname, this );
|
||||
if ( !entry.isParentFolder || includeParent ) {
|
||||
entries.push( entry );
|
||||
};
|
||||
} );
|
||||
callback( entries );
|
||||
};
|
||||
}
|
||||
} );
|
||||
};
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
this.checkPathname = function ( pathname, callback ) {
|
||||
|
||||
if ( h5ai.config.folderStatus[ pathname ] !== undefined ) {
|
||||
callback( h5ai.config.folderStatus[ pathname ] );
|
||||
} else {
|
||||
$.ajax( {
|
||||
url: pathname,
|
||||
type: "HEAD",
|
||||
complete: function ( xhr ) {
|
||||
if ( xhr.status === 200 && contentTypeRegEx.test( xhr.getResponseHeader( "Content-Type" ) ) ) {
|
||||
callback( 0 );
|
||||
} else {
|
||||
callback( xhr.status );
|
||||
};
|
||||
}
|
||||
} );
|
||||
};
|
||||
};
|
||||
};
|
15
src/h5ai/js/inc/utils.js
Normal file
15
src/h5ai/js/inc/utils.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
var Utils = function () {
|
||||
|
||||
var pathnameRegEx = /^(\/(.*\/)*)([^\/]+\/?)$/;
|
||||
|
||||
this.splitPathname = function ( pathname ) {
|
||||
|
||||
if ( pathname === "/" ) {
|
||||
return [ "", "/" ];
|
||||
};
|
||||
var match = pathnameRegEx.exec( pathname );
|
||||
return [ match[1], match[3] ];
|
||||
};
|
||||
|
||||
};
|
|
@ -1,3 +1,37 @@
|
|||
// @include "inc/jquery.json.min.js"
|
||||
( function( $ ) {
|
||||
|
||||
// @include "inc/utils.js"
|
||||
// @include "inc/h5ai.js"
|
||||
// #not#include "inc/h5aitree.js"
|
||||
// @include "inc/file.js"
|
||||
// @include "inc/tree.js"
|
||||
|
||||
|
||||
/*******************************
|
||||
* create
|
||||
*******************************/
|
||||
|
||||
var utils = new Utils();
|
||||
var h5ai = new H5ai( h5aiOptions );
|
||||
var tree = new Tree( utils, h5ai );
|
||||
|
||||
|
||||
/*******************************
|
||||
* register public api
|
||||
*******************************/
|
||||
|
||||
$.h5ai = {
|
||||
folderClick: h5ai.folderClick,
|
||||
fileClick: h5ai.fileClick
|
||||
};
|
||||
|
||||
|
||||
/*******************************
|
||||
* init after dom load
|
||||
*******************************/
|
||||
|
||||
$( function() {
|
||||
h5ai.init();
|
||||
tree.init();
|
||||
} );
|
||||
|
||||
} )( jQuery );
|
8
src/h5ai/options.js
Normal file
8
src/h5ai/options.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
h5aiOptions = {
|
||||
viewmodes: [ "icons", "details" ],
|
||||
showTree: true,
|
||||
folderStatus: {
|
||||
"/develop/folder-types/phpsite/": 200
|
||||
}
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
################################
|
||||
# h5ai 0.5.2
|
||||
# h5ai 0.5.3
|
||||
# customized .htaccess
|
||||
################################
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
|||
|
||||
IndexOrderDefault Ascending Name
|
||||
|
||||
IndexOptions Type=text/html;h5ai=0.5.2
|
||||
IndexOptions Type=text/html;h5ai=0.5.3
|
||||
IndexOptions Charset=UTF-8
|
||||
IndexOptions FancyIndexing
|
||||
IndexOptions HTMLTable
|
||||
|
|
|
@ -11,12 +11,13 @@
|
|||
<img class="techclass" src="/h5ai/images/html5-storage.png" alt="html5-storage" />
|
||||
<img class="techclass" src="/h5ai/images/html5-css3.png" alt="html5-css3" />
|
||||
</a>
|
||||
<a href="http://larsjung.de/h5ai" target="_blank" title="h5ai 0.5.2">h5ai</a>
|
||||
<a href="http://larsjung.de/h5ai" target="_blank" title="h5ai 0.5.3">h5ai</a>
|
||||
using
|
||||
<a href="http://tiheum.deviantart.com/art/Faenza-Icons-173323228" target="_blank" title="icon theme for Gnome">Faenza icons</a>
|
||||
</footer>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write( '<script src="/h5ai/js/lib/jquery.min.js"><\/script>' )</script>
|
||||
<script src="/h5ai/options.js"></script>
|
||||
<script src="/h5ai/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Directory index · styled with h5ai</title>
|
||||
<meta name="h5ai-version" content="h5ai 0.5.2">
|
||||
<meta name="h5ai-version" content="h5ai 0.5.3">
|
||||
<meta name="description" content="Directory index styled with h5ai (http://larsjung.de/h5ai)">
|
||||
<meta name="keywords" content="directory, index, autoindex, h5ai">
|
||||
<link rel="shortcut icon" type="image/png" href="/h5ai/images/h5ai-16x16.png">
|
||||
|
|
File diff suppressed because one or more lines are too long
8
target/h5ai/options.js
Normal file
8
target/h5ai/options.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
h5aiOptions = {
|
||||
viewmodes: [ "icons", "details" ],
|
||||
showTree: true,
|
||||
folderStatus: {
|
||||
"/develop/folder-types/phpsite/": 200
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue