var H5ai = function ( options, langs, pathCache ) { /******************************* * config *******************************/ var defaults = { defaultSortOrder: "C=N;O=A", store: { viewmode: "h5ai.viewmode" }, customHeader: "h5ai.header.html", customFooter: "h5ai.footer.html", callbacks: { pathClick: [] }, viewmodes: [ "details", "icons" ], showTree: false, folderStatus: { }, lang: undefined, useBrowserLang: true, setParentFolderLabels: true, linkHoverStates: true }; this.config = $.extend( {}, defaults, options ); /******************************* * public api *******************************/ this.pathClick = function ( fn ) { if ( $.isFunction( fn ) ) { this.config.callbacks.pathClick.push( fn ); }; return this; }; /******************************* * init *******************************/ this.init = function () { document.title = decodeURI( document.domain + document.location.pathname ); this.applyViewmode(); this.initBreadcrumb(); this.initTopSpace(); this.initViews(); this.customize(); this.localize( langs, this.config.lang, this.config.useBrowserLang ); }; /******************************* * 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(); $( "body > nav li.view" ).hide().removeClass( "current" ); if ( this.config.viewmodes.length > 1 ) { if ( $.inArray( "details", this.config.viewmodes ) >= 0 ) { $( "#viewdetails" ).show(); }; if ( $.inArray( "icons", this.config.viewmodes ) >= 0 ) { $( "#viewicons" ).show(); }; }; if ( viewmode === "details" ) { $( "#viewdetails" ).closest( "li" ).addClass( "current" ); $( "#table" ).hide(); $( "#extended" ).addClass( "details-view" ).removeClass( "icons-view" ).show(); } else if ( viewmode === "icons" ) { $( "#viewicons" ).closest( "li" ).addClass( "current" ); $( "#table" ).hide(); $( "#extended" ).removeClass( "details-view" ).addClass( "icons-view" ).show(); } else { $( "#table" ).show(); $( "#extended" ).hide(); }; }; /******************************* * breadcrumb *******************************/ this.initBreadcrumb = function () { var $ul = $( "body > nav ul" ); var pathname = "/"; var path = pathCache.getPathForFolder( pathname ); $ul.append( path.updateCrumbHtml() ); var pathnameParts = document.location.pathname.split( "/" ); for ( idx in pathnameParts ) { var part = pathnameParts[idx]; if ( part !== "" ) { pathname += part + "/"; var path = pathCache.getPathForFolder( pathname ); $ul.append( path.updateCrumbHtml() ); }; }; }; /******************************* * top space, depending on nav height *******************************/ this.initTopSpace = function () { 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 { $( "#tree" ).get( 0 ).updateScrollbar(); } catch ( err ) {}; }; $( window ).resize( function () { adjustTopSpace(); } ); adjustTopSpace(); }; /******************************* * table view *******************************/ this.initTableView = function () { $( "#table td" ).removeAttr( "align" ).removeAttr( "valign" ); }; /******************************* * extended view *******************************/ this.initExtendedView = function () { var $ul = $( "