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

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2008                          #||
||#     Created: 3rd Feb 2008                            #||
||#     Filename: image-directory.js.php                 #||
||#                                                      #||
||########################################################||
/*========================================================*/

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

?>
window.onload = function() {
	var query = new String(window.location).split( "?" );
	var url = query.shift();
	query.push( "ajax=1" );

	var mycurdir = query[0].split("&"), v = "";
	for ( var i = 0; i < mycurdir.length; i++ ) {
		if ( mycurdir[i].substring( 0, 6) == "curdir" ) {
			v = mycurdir[i].split("=")[1];
		}
	}

	if ( "" == v ) {
		v = opener.document.forms[0].image.value;
		v = v.substring( 0, v.lastIndexOf("/") );
	}
	query.push( "curdir=" + v );

	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 );
};

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.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" );
		if ( "dir" == dirXML[i].getAttribute("type") ) {
			node.className = "dir";
		} else {
			node.className = "file";
		}

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

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

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

			if ( "file" == this["xml"].getAttribute("type") ) {
				opener.document.forms[0].image.value = this["xml"].getAttribute("url");
			}

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

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

			if ( document.forms[0].curdir ) {
				document.forms[0].curdir.value = 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