//// // Formatting of Apache `mod_autoindex` pages. var __autoindex_autoindex_js; if( !__autoindex_autoindex_js ) { __autoindex_autoindex_js = true; // prevent double-loading of this script from both /_/web_service/autoindex/deprecated/header.html and ./_autoindex-summary.html var textbenderWaveHTML = // pattern suggested by Adrian Gog // changing? grep for clones in other files, where it commonly appears as: textbender "t" + "e" + "x" + "t" + "b" + "e" + "n" + "d" + "e" + "r"; /** Appends text after an 'a' element of the Apache autoindex listing. */ function appendAfterListingA( a, extraString ) { // alert( 'appendAfterListingA, this needs to be fixed' ); // Test on IE. I think the line ends in 2 chars (\r\n). Could try regexp replace instead (but see replaceAfterListingA). //// works, though why replaceAfterListingA had such trouble, is unclear var textAfterA = a.nextSibling; var i = textAfterA.data.length - 1; // insert before trailing newline textAfterA.insertData( i, extraString ); } /** Appends text to the content of an 'a' element of the Apache autoindex listing. */ function appendInListingA( a, extraString ) { span = document.createElement( 'span' ); a.appendChild( span ); span.appendChild( document.createTextNode( extraString )); span.className = 'appendInListingA'; } function elementAddClass( element, className ) { if( this.elementHasClass( element, className )) return; var separator = element.className? ' ': ''; element.className += separator + className; } function elementHasClass( element, className ) { return element.className.match(new RegExp('(?:^|\\s)'+className+'(?:\\s|$)')) != null; } function elementRemoveClass( element, className ) { // modified from MooTools. [1] element.className = element.className.replace( new RegExp('(^|\\s)'+className+'(?:\\s|$)'), '$1' ); } /** Assigns classes to 'a' elements that mimic the file-type style rules that IE can't * understand (because it selects on atttributes). See autoindex.css. */ function fixFileTypeStylesForIE() { var pre; for( var child = document.body.firstChild; child != null; child = child.nextSibling ) { if( child.nodeType != /*element*/1 ) continue; if( child.tagName.toLowerCase() == 'pre' ) { pre = child; break; } } if( !pre ) return; for( var child = pre.firstChild; child != null; child = child.nextSibling ) { if( child.nodeType != /*element*/1 ) continue; if( child.tagName.toLowerCase() != 'a' ) continue; var href = child.getAttribute( 'href' ); // IE messes href up by expanding it (per textbender/_/autoindex-summary.js) so must use regexp here if( href.match(/\?C=M;O=A$/) != null || href.match(/\?C=M;O=D$/) != null || href.match(/\?C=N;O=A$/) != null || href.match(/\?C=N;O=D$/) != null || href.match(/\?C=S;O=A$/) != null || href.match(/\?C=S;O=D$/) != null ) { elementAddClass( child, 'list-header' ); continue; } var img; // preceding the 'a' child for( var sib = child;; ) { sib = sib.previousSibling; if( sib == null ) break; if( sib.nodeType == /*element*/1 ) { if( sib.tagName.toLowerCase() == 'img' ) img = sib; break; } } if( img == null ) continue; var alt = img.getAttribute( 'alt' ); if( alt == '[DIR]' ) { elementAddClass( child, 'DIR-ie-fix' ); continue; } if( alt == '[ETC]' ) { elementAddClass( child, 'ETC' ); continue; } if( alt == '[htm]' ) { elementAddClass( child, 'htm' ); continue; } if( alt == '[jav]' ) { elementAddClass( child, 'jav' ); continue; } if( alt == '[jnl]' ) { elementAddClass( child, 'jnl' ); continue; } if( alt == '[PAR]' ) { elementAddClass( child, 'par' ); continue; } if( alt == '[-pm]' ) { elementAddClass( child, 'pm' ); continue; } if( alt == '[txt]' ) { elementAddClass( child, 'txt' ); continue; } } } /** Returns the title of the index page, based on the current location. * * @param rootTitle title to return if the location is the root * (which would otherwise yield an empty title) */ function indexTitle( rootTitle ) { var title = relativePathFromRoot(); title = title.replace( /\/_autoindex-summary\.[a-z]+$/, "" ); // chop the name of the file when viewing footer (_autoindex-summary file) alone if( title == '' ) return rootTitle; var subrootTitle; subrootTitle = 'project/outcast'; if( title == subrootTitle ) { title = titleOutcast; return title; } subrootTitle = 'project/Textbender'; if( title.indexOf(subrootTitle) == 0 ) { if( title == subrootTitle ) title = 'textbender'; else title = 't' + title.substring( subrootTitle.length ); return title; } subrootTitle = 'project/Votorola'; if( title.indexOf(subrootTitle) == 0 ) { if( title == subrootTitle ) title = titleVotorola; else title = 'v' + title.substring( subrootTitle.length ); return title; } return title; } /** Returns the relative path of the current location from the site root. * Any leading or trailing / is stripped. */ function relativePathFromRoot() { var path = location.pathname; path = path.replace( /^\/?(.*?)\/?$/, "$1" ); // chop any leading and trailing '/' return path; } /** Removes from the Apache autoindex listing the line that contains the specified 'a' * element. Only tested on lines that index directories. * * @return the last node of the previous line. */ function removeFromListing( a ) { var parent = a.parentNode; var node = a; node = node.previousSibling; // text (space) node = node.previousSibling; // img (icon) node = node.previousSibling; // end of previous line (always present if only as header line) parent.removeChild( node.nextSibling ); // img (icon) parent.removeChild( node.nextSibling ); // text (space) parent.removeChild( node.nextSibling ); // a parent.removeChild( node.nextSibling ); // text (trailer) return node; } /** Replaces the text after an 'a' element of the Apache autoindex listing. */ function replaceAfterListingA( a, replacementString ) { var textAfterA = a.nextSibling; // textAfterA.replaceData( 0, 999, replacementString + '\n\r' ); // Number.MAX_VALUE fails here ////// fails on IE (JS does not convert to \r\n automatically?) // var data = textAfterA.data.replace( /^.*($)/m, replacementString + '$1' ); // textAfterA.data = data; ////// fails on IE, the same way as plain '\n' textAfterA.replaceData( 0, 999, replacementString + '\n\r' ); // Number.MAX_VALUE fails here ////// '\n\r' above is the reverse of what it ought to be, but amazingly this is the only thing that works on IE7. // BUG. When used on last item in the list, extra vertical space appears (Firefox 2). // Maybe because of the funny newline encoding '\n\r'? } var titleVotorola = 'Votorola source files'; var titleOutcast = 'Outcast voting network'; /** Writes the document header and title. Called when locally viewing footer * (_autoindex-summary.html file). Results in a document that mimics (somewhat) * Apache's complete autoindex output (without the actual index). *
* Works only for HTML, not XHTML. The document needs a