Location: PHPKode > projects > WB News > admin/js/directory.js.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2008                          #||
||#     Created: 28th Jan 2008                           #||
||#     Filename: directory.js.php                       #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *	@version $Id: directory.js.php,v 1.1.2.2 2008/06/21 03:18:27 pmcilwaine Exp $
 */

?>
addEvent( window, 'load', function() {
	var query = new String(window.location).split( "?" );
	var url = query.shift();
	query.push( "ajax=1" );
	query.push( "curdir=" + opener.document.forms[0].themepath.value );

	var xmlhttp = new AJAX();
	xmlhttp.open( "GET", url + "?" + query.join( "&" ), true );
	xmlhttp.onreadystatechange = function() {
		if ( xmlhttp.readyState == 4 ) {
			if ( xmlhttp.status == 200 ) {
				Directory( xmlhttp );
			} else {
				alert( "Couldn't contact server" );
			}
		}
	};
	xmlhttp.send( null );
}, false);

function Directory( xmlObj )
{
	if ( xmlObj.responseXML ) {
		HTMLFormat(
			xmlObj.responseXML.getElementsByTagName( "dirs" )[0],
			xmlObj.responseXML.getElementsByTagName( "dirs" )[0].getElementsByTagName("dir")
			);
	}
}

function HTMLFormat( parentXML, dirXML )
{
	var struct = document.getElementById( "structure" );
	removeElements( struct );

	/** work on parent node **/
	var pEl = document.createElement( "div" );
	pEl.id = "parentnode";

	pEl.onclick = function() {
		path = this.innerHTML.split( "/" );
		if ( path.length == 1 ) {
			return;
		} else {
			path.shift();
			opener.document.forms[0].themepath.value = path.join( "/" );
		}
	};

	pEl.appendChild( document.createTextNode( parentXML.getAttribute( "current" ) ) );
	struct.appendChild( pEl );

	/** work on dirs **/
	var node, _self;
	for ( var i = 0; i < dirXML.length; i = i + 1 ) {
		_self = dirXML[i];

		node = document.createElement( "div" );
		node.className = "dir";

		if ( "false" == dirXML[i].getAttribute( "enabled" ) ) {
			node.className += " parent";
		}

		node["xml"] = dirXML[i];

		node.onclick = function() {
			if ( "" == this["xml"].getAttribute("url") ) {
				return;
			}

			var path = this["xml"].getAttribute("url").split("/");
			path.shift();

			var query = new String(window.location).split( "?" );
			var url = query.shift();
			query.push( "ajax=1" );
			query.push( "curdir=" + path.join( "/" ) );

			var xmlhttp = new AJAX();
			xmlhttp.open( "GET", url + "?" + query.join( "&" ), true );
			xmlhttp.onreadystatechange = function() {
				if ( xmlhttp.readyState == 4 ) {
					if ( xmlhttp.status == 200 ) {
						Directory( xmlhttp );
					} else {
						alert( "Couldn't contact server" );
					}
				}
			};
			xmlhttp.send( null );
		};

		node.appendChild( document.createTextNode( dirXML[i].firstChild.nodeValue ) );
		struct.appendChild( node );
	}
}

function removeElements( o )
{
	/** just clean out **/
	o.innerHTML = "";
}
Return current item: WB News