You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/05/13 18:37:00 UTC

svn commit: r406128 [10/27] - in /tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo: ./ src/ src/animation/ src/collections/ src/compat/ src/crypto/ src/data/ src/data/format/ src/data/provider/ src/debug/ src/dnd/ src/event/ sr...

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js Sat May 13 09:36:25 2006
@@ -0,0 +1,361 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+// make jsc shut up (so we can use jsc to sanity check the code even if it will never run it).
+/*@cc_on
+@if (@_jscript_version >= 7)
+var window; var XMLHttpRequest;
+@end
+@*/
+
+if(typeof window == 'undefined'){
+	dojo.raise("no window object");
+}
+
+// attempt to figure out the path to dojo if it isn't set in the config
+(function() {
+	// before we get any further with the config options, try to pick them out
+	// of the URL. Most of this code is from NW
+	if(djConfig.allowQueryConfig){
+		var baseUrl = document.location.toString(); // FIXME: use location.query instead?
+		var params = baseUrl.split("?", 2);
+		if(params.length > 1){
+			var paramStr = params[1];
+			var pairs = paramStr.split("&");
+			for(var x in pairs){
+				var sp = pairs[x].split("=");
+				// FIXME: is this eval dangerous?
+				if((sp[0].length > 9)&&(sp[0].substr(0, 9) == "djConfig.")){
+					var opt = sp[0].substr(9);
+					try{
+						djConfig[opt]=eval(sp[1]);
+					}catch(e){
+						djConfig[opt]=sp[1];
+					}
+				}
+			}
+		}
+	}
+
+	if(((djConfig["baseScriptUri"] == "")||(djConfig["baseRelativePath"] == "")) &&(document && document.getElementsByTagName)){
+		var scripts = document.getElementsByTagName("script");
+		var rePkg = /(__package__|dojo|bootstrap1)\.js([\?\.]|$)/i;
+		for(var i = 0; i < scripts.length; i++) {
+			var src = scripts[i].getAttribute("src");
+			if(!src) { continue; }
+			var m = src.match(rePkg);
+			if(m) {
+				root = src.substring(0, m.index);
+				if(src.indexOf("bootstrap1") > -1) { root += "../"; }
+				if(!this["djConfig"]) { djConfig = {}; }
+				if(djConfig["baseScriptUri"] == "") { djConfig["baseScriptUri"] = root; }
+				if(djConfig["baseRelativePath"] == "") { djConfig["baseRelativePath"] = root; }
+				break;
+			}
+		}
+	}
+
+	// fill in the rendering support information in dojo.render.*
+	var dr = dojo.render;
+	var drh = dojo.render.html;
+	var drs = dojo.render.svg;
+	var dua = drh.UA = navigator.userAgent;
+	var dav = drh.AV = navigator.appVersion;
+	var t = true;
+	var f = false;
+	drh.capable = t;
+	drh.support.builtin = t;
+
+	dr.ver = parseFloat(drh.AV);
+	dr.os.mac = dav.indexOf("Macintosh") >= 0;
+	dr.os.win = dav.indexOf("Windows") >= 0;
+	// could also be Solaris or something, but it's the same browser
+	dr.os.linux = dav.indexOf("X11") >= 0;
+
+	drh.opera = dua.indexOf("Opera") >= 0;
+	drh.khtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0);
+	drh.safari = dav.indexOf("Safari") >= 0;
+	var geckoPos = dua.indexOf("Gecko");
+	drh.mozilla = drh.moz = (geckoPos >= 0)&&(!drh.khtml);
+	if (drh.mozilla) {
+		// gecko version is YYYYMMDD
+		drh.geckoVersion = dua.substring(geckoPos + 6, geckoPos + 14);
+	}
+	drh.ie = (document.all)&&(!drh.opera);
+	drh.ie50 = drh.ie && dav.indexOf("MSIE 5.0")>=0;
+	drh.ie55 = drh.ie && dav.indexOf("MSIE 5.5")>=0;
+	drh.ie60 = drh.ie && dav.indexOf("MSIE 6.0")>=0;
+
+	dr.vml.capable=drh.ie;
+	drs.capable = f;
+	drs.support.plugin = f;
+	drs.support.builtin = f;
+	if (document.implementation
+		&& document.implementation.hasFeature
+		&& document.implementation.hasFeature("org.w3c.dom.svg", "1.0")
+	){
+		drs.capable = t;
+		drs.support.builtin = t;
+		drs.support.plugin = f;
+	}
+})();
+
+dojo.hostenv.startPackage("dojo.hostenv");
+
+dojo.render.name = dojo.hostenv.name_ = 'browser';
+dojo.hostenv.searchIds = [];
+
+// These are in order of decreasing likelihood; this will change in time.
+var DJ_XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
+
+dojo.hostenv.getXmlhttpObject = function(){
+    var http = null;
+	var last_e = null;
+	try{ http = new XMLHttpRequest(); }catch(e){}
+    if(!http){
+		for(var i=0; i<3; ++i){
+			var progid = DJ_XMLHTTP_PROGIDS[i];
+			try{
+				http = new ActiveXObject(progid);
+			}catch(e){
+				last_e = e;
+			}
+
+			if(http){
+				DJ_XMLHTTP_PROGIDS = [progid];  // so faster next time
+				break;
+			}
+		}
+
+		/*if(http && !http.toString) {
+			http.toString = function() { "[object XMLHttpRequest]"; }
+		}*/
+	}
+
+	if(!http){
+		return dojo.raise("XMLHTTP not available", last_e);
+	}
+
+	return http;
+}
+
+/**
+ * Read the contents of the specified uri and return those contents.
+ *
+ * @param uri A relative or absolute uri. If absolute, it still must be in the
+ * same "domain" as we are.
+ *
+ * @param async_cb If not specified, load synchronously. If specified, load
+ * asynchronously, and use async_cb as the progress handler which takes the
+ * xmlhttp object as its argument. If async_cb, this function returns null.
+ *
+ * @param fail_ok Default false. If fail_ok and !async_cb and loading fails,
+ * return null instead of throwing.
+ */
+dojo.hostenv.getText = function(uri, async_cb, fail_ok){
+
+	var http = this.getXmlhttpObject();
+
+	if(async_cb){
+		http.onreadystatechange = function(){
+			if((4==http.readyState)&&(http["status"])){
+				if(http.status==200){
+					// dojo.debug("LOADED URI: "+uri);
+					async_cb(http.responseText);
+				}
+			}
+		}
+	}
+
+	http.open('GET', uri, async_cb ? true : false);
+	try {
+		http.send(null);
+	} catch (e) {
+		if (fail_ok && !async_cb) {
+			return null;
+		} else {
+			throw e;
+		}
+	}
+	if(async_cb){
+		return null;
+	}
+
+	return http.responseText;
+}
+
+/*
+ * It turns out that if we check *right now*, as this script file is being loaded,
+ * then the last script element in the window DOM is ourselves.
+ * That is because any subsequent script elements haven't shown up in the document
+ * object yet.
+ */
+ /*
+function dj_last_script_src() {
+    var scripts = window.document.getElementsByTagName('script');
+    if(scripts.length < 1){
+		dojo.raise("No script elements in window.document, so can't figure out my script src");
+	}
+    var script = scripts[scripts.length - 1];
+    var src = script.src;
+    if(!src){
+		dojo.raise("Last script element (out of " + scripts.length + ") has no src");
+	}
+    return src;
+}
+
+if(!dojo.hostenv["library_script_uri_"]){
+	dojo.hostenv.library_script_uri_ = dj_last_script_src();
+}
+*/
+
+dojo.hostenv.defaultDebugContainerId = 'dojoDebug';
+dojo.hostenv._println_buffer = [];
+dojo.hostenv._println_safe = false;
+dojo.hostenv.println = function (line){
+	if(!dojo.hostenv._println_safe){
+		dojo.hostenv._println_buffer.push(line);
+	}else{
+		try {
+			var console = document.getElementById(djConfig.debugContainerId ?
+				djConfig.debugContainerId : dojo.hostenv.defaultDebugContainerId);
+			if(!console) { console = document.getElementsByTagName("body")[0] || document.body; }
+
+			var div = document.createElement("div");
+			div.appendChild(document.createTextNode(line));
+			console.appendChild(div);
+		} catch (e) {
+			try{
+				// safari needs the output wrapped in an element for some reason
+				document.write("<div>" + line + "</div>");
+			}catch(e2){
+				window.status = line;
+			}
+		}
+	}
+}
+
+dojo.addOnLoad(function(){
+	dojo.hostenv._println_safe = true;
+	while(dojo.hostenv._println_buffer.length > 0){
+		dojo.hostenv.println(dojo.hostenv._println_buffer.shift());
+	}
+});
+
+function dj_addNodeEvtHdlr (node, evtName, fp, capture){
+	var oldHandler = node["on"+evtName] || function(){};
+	node["on"+evtName] = function(){
+		fp.apply(node, arguments);
+		oldHandler.apply(node, arguments);
+	}
+	return true;
+}
+
+
+/* Uncomment this to allow init after DOMLoad, not after window.onload
+
+// Mozilla exposes the event we could use
+if (dojo.render.html.mozilla) {
+   document.addEventListener("DOMContentLoaded", dj_load_init, null);
+}
+// for Internet Explorer. readyState will not be achieved on init call, but dojo doesn't need it
+//Tighten up the comments below to allow init after DOMLoad, not after window.onload
+/ * @cc_on @ * /
+/ * @if (@_win32)
+    document.write("<script defer>dj_load_init()<"+"/script>");
+/ * @end @ * /
+*/
+
+// default for other browsers
+// potential TODO: apply setTimeout approach for other browsers
+// that will cause flickering though ( document is loaded and THEN is processed)
+// maybe show/hide required in this case..
+// TODO: other browsers may support DOMContentLoaded/defer attribute. Add them to above.
+dj_addNodeEvtHdlr(window, "load", function(){
+	// allow multiple calls, only first one will take effect
+	if(arguments.callee.initialized){ return; }
+	arguments.callee.initialized = true;
+
+	var initFunc = function(){
+		//perform initialization
+		if(dojo.render.html.ie){
+			dojo.hostenv.makeWidgets();
+		}
+	};
+
+	if(dojo.hostenv.inFlightCount == 0){
+		initFunc();
+		dojo.hostenv.modulesLoaded();
+	}else{
+		dojo.addOnLoad(initFunc);
+	}
+});
+
+dojo.hostenv.makeWidgets = function(){
+	// you can put searchIds in djConfig and dojo.hostenv at the moment
+	// we should probably eventually move to one or the other
+	var sids = [];
+	if(djConfig.searchIds && djConfig.searchIds.length > 0) {
+		sids = sids.concat(djConfig.searchIds);
+	}
+	if(dojo.hostenv.searchIds && dojo.hostenv.searchIds.length > 0) {
+		sids = sids.concat(dojo.hostenv.searchIds);
+	}
+
+	if((djConfig.parseWidgets)||(sids.length > 0)){
+		if(dojo.evalObjPath("dojo.widget.Parse")){
+			// we must do this on a delay to avoid:
+			//	http://www.shaftek.org/blog/archives/000212.html
+			// IE is such a tremendous peice of shit.
+			try{
+				var parser = new dojo.xml.Parse();
+				if(sids.length > 0){
+					for(var x=0; x<sids.length; x++){
+						var tmpNode = document.getElementById(sids[x]);
+						if(!tmpNode){ continue; }
+						var frag = parser.parseElement(tmpNode, null, true);
+						dojo.widget.getParser().createComponents(frag);
+					}
+				}else if(djConfig.parseWidgets){
+					var frag  = parser.parseElement(document.getElementsByTagName("body")[0] || document.body, null, true);
+					dojo.widget.getParser().createComponents(frag);
+				}
+			}catch(e){
+				dojo.debug("auto-build-widgets error:", e);
+			}
+		}
+	}
+}
+
+dojo.addOnLoad(function(){
+	if(!dojo.render.html.ie) {
+		dojo.hostenv.makeWidgets();
+	}
+});
+
+try {
+	if (dojo.render.html.ie) {
+		//	easier and safer VML addition.  Thanks Emil!
+		document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
+		document.createStyleSheet().addRule("v\\:*", "behavior:url(#default#VML)");
+	}
+} catch (e) { }
+
+// stub, over-ridden by debugging code. This will at least keep us from
+// breaking when it's not included
+dojo.hostenv.writeIncludes = function(){}
+
+dojo.byId = function(id, doc){
+	if(id && (typeof id == "string" || id instanceof String)){
+		if(!doc){ doc = document; }
+		return doc.getElementById(id);
+	}
+	return id; // assume it's a node
+}

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js Sat May 13 09:36:25 2006
@@ -0,0 +1,197 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.render.name = dojo.hostenv.name_ = "dashboard";
+
+dojo.hostenv.println = function(/*String*/ message){
+	// summary: Prints a message to the OS X console
+	return alert(message); // null
+}
+
+dojo.hostenv.getXmlhttpObject = function(/*Object*/ kwArgs){
+	// summary: Returns the appropriate transfer object for the call type
+	if(widget.system && kwArgs){
+		if((kwArgs.contentType && kwArgs.contentType.indexOf("text/") != 0) || (kwArgs.headers && kwArgs.headers["content-type"] && kwArgs.headers["content-type"].indexOf("text/") != 0)){
+			var curl = new dojo.hostenv.CurlRequest;
+			curl._save = true;
+			return curl;
+		}else if(kwArgs.method && kwArgs.method.toUpperCase() == "HEAD"){
+			return new dojo.hostenv.CurlRequest;
+		}else if(kwArgs.headers && kwArgs.header.referer){
+			return new dojo.hostenv.CurlRequest; 
+		}
+	}
+	return new XMLHttpRequest; // XMLHttpRequest
+}
+
+dojo.hostenv.CurlRequest = function(){
+	// summary: Emulates the XMLHttpRequest Object
+	this.onreadystatechange = null;
+	this.readyState = 0;
+	this.responseText = "";
+	this.responseXML = null;
+	this.status = 0;
+	this.statusText = "";
+	this._method = "";
+	this._url = "";
+	this._async = true;
+	this._referrer = "";
+	this._headers = [];
+	this._save = false;
+	this._responseHeader = "";
+	this._responseHeaders = {};
+	this._fileName = "";
+	this._username = "";
+	this._password = "";
+}
+
+dojo.hostenv.CurlRequest.prototype.open = function(/*String*/ method, /*URL*/ url, /*Boolean?*/ async, /*String?*/ username, /*String?*/ password){
+	this._method = method;
+	this._url = url;
+	if(async){
+		this._async = async;
+	}
+	if(username){
+		this._username = username;
+	}
+	if(password){
+		this._password = password;
+	}
+}
+
+dojo.hostenv.CurlRequest.prototype.setRequestHeader = function(/*String*/ label, /*String*/ value){
+	switch(label){
+		case "Referer":
+			this._referrer = value;
+			break;
+		case "content-type":
+			break;
+		default:
+			this._headers.push(label + "=" + value);
+			break;
+	}
+}
+
+dojo.hostenv.CurlRequest.prototype.getAllResponseHeaders = function(){
+	return this._responseHeader; // String
+}
+
+dojo.hostenv.CurlRequest.prototype.getResponseHeader = function(/*String*/ headerLabel){
+	return this._responseHeaders[headerLabel]; // String
+}
+
+// -sS = Show only errors in errorString
+// -i = Display headers with return
+// -e = Referrer URI
+// -H = Headers
+// -d = data to be sent (forces POST)
+// -G = forces GET
+// -o = Writes to file (in the cache directory)
+// -I = Only load headers
+// -u = user:password
+dojo.hostenv.CurlRequest.prototype.send = function(/*String*/ content){
+	this.readyState = 1;
+	if(this.onreadystatechange){
+		this.onreadystatechange.call(this);
+	}
+	var query = {sS: ""};
+	if(this._referrer){
+		query.e = this._referrer;
+	}
+	if(this._headers.length){
+		query.H = this._headers.join("&");
+	}
+	if(this._username){
+		if(this._password){
+			query.u = this._username + ":" + this._password;
+		}else{
+			query.u = this._username;
+		}
+	}
+	if(content){
+		query.d = this.content;
+		if(this._method != "POST"){
+			query.G = "";
+		}
+	}
+	if(this._method == "HEAD"){
+		query.I = "";
+	}else{
+		if(this._save){
+			query.I = ""; // Get the headers in the initial query
+		}else{
+			query.i = "";
+		}
+	}
+
+	var system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
+	this.readyState = 2;
+	if(this.onreadystatechange){
+		this.onreadystatechange.call(this);
+	}
+	if(system.errorString){
+		this.responseText = system.errorString;
+		this.status = 0;
+	}else{
+		if(this._save){
+			this._responseHeader = system.outputString;
+		}else{
+			var split = system.outputString.replace(/\r/g, "").split("\n\n", 2);
+			this._responseHeader = split[0];
+			this.responseText = split[1];
+		}
+		split = this._responseHeader.split("\n");
+		this.statusText = split.shift();
+		this.status = this.statusText.split(" ")[1];
+		for(var i = 0, header; header = split[i]; i++){
+			var header_split = header.split(": ", 2);
+			this._responseHeaders[header_split[0]] = header_split[1];
+		}
+		if(this._save){
+			widget.system("/bin/mkdir cache", null);
+			// First, make a file name
+			this._fileName = this._url.split("/").pop().replace(/\W/g, "");
+			// Then, get its extension
+			this._fileName += "." + this._responseHeaders["Content-Type"].replace(/[\r\n]/g, "").split("/").pop()
+			delete query.I;
+			query.o = "cache/" + this._fileName; // Tell it where to be saved.
+			system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
+			if(!system.errorString){
+				this.responseText = "cache/" + this._fileName;
+			}
+		}else if(this._method == "HEAD"){
+			this.responseText = this._responseHeader;
+		}
+	}
+
+	this.readyState = 4;
+	if(this.onreadystatechange){
+		this.onreadystatechange.call(this);
+	}
+}
+
+dojo.hostenv.CurlRequest._formatCall = function(query, url){
+	var call = ["/usr/bin/curl"];
+	for(var key in query){
+		if(query[key] != ""){
+			call.push("-" + key + " '" + query[key].replace(/'/g, "\'") + "'");
+		}else{
+			call.push("-" + key);
+		}
+	}
+	call.push("'" + url.replace(/'/g, "\'") + "'");
+	return call.join(" ");
+}
+
+dojo.hostenv.exit = function(){
+	if(widget.system){
+		widget.system("/bin/rm -rf cache/*", null);
+	}
+}

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js Sat May 13 09:36:25 2006
@@ -0,0 +1,76 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+/*
+ * JScript .NET jsc
+ *
+ */
+
+dojo.hostenv.name_ = 'jsc';
+
+// Sanity check this is the right hostenv.
+// See the Rotor source code jscript/engine/globalobject.cs for what globals
+// are available.
+if((typeof ScriptEngineMajorVersion != 'function')||(ScriptEngineMajorVersion() < 7)){
+	dojo.raise("attempt to use JScript .NET host environment with inappropriate ScriptEngine"); 
+}
+
+// for more than you wanted to know about why this import is required even if
+// we fully qualify all symbols, see
+// http://groups.google.com/groups?th=f050c7aeefdcbde2&rnum=12
+import System;
+
+dojo.hostenv.getText = function(uri){
+	if(!System.IO.File.Exists(uri)){
+		// dojo.raise("No such file '" + uri + "'");
+		return 0;
+	}
+	var reader = new System.IO.StreamReader(uri);
+	var contents : String = reader.ReadToEnd();
+	return contents;
+}
+
+dojo.hostenv.loadUri = function(uri){
+	var contents = this.getText(uri);
+	if(!contents){
+		dojo.raise("got no back contents from uri '" + uri + "': " + contents);
+	}
+	// TODO: in JScript .NET, eval will not affect the symbol table of the current code?
+	var value = dj_eval(contents);
+	dojo.debug("jsc eval of contents returned: ", value);
+	return 1;
+
+	// for an example doing runtime code compilation, see:
+	// http://groups.google.com/groups?selm=eQ1aeciCBHA.1644%40tkmsftngp05&rnum=6
+	// Microsoft.JScript or System.CodeDom.Compiler ?
+	// var engine = new Microsoft.JScript.Vsa.VsaEngine()
+	// what about loading a js file vs. a dll?
+	// GetObject("script:" . uri);
+}
+
+/* The System.Environment object is useful:
+    print ("CommandLine='" + System.Environment.CommandLine + "' " +
+	   "program name='" + System.Environment.GetCommandLineArgs()[0] + "' " +
+	   "CurrentDirectory='" + System.Environment.CurrentDirectory + "' " +
+	   "StackTrace='" + System.Environment.StackTrace + "'");
+*/
+
+// same as System.Console.WriteLine
+// sigh; Rotor treats symbol "print" at parse time without actually putting it
+// in the builtin symbol table.
+// Note that the print symbol is not available if jsc is run with the "/print-"
+// option.
+dojo.hostenv.println = function(s){
+	print(s); // = print
+}
+
+dojo.hostenv.getLibraryScriptUri = function(){
+	return System.Environment.GetCommandLineArgs()[0];
+}

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js Sat May 13 09:36:25 2006
@@ -0,0 +1,190 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+/*
+* Rhino host environment
+*/
+
+// make jsc shut up (so we can use jsc for sanity checking) 
+/*@cc_on
+@if (@_jscript_version >= 7)
+var loadClass; var print; var load; var quit; var version; var Packages; var java;
+@end
+@*/
+
+// TODO: not sure what we gain from the next line, anyone?
+//if (typeof loadClass == 'undefined') { dojo.raise("attempt to use Rhino host environment when no 'loadClass' global"); }
+
+dojo.render.name = dojo.hostenv.name_ = 'rhino';
+dojo.hostenv.getVersion = function() {return version()};
+
+// see comments in spidermonkey loadUri
+dojo.hostenv.loadUri = function(uri, cb){
+	dojo.debug("uri: "+uri);
+	try{
+		// FIXME: what about remote URIs?
+		var found = true;
+		if(!(new java.io.File(uri)).exists()){
+			try{
+				// try it as a file first, URL second
+				(new java.io.URL(uri)).openStream();
+			}catch(e){
+				found = false;
+			}
+		}
+		if(!found){
+			dojo.debug(uri+" does not exist");
+			if(cb){ cb(0); }
+			return 0;
+		}
+		var ok = load(uri);
+		// dojo.debug(typeof ok);
+		dojo.debug("rhino load('", uri, "') returned. Ok: ", ok);
+		if(cb){ cb(1); }
+		return 1;
+	}catch(e){
+		dojo.debug("rhino load('", uri, "') failed");
+		if(cb){ cb(0); }
+		return 0;
+	}
+}
+
+dojo.hostenv.println = print;
+dojo.hostenv.exit = function(exitcode){ 
+	quit(exitcode);
+}
+
+// Hack to determine current script...
+//
+// These initial attempts failed:
+//   1. get an EcmaError and look at e.getSourceName(): try {eval ("static in return")} catch(e) { ...
+//   Won't work because NativeGlobal.java only does a put of "name" and "message", not a wrapped reflecting object.
+//   Even if the EcmaError object had the sourceName set.
+//  
+//   2. var e = Packages.org.mozilla.javascript.Context.getCurrentContext().reportError('');
+//   Won't work because it goes directly to the errorReporter, not the return value.
+//   We want context.interpreterSourceFile and context.interpreterLine, which are used in static Context.getSourcePositionFromStack
+//   (set by Interpreter.java at interpretation time, if in interpreter mode).
+//
+//   3. var e = Packages.org.mozilla.javascript.Context.getCurrentContext().reportRuntimeError('');
+//   This returns an object, but e.message still does not have source info.
+//   In compiler mode, perhaps not set; in interpreter mode, perhaps not used by errorReporter?
+//
+// What we found works is to do basically the same hack as is done in getSourcePositionFromStack,
+// making a new java.lang.Exception() and then calling printStackTrace on a string stream.
+// We have to parse the string for the .js files (different from the java files).
+// This only works however in compiled mode (-opt 0 or higher).
+// In interpreter mode, entire stack is java.
+// When compiled, printStackTrace is like:
+// java.lang.Exception
+//	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
+//	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
+//	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
+//	at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
+//	at org.mozilla.javascript.NativeJavaClass.constructSpecific(NativeJavaClass.java:228)
+//	at org.mozilla.javascript.NativeJavaClass.construct(NativeJavaClass.java:185)
+//	at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:1269)
+//	at org.mozilla.javascript.gen.c2.call(/Users/mda/Sites/burstproject/testrhino.js:27)
+//    ...
+//	at org.mozilla.javascript.tools.shell.Main.main(Main.java:76)
+//
+// Note may get different answers based on:
+//    Context.setOptimizationLevel(-1)
+//    Context.setGeneratingDebug(true)
+//    Context.setGeneratingSource(true) 
+//
+// Some somewhat helpful posts:
+//    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=9v9n0g%246gr1%40ripley.netscape.com
+//    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=3BAA2DC4.6010702%40atg.com
+//
+// Note that Rhino1.5R5 added source name information in some exceptions.
+// But this seems not to help in command-line Rhino, because Context.java has an error reporter
+// so no EvaluationException is thrown.
+
+// do it by using java java.lang.Exception
+function dj_rhino_current_script_via_java(depth) {
+    var optLevel = Packages.org.mozilla.javascript.Context.getCurrentContext().getOptimizationLevel();  
+    if (optLevel == -1) dojo.unimplemented("getCurrentScriptURI (determine current script path for rhino when interpreter mode)", '');
+    var caw = new java.io.CharArrayWriter();
+    var pw = new java.io.PrintWriter(caw);
+    var exc = new java.lang.Exception();
+    var s = caw.toString();
+    // we have to exclude the ones with or without line numbers because they put double entries in:
+    //   at org.mozilla.javascript.gen.c3._c4(/Users/mda/Sites/burstproject/burst/Runtime.js:56)
+    //   at org.mozilla.javascript.gen.c3.call(/Users/mda/Sites/burstproject/burst/Runtime.js)
+    var matches = s.match(/[^\(]*\.js\)/gi);
+    if(!matches){
+		throw Error("cannot parse printStackTrace output: " + s);
+	}
+
+    // matches[0] is entire string, matches[1] is this function, matches[2] is caller, ...
+    var fname = ((typeof depth != 'undefined')&&(depth)) ? matches[depth + 1] : matches[matches.length - 1];
+    var fname = matches[3];
+	if(!fname){ fname = matches[1]; }
+    // print("got fname '" + fname + "' from stack string '" + s + "'");
+    if (!fname) throw Error("could not find js file in printStackTrace output: " + s);
+    //print("Rhino getCurrentScriptURI returning '" + fname + "' from: " + s); 
+    return fname;
+}
+
+// UNUSED: leverage new support in native exception for getSourceName
+/*
+function dj_rhino_current_script_via_eval_exception() {
+    var exc;
+    // 'ReferenceError: "undefinedsymbol" is not defined.'
+    try {eval ("undefinedsymbol()") } catch(e) {exc = e;}
+    // 'Error: whatever'
+    // try{throw Error("whatever");} catch(e) {exc = e;}
+    // 'SyntaxError: identifier is a reserved word'
+    // try {eval ("static in return")} catch(e) { exc = e; }
+    print("got exception: '" + exc + "'");
+    print("exc.stack=" + (typeof exc.stack));
+    var sn = exc.getSourceName();
+    print("SourceName=" + sn);
+    return sn;
+} 
+*/
+
+// reading a file from disk in Java is a humiliating experience by any measure.
+// Lets avoid that and just get the freaking text
+function readText(uri){
+	// NOTE: we intentionally avoid handling exceptions, since the caller will
+	// want to know
+	var jf = new java.io.File(uri);
+	var sb = new java.lang.StringBuffer();
+	var input = new java.io.BufferedReader(new java.io.FileReader(jf));
+	var line = "";
+	while((line = input.readLine()) != null){
+		sb.append(line);
+		sb.append(java.lang.System.getProperty("line.separator"));
+	}
+	return sb.toString();
+}
+
+// call this now because later we may not be on the top of the stack
+if(!djConfig.libraryScriptUri.length){
+	try{
+		djConfig.libraryScriptUri = dj_rhino_current_script_via_java(1);
+	}catch(e){
+		// otherwise just fake it
+		if(djConfig["isDebug"]){
+			print("\n");
+			print("we have no idea where Dojo is located from.");
+			print("Please try loading rhino in a non-interpreted mode or set a");
+			print("\n	djConfig.libraryScriptUri\n");
+			print("Setting the dojo path to './'");
+			print("This is probably wrong!");
+			print("\n");
+			print("Dojo will try to load anyway");
+		}
+		djConfig.libraryScriptUri = "./";
+	}
+}
+

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js Sat May 13 09:36:25 2006
@@ -0,0 +1,79 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+/*
+ * SpiderMonkey host environment
+ */
+
+dojo.hostenv.name_ = 'spidermonkey';
+
+dojo.hostenv.println = print;
+dojo.hostenv.exit = function(exitcode){ 
+	quit(exitcode); 
+}
+
+// version() returns 0, sigh. and build() returns nothing but just prints.
+dojo.hostenv.getVersion = function(){ return version(); }
+
+// make jsc shut up (so we can use jsc for sanity checking) 
+/*@cc_on
+@if (@_jscript_version >= 7)
+var line2pc; var print; var load; var quit;
+@end
+@*/
+
+if(typeof line2pc == 'undefined'){
+	dojo.raise("attempt to use SpiderMonkey host environment when no 'line2pc' global");
+}
+
+/*
+ * This is a hack that determines the current script file by parsing a generated
+ * stack trace (relying on the non-standard "stack" member variable of the
+ * SpiderMonkey Error object).
+ * If param depth is passed in, it'll return the script file which is that far down
+ * the stack, but that does require that you know how deep your stack is when you are
+ * calling.
+ */
+function dj_spidermonkey_current_file(depth){
+    var s = '';
+    try{
+		throw Error("whatever");
+	}catch(e){
+		s = e.stack;
+	}
+    // lines are like: bu_getCurrentScriptURI_spidermonkey("ScriptLoader.js")@burst/Runtime.js:101
+    var matches = s.match(/[^@]*\.js/gi);
+    if(!matches){ 
+		dojo.raise("could not parse stack string: '" + s + "'");
+	}
+    var fname = (typeof depth != 'undefined' && depth) ? matches[depth + 1] : matches[matches.length - 1];
+    if(!fname){ 
+		dojo.raise("could not find file name in stack string '" + s + "'");
+	}
+    //print("SpiderMonkeyRuntime got fname '" + fname + "' from stack string '" + s + "'");
+    return fname;
+}
+
+// call this now because later we may not be on the top of the stack
+if(!dojo.hostenv.library_script_uri_){ 
+	dojo.hostenv.library_script_uri_ = dj_spidermonkey_current_file(0); 
+}
+
+dojo.hostenv.loadUri = function(uri){
+	// spidermonkey load() evaluates the contents into the global scope (which
+	// is what we want).
+	// TODO: sigh, load() does not return a useful value. 
+	// Perhaps it is returning the value of the last thing evaluated?
+	var ok = load(uri);
+	// dojo.debug("spidermonkey load(", uri, ") returned ", ok);
+	return 1;
+}
+
+

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_svg.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_svg.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_svg.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_svg.js Sat May 13 09:36:25 2006
@@ -0,0 +1,223 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+//	hostenv_svg
+if(typeof window == 'undefined'){
+	dojo.raise("attempt to use adobe svg hostenv when no window object");
+}
+dojo.debug = function(){ 
+	if (!djConfig.isDebug) { return; }
+	var args = arguments;
+	var isJUM = dj_global["jum"];
+	var s = isJUM ? "": "DEBUG: ";
+	for (var i = 0; i < args.length; ++i){ s += args[i]; }
+	if (isJUM){ // this seems to be the only way to get JUM to "play nice"
+		jum.debug(s);
+	} else{ 
+		dojo.hostenv.println(s);
+	}
+};
+
+//	set up dojo.render.
+dojo.render.name = navigator.appName;
+dojo.render.ver = parseFloat(navigator.appVersion, 10);
+switch(navigator.platform){
+	case "MacOS":
+		dojo.render.os.osx =  true;
+		break;
+	case "Linux":
+		dojo.render.os.linux =  true;
+		break;
+	case "Windows":
+		dojo.render.os.win =  true;
+		break;
+	default:
+		dojo.render.os.linux = true;
+		break;
+};
+dojo.render.svg.capable = true;
+dojo.render.svg.support.builtin = true;
+//	FIXME the following two is a big-ass hack for now.
+dojo.render.svg.moz = ((navigator.userAgent.indexOf("Gecko") >= 0) && (!((navigator.appVersion.indexOf("Konqueror") >= 0) || (navigator.appVersion.indexOf("Safari") >= 0))));
+dojo.render.svg.adobe = (window.parseXML != null);
+
+//	agent-specific implementations.
+
+//	from old hostenv_adobesvg.
+dojo.hostenv.startPackage("dojo.hostenv");
+dojo.hostenv.println = function(s){ 
+	try {
+		var ti = document.createElement("text");
+		ti.setAttribute("x","50");
+		ti.setAttribute("y", (25 + 15 * document.getElementsByTagName("text").length));
+		ti.appendChild(document.createTextNode(s));
+		document.documentElement.appendChild(ti);
+	} catch(e){ }
+};
+dojo.hostenv.name_ = "svg";
+
+//	expected/defined by bootstrap1.js
+dojo.hostenv.setModulePrefix = function(module, prefix){ };
+dojo.hostenv.getModulePrefix = function(module){ };
+dojo.hostenv.getTextStack = [];
+dojo.hostenv.loadUriStack = [];
+dojo.hostenv.loadedUris = [];
+dojo.hostenv.modules_ = {};
+dojo.hostenv.modulesLoadedFired = false;
+dojo.hostenv.modulesLoadedListeners = [];
+dojo.hostenv.getText = function(uri, cb, data){ 
+	if (!cb) var cb = function(result){ window.alert(result); };
+	if (!data) {
+		window.getUrl(uri, cb);
+	} else {
+		window.postUrl(uri, data, cb);
+	}
+};
+dojo.hostenv.getLibaryScriptUri = function(){ };
+
+dojo.hostenv.loadUri = function(uri){ };
+dojo.hostenv.loadUriAndCheck = function(uri, module){ };
+
+//	aliased in loader.js, don't ignore
+//	we are going to kill loadModule for the first round of SVG stuff, and include shit manually.
+dojo.hostenv.loadModule = function(moduleName){
+	//	just like startPackage, but this time we're just checking to make sure it exists already.
+	var a = moduleName.split(".");
+	var currentObj = window;
+	var s = [];
+	for (var i = 0; i < a.length; i++){
+		if (a[i] == "*") continue;
+		s.push(a[i]);
+		if (!currentObj[a[i]]){
+			dojo.raise("dojo.require('" + moduleName + "'): module does not exist.");
+		} else currentObj = currentObj[a[i]];
+	}
+	return; 
+};
+dojo.hostenv.startPackage = function(moduleName){
+	var a = moduleName.split(".");
+	var currentObj = window;
+	var s = [];
+	for (var i = 0; i < a.length; i++){
+		if (a[i] == "*") continue;
+		s.push(a[i]);
+		if (!currentObj[a[i]]) currentObj[a[i]] = {};
+		currentObj = currentObj[a[i]];
+	}
+	return; 
+};
+
+//	wrapper objects for ASVG
+if (window.parseXML){
+	window.XMLSerialzer = function(){
+		//	based on WebFX RichTextControl getXHTML() function.
+		function nodeToString(n, a) {
+			function fixText(s) { return String(s).replace(/\&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;"); }
+			function fixAttribute(s) { return fixText(s).replace(/\"/g, "&quot;"); }
+			switch (n.nodeType) {
+				case 1:	{	//	ELEMENT
+					var name = n.nodeName;
+					a.push("<" + name);
+					for (var i = 0; i < n.attributes.length; i++) {
+						if (n.attributes.item(i).specified) {
+							a.push(" " + n.attributes.item(i).nodeName.toLowerCase() + "=\"" + fixAttribute(n.attributes.item(i).nodeValue) + "\"");
+						}
+					}
+					if (n.canHaveChildren || n.hasChildNodes()) {
+						a.push(">");
+						for (var i = 0; i < n.childNodes.length; i++) nodeToString(n.childNodes.item(i), a);
+						a.push("</" + name + ">\n");
+					} else a.push(" />\n");
+					break;
+				}
+				case 3: {	//	TEXT
+					a.push(fixText(n.nodeValue));
+					break;
+				}
+				case 4: {	//	CDATA
+					a.push("<![CDA" + "TA[\n" + n.nodeValue + "\n]" + "]>");
+					break;
+				}
+				case 7:{	//	PROCESSING INSTRUCTION
+					a.push(n.nodeValue);
+					if (/(^<\?xml)|(^<\!DOCTYPE)/.test(n.nodeValue)) a.push("\n");
+					break;
+				}
+				case 8:{	//	COMMENT
+					a.push("<!-- " + n.nodeValue + " -->\n");
+					break;
+				}
+				case 9:		//	DOCUMENT
+				case 11:{	//	DOCUMENT FRAGMENT
+					for (var i = 0; i < n.childNodes.length; i++) nodeToString(n.childNodes.item(i), a);
+					break;
+				}
+				default:{
+					a.push("<!--\nNot Supported:\n\n" + "nodeType: " + n.nodeType + "\nnodeName: " + n.nodeName + "\n-->");
+				}
+			}
+		}
+		this.serializeToString = function(node){
+			var a = [];
+			nodeToString(node, a);
+			return a.join("");
+		};
+	};
+
+	window.DOMParser = function(){
+		//	mimetype is basically ignored
+		this.parseFromString = function(s){
+			return parseXML(s, window.document);
+		}
+	};
+
+	window.XMLHttpRequest = function(){
+		//	we ignore the setting and getting of content-type.
+		var uri = null;
+		var method = "POST";
+		var isAsync = true;	
+		var cb = function(d){
+			this.responseText = d.content;
+			try {
+				this.responseXML = parseXML(this.responseText, window.document);
+			} catch(e){}
+			this.status = "200";
+			this.statusText = "OK";
+			if (!d.success) {
+				this.status = "500";
+				this.statusText = "Internal Server Error";
+			}
+			this.onload();
+			this.onreadystatechange();
+		};
+		this.onload = function(){};
+		this.readyState = 4;
+		this.onreadystatechange = function(){};
+		this.status = 0;
+		this.statusText = "";
+		this.responseBody = null;
+		this.responseStream = null;
+		this.responseXML = null;
+		this.responseText = null;
+		this.abort = function(){ return; };
+		this.getAllResponseHeaders = function(){ return []; };
+		this.getResponseHeader = function(n){ return null; };
+		this.setRequestHeader = function(nm, val){ };
+		this.open = function(meth, url, async){ 
+			method = meth;
+			uri = url;
+		};
+		this.send = function(data){
+			var d = data || null;
+			if (method == "GET") getURL(uri, cb);
+			else postURL(uri, data, cb);
+		};
+	};
+}

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_wsh.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_wsh.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_wsh.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_wsh.js Sat May 13 09:36:25 2006
@@ -0,0 +1,46 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+/*
+ * WSH
+ */
+
+dojo.hostenv.name_ = 'wsh';
+
+// make jsc shut up (so can sanity check)
+/*@cc_on
+@if (@_jscript_version >= 7)
+var WScript;
+@end
+@*/
+
+// make sure we are in right environment
+if(typeof WScript == 'undefined'){
+	dojo.raise("attempt to use WSH host environment when no WScript global");
+}
+
+dojo.hostenv.println = WScript.Echo;
+
+dojo.hostenv.getCurrentScriptUri = function(){
+	return WScript.ScriptFullName();
+}
+
+dojo.hostenv.getText = function(fpath){
+	var fso = new ActiveXObject("Scripting.FileSystemObject");
+	var istream = fso.OpenTextFile(fpath, 1); // iomode==1 means read only
+	if(!istream){
+		return null;
+	}
+	var contents = istream.ReadAll();
+	istream.Close();
+	return contents;
+}
+
+dojo.hostenv.exit = function(exitcode){ WScript.Quit(exitcode); }

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html.js Sat May 13 09:36:25 2006
@@ -0,0 +1,571 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.html");
+
+dojo.require("dojo.lang.func");
+dojo.require("dojo.dom");
+dojo.require("dojo.style");
+dojo.require("dojo.string");
+
+dojo.lang.mixin(dojo.html, dojo.dom);
+dojo.lang.mixin(dojo.html, dojo.style);
+
+// FIXME: we are going to assume that we can throw any and every rendering
+// engine into the IE 5.x box model. In Mozilla, we do this w/ CSS.
+// Need to investigate for KHTML and Opera
+
+dojo.html.clearSelection = function(){
+	try{
+		if(window["getSelection"]){ 
+			if(dojo.render.html.safari){
+				// pulled from WebCore/ecma/kjs_window.cpp, line 2536
+				window.getSelection().collapse();
+			}else{
+				window.getSelection().removeAllRanges();
+			}
+		}else if(document.selection){
+			if(document.selection.empty){
+				document.selection.empty();
+			}else if(document.selection.clear){
+				document.selection.clear();
+			}
+		}
+		return true;
+	}catch(e){
+		dojo.debug(e);
+		return false;
+	}
+}
+
+dojo.html.disableSelection = function(element){
+	element = dojo.byId(element)||document.body;
+	var h = dojo.render.html;
+	
+	if(h.mozilla){
+		element.style.MozUserSelect = "none";
+	}else if(h.safari){
+		element.style.KhtmlUserSelect = "none"; 
+	}else if(h.ie){
+		element.unselectable = "on";
+	}else{
+		return false;
+	}
+	return true;
+}
+
+dojo.html.enableSelection = function(element){
+	element = dojo.byId(element)||document.body;
+	
+	var h = dojo.render.html;
+	if(h.mozilla){ 
+		element.style.MozUserSelect = ""; 
+	}else if(h.safari){
+		element.style.KhtmlUserSelect = "";
+	}else if(h.ie){
+		element.unselectable = "off";
+	}else{
+		return false;
+	}
+	return true;
+}
+
+dojo.html.selectElement = function(element){
+	element = dojo.byId(element);
+	if(document.selection && document.body.createTextRange){ // IE
+		var range = document.body.createTextRange();
+		range.moveToElementText(element);
+		range.select();
+	}else if(window["getSelection"]){
+		var selection = window.getSelection();
+		// FIXME: does this work on Safari?
+		if(selection["selectAllChildren"]){ // Mozilla
+			selection.selectAllChildren(element);
+		}
+	}
+}
+
+dojo.html.selectInputText = function(element){
+	element = dojo.byId(element);
+	if(document.selection && document.body.createTextRange){ // IE
+		var range = element.createTextRange();
+		range.moveStart("character", 0);
+		range.moveEnd("character", element.value.length);
+		range.select();
+	}else if(window["getSelection"]){
+		var selection = window.getSelection();
+		// FIXME: does this work on Safari?
+		element.setSelectionRange(0, element.value.length);
+	}
+	element.focus();
+}
+
+
+dojo.html.isSelectionCollapsed = function(){
+	if(document["selection"]){ // IE
+		return document.selection.createRange().text == "";
+	}else if(window["getSelection"]){
+		var selection = window.getSelection();
+		if(dojo.lang.isString(selection)){ // Safari
+			return selection == "";
+		}else{ // Mozilla/W3
+			return selection.isCollapsed;
+		}
+	}
+}
+
+dojo.html.getEventTarget = function(evt){
+	if(!evt) { evt = window.event || {} };
+	var t = (evt.srcElement ? evt.srcElement : (evt.target ? evt.target : null));
+	while((t)&&(t.nodeType!=1)){ t = t.parentNode; }
+	return t;
+}
+
+dojo.html.getDocumentWidth = function(){
+	dojo.deprecated("dojo.html.getDocument*", "replaced by dojo.html.getViewport*", "0.4");
+	return dojo.html.getViewportWidth();
+}
+
+dojo.html.getDocumentHeight = function(){
+	dojo.deprecated("dojo.html.getDocument*", "replaced by dojo.html.getViewport*", "0.4");
+	return dojo.html.getViewportHeight();
+}
+
+dojo.html.getDocumentSize = function(){
+	dojo.deprecated("dojo.html.getDocument*", "replaced of dojo.html.getViewport*", "0.4");
+	return dojo.html.getViewportSize();
+}
+
+dojo.html.getViewportWidth = function(){
+	var w = 0;
+
+	if(window.innerWidth){
+		w = window.innerWidth;
+	}
+
+	if(dojo.exists(document, "documentElement.clientWidth")){
+		// IE6 Strict
+		var w2 = document.documentElement.clientWidth;
+		// this lets us account for scrollbars
+		if(!w || w2 && w2 < w) {
+			w = w2;
+		}
+		return w;
+	}
+
+	if(document.body){
+		// IE
+		return document.body.clientWidth;
+	}
+
+	return 0;
+}
+
+dojo.html.getViewportHeight = function(){
+	if (window.innerHeight){
+		return window.innerHeight;
+	}
+
+	if (dojo.exists(document, "documentElement.clientHeight")){
+		// IE6 Strict
+		return document.documentElement.clientHeight;
+	}
+
+	if (document.body){
+		// IE
+		return document.body.clientHeight;
+	}
+
+	return 0;
+}
+
+dojo.html.getViewportSize = function(){
+	var ret = [dojo.html.getViewportWidth(), dojo.html.getViewportHeight()];
+	ret.w = ret[0];
+	ret.h = ret[1];
+	return ret;
+}
+
+dojo.html.getScrollTop = function(){
+	return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
+}
+
+dojo.html.getScrollLeft = function(){
+	return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
+}
+
+dojo.html.getScrollOffset = function(){
+	var off = [dojo.html.getScrollLeft(), dojo.html.getScrollTop()];
+	off.x = off[0];
+	off.y = off[1];
+	return off;
+}
+
+dojo.html.getParentOfType = function(node, type){
+	dojo.deprecated("dojo.html.getParentOfType", "replaced by dojo.html.getParentByType*", "0.4");
+	return dojo.html.getParentByType(node, type);
+}
+
+dojo.html.getParentByType = function(node, type) {
+	var parent = dojo.byId(node);
+	type = type.toLowerCase();
+	while((parent)&&(parent.nodeName.toLowerCase()!=type)){
+		if(parent==(document["body"]||document["documentElement"])){
+			return null;
+		}
+		parent = parent.parentNode;
+	}
+	return parent;
+}
+
+// RAR: this function comes from nwidgets and is more-or-less unmodified.
+// We should probably look ant Burst and f(m)'s equivalents
+dojo.html.getAttribute = function(node, attr){
+	node = dojo.byId(node);
+	// FIXME: need to add support for attr-specific accessors
+	if((!node)||(!node.getAttribute)){
+		// if(attr !== 'nwType'){
+		//	alert("getAttr of '" + attr + "' with bad node"); 
+		// }
+		return null;
+	}
+	var ta = typeof attr == 'string' ? attr : new String(attr);
+
+	// first try the approach most likely to succeed
+	var v = node.getAttribute(ta.toUpperCase());
+	if((v)&&(typeof v == 'string')&&(v!="")){ return v; }
+
+	// try returning the attributes value, if we couldn't get it as a string
+	if(v && v.value){ return v.value; }
+
+	// this should work on Opera 7, but it's a little on the crashy side
+	if((node.getAttributeNode)&&(node.getAttributeNode(ta))){
+		return (node.getAttributeNode(ta)).value;
+	}else if(node.getAttribute(ta)){
+		return node.getAttribute(ta);
+	}else if(node.getAttribute(ta.toLowerCase())){
+		return node.getAttribute(ta.toLowerCase());
+	}
+	return null;
+}
+	
+/**
+ *	Determines whether or not the specified node carries a value for the
+ *	attribute in question.
+ */
+dojo.html.hasAttribute = function(node, attr){
+	node = dojo.byId(node);
+	return dojo.html.getAttribute(node, attr) ? true : false;
+}
+	
+/**
+ * Returns the string value of the list of CSS classes currently assigned
+ * directly to the node in question. Returns an empty string if no class attribute
+ * is found;
+ */
+dojo.html.getClass = function(node){
+	node = dojo.byId(node);
+	if(!node){ return ""; }
+	var cs = "";
+	if(node.className){
+		cs = node.className;
+	}else if(dojo.html.hasAttribute(node, "class")){
+		cs = dojo.html.getAttribute(node, "class");
+	}
+	return dojo.string.trim(cs);
+}
+
+/**
+ * Returns an array of CSS classes currently assigned
+ * directly to the node in question. Returns an empty array if no classes
+ * are found;
+ */
+dojo.html.getClasses = function(node) {
+	var c = dojo.html.getClass(node);
+	return (c == "") ? [] : c.split(/\s+/g);
+}
+
+/**
+ * Returns whether or not the specified classname is a portion of the
+ * class list currently applied to the node. Does not cover cascaded
+ * styles, only classes directly applied to the node.
+ */
+dojo.html.hasClass = function(node, classname){
+	return dojo.lang.inArray(dojo.html.getClasses(node), classname);
+}
+
+/**
+ * Adds the specified class to the beginning of the class list on the
+ * passed node. This gives the specified class the highest precidence
+ * when style cascading is calculated for the node. Returns true or
+ * false; indicating success or failure of the operation, respectively.
+ */
+dojo.html.prependClass = function(node, classStr){
+	classStr += " " + dojo.html.getClass(node);
+	return dojo.html.setClass(node, classStr);
+}
+
+/**
+ * Adds the specified class to the end of the class list on the
+ *	passed &node;. Returns &true; or &false; indicating success or failure.
+ */
+dojo.html.addClass = function(node, classStr){
+	if (dojo.html.hasClass(node, classStr)) {
+	  return false;
+	}
+	classStr = dojo.string.trim(dojo.html.getClass(node) + " " + classStr);
+	return dojo.html.setClass(node, classStr);
+}
+
+/**
+ *	Clobbers the existing list of classes for the node, replacing it with
+ *	the list given in the 2nd argument. Returns true or false
+ *	indicating success or failure.
+ */
+dojo.html.setClass = function(node, classStr){
+	node = dojo.byId(node);
+	var cs = new String(classStr);
+	try{
+		if(typeof node.className == "string"){
+			node.className = cs;
+		}else if(node.setAttribute){
+			node.setAttribute("class", classStr);
+			node.className = cs;
+		}else{
+			return false;
+		}
+	}catch(e){
+		dojo.debug("dojo.html.setClass() failed", e);
+	}
+	return true;
+}
+
+/**
+ * Removes the className from the node;. Returns
+ * true or false indicating success or failure.
+ */ 
+dojo.html.removeClass = function(node, classStr, allowPartialMatches){
+	var classStr = dojo.string.trim(new String(classStr));
+
+	try{
+		var cs = dojo.html.getClasses(node);
+		var nca	= [];
+		if(allowPartialMatches){
+			for(var i = 0; i<cs.length; i++){
+				if(cs[i].indexOf(classStr) == -1){ 
+					nca.push(cs[i]);
+				}
+			}
+		}else{
+			for(var i=0; i<cs.length; i++){
+				if(cs[i] != classStr){ 
+					nca.push(cs[i]);
+				}
+			}
+		}
+		dojo.html.setClass(node, nca.join(" "));
+	}catch(e){
+		dojo.debug("dojo.html.removeClass() failed", e);
+	}
+
+	return true;
+}
+
+/**
+ * Replaces 'oldClass' and adds 'newClass' to node
+ */
+dojo.html.replaceClass = function(node, newClass, oldClass) {
+	dojo.html.removeClass(node, oldClass);
+	dojo.html.addClass(node, newClass);
+}
+
+// Enum type for getElementsByClass classMatchType arg:
+dojo.html.classMatchType = {
+	ContainsAll : 0, // all of the classes are part of the node's class (default)
+	ContainsAny : 1, // any of the classes are part of the node's class
+	IsOnly : 2 // only all of the classes are part of the node's class
+}
+
+
+/**
+ * Returns an array of nodes for the given classStr, children of a
+ * parent, and optionally of a certain nodeType
+ */
+dojo.html.getElementsByClass = function(classStr, parent, nodeType, classMatchType){
+	parent = dojo.byId(parent) || document;
+	var classes = classStr.split(/\s+/g);
+	var nodes = [];
+	if( classMatchType != 1 && classMatchType != 2 ) classMatchType = 0; // make it enum
+	var reClass = new RegExp("(\\s|^)((" + classes.join(")|(") + "))(\\s|$)");
+
+	// FIXME: doesn't have correct parent support!
+	if(!nodeType){ nodeType = "*"; }
+	var candidateNodes = parent.getElementsByTagName(nodeType);
+
+	var node, i = 0;
+	outer:
+	while (node = candidateNodes[i++]) {
+		var nodeClasses = dojo.html.getClasses(node);
+		if(nodeClasses.length == 0) { continue outer; }
+		var matches = 0;
+
+		for(var j = 0; j < nodeClasses.length; j++) {
+			if( reClass.test(nodeClasses[j]) ) {
+				if( classMatchType == dojo.html.classMatchType.ContainsAny ) {
+					nodes.push(node);
+					continue outer;
+				} else {
+					matches++;
+				}
+			} else {
+				if( classMatchType == dojo.html.classMatchType.IsOnly ) {
+					continue outer;
+				}
+			}
+		}
+
+		if( matches == classes.length ) {
+			if( classMatchType == dojo.html.classMatchType.IsOnly && matches == nodeClasses.length ) {
+				nodes.push(node);
+			} else if( classMatchType == dojo.html.classMatchType.ContainsAll ) {
+				nodes.push(node);
+			}
+		}
+	}
+	
+	return nodes;
+}
+
+dojo.html.getElementsByClassName = dojo.html.getElementsByClass;
+
+/**
+ * Returns the mouse position relative to the document (not the viewport).
+ * For example, if you have a document that is 10000px tall,
+ * but your browser window is only 100px tall,
+ * if you scroll to the bottom of the document and call this function it
+ * will return {x: 0, y: 10000}
+ */
+dojo.html.getCursorPosition = function(e){
+	e = e || window.event;
+	var cursor = {x:0, y:0};
+	if(e.pageX || e.pageY){
+		cursor.x = e.pageX;
+		cursor.y = e.pageY;
+	}else{
+		var de = document.documentElement;
+		var db = document.body;
+		cursor.x = e.clientX + ((de||db)["scrollLeft"]) - ((de||db)["clientLeft"]);
+		cursor.y = e.clientY + ((de||db)["scrollTop"]) - ((de||db)["clientTop"]);
+	}
+	return cursor;
+}
+
+dojo.html.overElement = function(element, e){
+	element = dojo.byId(element);
+	var mouse = dojo.html.getCursorPosition(e);
+
+	with(dojo.html){
+		var top = getAbsoluteY(element, true);
+		var bottom = top + getInnerHeight(element);
+		var left = getAbsoluteX(element, true);
+		var right = left + getInnerWidth(element);
+	}
+	
+	return (mouse.x >= left && mouse.x <= right &&
+		mouse.y >= top && mouse.y <= bottom);
+}
+
+dojo.html.setActiveStyleSheet = function(title){
+	var i = 0, a, els = document.getElementsByTagName("link");
+	while (a = els[i++]) {
+		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")){
+			a.disabled = true;
+			if (a.getAttribute("title") == title) { a.disabled = false; }
+		}
+	}
+}
+
+dojo.html.getActiveStyleSheet = function(){
+	var i = 0, a, els = document.getElementsByTagName("link");
+	while (a = els[i++]) {
+		if (a.getAttribute("rel").indexOf("style") != -1 &&
+			a.getAttribute("title") && !a.disabled) { return a.getAttribute("title"); }
+	}
+	return null;
+}
+
+dojo.html.getPreferredStyleSheet = function(){
+	var i = 0, a, els = document.getElementsByTagName("link");
+	while (a = els[i++]) {
+		if(a.getAttribute("rel").indexOf("style") != -1
+			&& a.getAttribute("rel").indexOf("alt") == -1
+			&& a.getAttribute("title")) { return a.getAttribute("title"); }
+	}
+	return null;
+}
+
+dojo.html.body = function(){
+	// Note: document.body is not defined for a strict xhtml document
+	return document.body || document.getElementsByTagName("body")[0];
+}
+
+/**
+ * Like dojo.dom.isTag, except case-insensitive
+**/
+dojo.html.isTag = function(node /* ... */) {
+	node = dojo.byId(node);
+	if(node && node.tagName) {
+		var arr = dojo.lang.map(dojo.lang.toArray(arguments, 1),
+			function(a) { return String(a).toLowerCase(); });
+		return arr[ dojo.lang.find(node.tagName.toLowerCase(), arr) ] || "";
+	}
+	return "";
+}
+
+dojo.html.copyStyle = function(target, source){
+	// work around for opera which doesn't have cssText, and for IE which fails on setAttribute 
+	if(dojo.lang.isUndefined(source.style.cssText)){ 
+		target.setAttribute("style", source.getAttribute("style")); 
+	}else{
+		target.style.cssText = source.style.cssText; 
+	}
+	dojo.html.addClass(target, dojo.html.getClass(source));
+}
+
+dojo.html._callExtrasDeprecated = function(inFunc, args) {
+	var module = "dojo.html.extras";
+	dojo.deprecated("dojo.html." + inFunc, "moved to " + module, "0.4");
+	dojo["require"](module); // weird syntax to fool list-profile-deps (build)
+	return dojo.html[inFunc].apply(dojo.html, args);
+}
+
+dojo.html.createNodesFromText = function() {
+	return dojo.html._callExtrasDeprecated('createNodesFromText', arguments);
+}
+
+dojo.html.gravity = function() {
+	return dojo.html._callExtrasDeprecated('gravity', arguments);
+}
+
+dojo.html.placeOnScreen = function() {
+	return dojo.html._callExtrasDeprecated('placeOnScreen', arguments);
+}
+
+dojo.html.placeOnScreenPoint = function() {
+	return dojo.html._callExtrasDeprecated('placeOnScreenPoint', arguments);
+}
+
+dojo.html.renderedTextContent = function() {
+	return dojo.html._callExtrasDeprecated('renderedTextContent', arguments);
+}
+
+dojo.html.BackgroundIframe = function() {
+	return dojo.html._callExtrasDeprecated('BackgroundIframe', arguments);
+}

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/__package__.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/__package__.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/__package__.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/__package__.js Sat May 13 09:36:25 2006
@@ -0,0 +1,14 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.kwCompoundRequire({
+	common: ["dojo.html", "dojo.html.extras", "dojo.html.shadow"]
+});
+dojo.provide("dojo.html.*");

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/extras.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/extras.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/extras.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/extras.js Sat May 13 09:36:25 2006
@@ -0,0 +1,428 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.require("dojo.html");
+dojo.provide("dojo.html.extras");
+dojo.require("dojo.string.extras"); 
+
+/**
+ * Calculates the mouse's direction of gravity relative to the centre
+ * of the given node.
+ * <p>
+ * If you wanted to insert a node into a DOM tree based on the mouse
+ * position you might use the following code:
+ * <pre>
+ * if (gravity(node, e) & gravity.NORTH) { [insert before]; }
+ * else { [insert after]; }
+ * </pre>
+ *
+ * @param node The node
+ * @param e		The event containing the mouse coordinates
+ * @return		 The directions, NORTH or SOUTH and EAST or WEST. These
+ *						 are properties of the function.
+ */
+dojo.html.gravity = function(node, e){
+	node = dojo.byId(node);
+	var mouse = dojo.html.getCursorPosition(e);
+
+	with (dojo.html) {
+		var nodecenterx = getAbsoluteX(node, true) + (getInnerWidth(node) / 2);
+		var nodecentery = getAbsoluteY(node, true) + (getInnerHeight(node) / 2);
+	}
+	
+	with (dojo.html.gravity) {
+		return ((mouse.x < nodecenterx ? WEST : EAST) |
+			(mouse.y < nodecentery ? NORTH : SOUTH));
+	}
+}
+
+dojo.html.gravity.NORTH = 1;
+dojo.html.gravity.SOUTH = 1 << 1;
+dojo.html.gravity.EAST = 1 << 2;
+dojo.html.gravity.WEST = 1 << 3;
+
+
+/**
+ * Attempts to return the text as it would be rendered, with the line breaks
+ * sorted out nicely. Unfinished.
+ */
+dojo.html.renderedTextContent = function(node){
+	node = dojo.byId(node);
+	var result = "";
+	if (node == null) { return result; }
+	for (var i = 0; i < node.childNodes.length; i++) {
+		switch (node.childNodes[i].nodeType) {
+			case 1: // ELEMENT_NODE
+			case 5: // ENTITY_REFERENCE_NODE
+				var display = "unknown";
+				try {
+					display = dojo.style.getStyle(node.childNodes[i], "display");
+				} catch(E) {}
+				switch (display) {
+					case "block": case "list-item": case "run-in":
+					case "table": case "table-row-group": case "table-header-group":
+					case "table-footer-group": case "table-row": case "table-column-group":
+					case "table-column": case "table-cell": case "table-caption":
+						// TODO: this shouldn't insert double spaces on aligning blocks
+						result += "\n";
+						result += dojo.html.renderedTextContent(node.childNodes[i]);
+						result += "\n";
+						break;
+					
+					case "none": break;
+					
+					default:
+						if(node.childNodes[i].tagName && node.childNodes[i].tagName.toLowerCase() == "br") {
+							result += "\n";
+						} else {
+							result += dojo.html.renderedTextContent(node.childNodes[i]);
+						}
+						break;
+				}
+				break;
+			case 3: // TEXT_NODE
+			case 2: // ATTRIBUTE_NODE
+			case 4: // CDATA_SECTION_NODE
+				var text = node.childNodes[i].nodeValue;
+				var textTransform = "unknown";
+				try {
+					textTransform = dojo.style.getStyle(node, "text-transform");
+				} catch(E) {}
+				switch (textTransform){
+					case "capitalize": text = dojo.string.capitalize(text); break;
+					case "uppercase": text = text.toUpperCase(); break;
+					case "lowercase": text = text.toLowerCase(); break;
+					default: break; // leave as is
+				}
+				// TODO: implement
+				switch (textTransform){
+					case "nowrap": break;
+					case "pre-wrap": break;
+					case "pre-line": break;
+					case "pre": break; // leave as is
+					default:
+						// remove whitespace and collapse first space
+						text = text.replace(/\s+/, " ");
+						if (/\s$/.test(result)) { text.replace(/^\s/, ""); }
+						break;
+				}
+				result += text;
+				break;
+			default:
+				break;
+		}
+	}
+	return result;
+}
+
+dojo.html.createNodesFromText = function(txt, trim){
+	if(trim) { txt = dojo.string.trim(txt); }
+
+	var tn = document.createElement("div");
+	// tn.style.display = "none";
+	tn.style.visibility= "hidden";
+	document.body.appendChild(tn);
+	var tableType = "none";
+	if((/^<t[dh][\s\r\n>]/i).test(dojo.string.trimStart(txt))) {
+		txt = "<table><tbody><tr>" + txt + "</tr></tbody></table>";
+		tableType = "cell";
+	} else if((/^<tr[\s\r\n>]/i).test(dojo.string.trimStart(txt))) {
+		txt = "<table><tbody>" + txt + "</tbody></table>";
+		tableType = "row";
+	} else if((/^<(thead|tbody|tfoot)[\s\r\n>]/i).test(dojo.string.trimStart(txt))) {
+		txt = "<table>" + txt + "</table>";
+		tableType = "section";
+	}
+	tn.innerHTML = txt;
+	if(tn["normalize"]){
+		tn.normalize();
+	}
+
+	var parent = null;
+	switch(tableType) {
+		case "cell":
+			parent = tn.getElementsByTagName("tr")[0];
+			break;
+		case "row":
+			parent = tn.getElementsByTagName("tbody")[0];
+			break;
+		case "section":
+			parent = tn.getElementsByTagName("table")[0];
+			break;
+		default:
+			parent = tn;
+			break;
+	}
+
+	/* this doesn't make much sense, I'm assuming it just meant trim() so wrap was replaced with trim
+	if(wrap){ 
+		var ret = [];
+		// start hack
+		var fc = tn.firstChild;
+		ret[0] = ((fc.nodeValue == " ")||(fc.nodeValue == "\t")) ? fc.nextSibling : fc;
+		// end hack
+		// tn.style.display = "none";
+		document.body.removeChild(tn);
+		return ret;
+	}
+	*/
+	var nodes = [];
+	for(var x=0; x<parent.childNodes.length; x++){
+		nodes.push(parent.childNodes[x].cloneNode(true));
+	}
+	tn.style.display = "none"; // FIXME: why do we do this?
+	document.body.removeChild(tn);
+	return nodes;
+}
+
+/* TODO: merge placeOnScreen and placeOnScreenPoint to make 1 function that allows you
+ * to define which corner(s) you want to bind to. Something like so:
+ *
+ * kes(node, desiredX, desiredY, "TR")
+ * kes(node, [desiredX, desiredY], ["TR", "BL"])
+ *
+ * TODO: make this function have variable call sigs
+ *
+ * kes(node, ptArray, cornerArray, padding, hasScroll)
+ * kes(node, ptX, ptY, cornerA, cornerB, cornerC, paddingArray, hasScroll)
+ */
+
+/**
+ * Keeps 'node' in the visible area of the screen while trying to
+ * place closest to desiredX, desiredY. The input coordinates are
+ * expected to be the desired screen position, not accounting for
+ * scrolling. If you already accounted for scrolling, set 'hasScroll'
+ * to true. Set padding to either a number or array for [paddingX, paddingY]
+ * to put some buffer around the element you want to position.
+ * NOTE: node is assumed to be absolutely or relatively positioned.
+ *
+ * Alternate call sig:
+ *  placeOnScreen(node, [x, y], padding, hasScroll)
+ *
+ * Examples:
+ *  placeOnScreen(node, 100, 200)
+ *  placeOnScreen("myId", [800, 623], 5)
+ *  placeOnScreen(node, 234, 3284, [2, 5], true)
+ */
+dojo.html.placeOnScreen = function(node, desiredX, desiredY, padding, hasScroll) {
+	if(dojo.lang.isArray(desiredX)) {
+		hasScroll = padding;
+		padding = desiredY;
+		desiredY = desiredX[1];
+		desiredX = desiredX[0];
+	}
+
+	if(!isNaN(padding)) {
+		padding = [Number(padding), Number(padding)];
+	} else if(!dojo.lang.isArray(padding)) {
+		padding = [0, 0];
+	}
+
+	var scroll = dojo.html.getScrollOffset();
+	var view = dojo.html.getViewportSize();
+
+	node = dojo.byId(node);
+	var w = node.offsetWidth + padding[0];
+	var h = node.offsetHeight + padding[1];
+
+	if(hasScroll) {
+		desiredX -= scroll.x;
+		desiredY -= scroll.y;
+	}
+
+	var x = desiredX + w;
+	if(x > view.w) {
+		x = view.w - w;
+	} else {
+		x = desiredX;
+	}
+	x = Math.max(padding[0], x) + scroll.x;
+
+	var y = desiredY + h;
+	if(y > view.h) {
+		y = view.h - h;
+	} else {
+		y = desiredY;
+	}
+	y = Math.max(padding[1], y) + scroll.y;
+
+	node.style.left = x + "px";
+	node.style.top = y + "px";
+
+	var ret = [x, y];
+	ret.x = x;
+	ret.y = y;
+	return ret;
+}
+
+/**
+ * Like placeOnScreenPoint except that it attempts to keep one of the node's
+ * corners at desiredX, desiredY.  Favors the bottom right position
+ *
+ * Examples placing node at mouse position (where e = [Mouse event]):
+ *  placeOnScreenPoint(node, e.clientX, e.clientY);
+ */
+dojo.html.placeOnScreenPoint = function(node, desiredX, desiredY, padding, hasScroll) {
+	if(dojo.lang.isArray(desiredX)) {
+		hasScroll = padding;
+		padding = desiredY;
+		desiredY = desiredX[1];
+		desiredX = desiredX[0];
+	}
+
+	if(!isNaN(padding)) {
+		padding = [Number(padding), Number(padding)];
+	} else if(!dojo.lang.isArray(padding)) {
+		padding = [0, 0];
+	}
+
+	var scroll = dojo.html.getScrollOffset();
+	var view = dojo.html.getViewportSize();
+
+	node = dojo.byId(node);
+	var oldDisplay = node.style.display;
+	node.style.display="";
+	var w = dojo.style.getInnerWidth(node);
+	var h = dojo.style.getInnerHeight(node);
+	node.style.display=oldDisplay;
+
+	if(hasScroll) {
+		desiredX -= scroll.x;
+		desiredY -= scroll.y;
+	}
+
+	var x = -1, y = -1;
+	//dojo.debug((desiredX+padding[0]) + w, "<=", view.w, "&&", (desiredY+padding[1]) + h, "<=", view.h);
+	if((desiredX+padding[0]) + w <= view.w && (desiredY+padding[1]) + h <= view.h) { // TL
+		x = (desiredX+padding[0]);
+		y = (desiredY+padding[1]);
+		//dojo.debug("TL", x, y);
+	}
+
+	//dojo.debug((desiredX-padding[0]), "<=", view.w, "&&", (desiredY+padding[1]) + h, "<=", view.h);
+	if((x < 0 || y < 0) && (desiredX-padding[0]) <= view.w && (desiredY+padding[1]) + h <= view.h) { // TR
+		x = (desiredX-padding[0]) - w;
+		y = (desiredY+padding[1]);
+		//dojo.debug("TR", x, y);
+	}
+
+	//dojo.debug((desiredX+padding[0]) + w, "<=", view.w, "&&", (desiredY-padding[1]), "<=", view.h);
+	if((x < 0 || y < 0) && (desiredX+padding[0]) + w <= view.w && (desiredY-padding[1]) <= view.h) { // BL
+		x = (desiredX+padding[0]);
+		y = (desiredY-padding[1]) - h;
+		//dojo.debug("BL", x, y);
+	}
+
+	//dojo.debug((desiredX-padding[0]), "<=", view.w, "&&", (desiredY-padding[1]), "<=", view.h);
+	if((x < 0 || y < 0) && (desiredX-padding[0]) <= view.w && (desiredY-padding[1]) <= view.h) { // BR
+		x = (desiredX-padding[0]) - w;
+		y = (desiredY-padding[1]) - h;
+		//dojo.debug("BR", x, y);
+	}
+
+	if(x < 0 || y < 0 || (x + w > view.w) || (y + h > view.h)) {
+		return dojo.html.placeOnScreen(node, desiredX, desiredY, padding, hasScroll);
+	}
+
+	x += scroll.x;
+	y += scroll.y;
+
+	node.style.left = x + "px";
+	node.style.top = y + "px";
+
+	var ret = [x, y];
+	ret.x = x;
+	ret.y = y;
+	return ret;
+}
+
+/**
+ * For IE z-index schenanigans
+ * Two possible uses:
+ *   1. new dojo.html.BackgroundIframe(node)
+ *        Makes a background iframe as a child of node, that fills area (and position) of node
+ *
+ *   2. new dojo.html.BackgroundIframe()
+ *        Attaches frame to document.body.  User must call size() to set size.
+ */
+dojo.html.BackgroundIframe = function(node) {
+	if(dojo.render.html.ie) {
+		var html=
+				 "<iframe "
+				+"style='position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;"
+				+        "z-index: -1; filter:Alpha(Opacity=\"0\");' "
+				+">";
+		this.iframe = document.createElement(html);
+		if(node){
+			node.appendChild(this.iframe);
+			this.domNode=node;
+		}else{
+			document.body.appendChild(this.iframe);
+			this.iframe.style.display="none";
+		}
+	}
+}
+dojo.lang.extend(dojo.html.BackgroundIframe, {
+	iframe: null,
+
+	// TODO: this function shouldn't be necessary but setting width=height=100% doesn't work!
+	onResized: function(){
+		if(this.iframe && this.domNode){
+			var w = dojo.style.getOuterWidth(this.domNode);
+			var h = dojo.style.getOuterHeight(this.domNode);
+			if (w  == 0 || h == 0 ){
+				dojo.lang.setTimeout(this, this.onResized, 50);
+				return;
+			}
+			var s = this.iframe.style;
+			s.width = w + "px";
+			s.height = h + "px";
+		}
+	},
+
+	// Call this function if the iframe is connected to document.body rather
+	// than the node being shadowed (TODO: erase)
+	size: function(node) {
+		if(!this.iframe) { return; }
+
+		coords = dojo.style.toCoordinateArray(node, true);
+
+		var s = this.iframe.style;
+		s.width = coords.w + "px";
+		s.height = coords.h + "px";
+		s.left = coords.x + "px";
+		s.top = coords.y + "px";
+	},
+
+	setZIndex: function(node /* or number */) {
+		if(!this.iframe) { return; }
+
+		if(dojo.dom.isNode(node)) {
+			this.iframe.style.zIndex = dojo.html.getStyle(node, "z-index") - 1;
+		} else if(!isNaN(node)) {
+			this.iframe.style.zIndex = node;
+		}
+	},
+
+	show: function() {
+		if(!this.iframe) { return; }
+		this.iframe.style.display = "block";
+	},
+
+	hide: function() {
+		if(!this.ie) { return; }
+		var s = this.iframe.style;
+		s.display = "none";
+	},
+
+	remove: function() {
+		dojo.dom.removeNode(this.iframe);
+	}
+});

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowB.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowB.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowB.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowBL.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowBL.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowBL.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowBR.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowBR.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowBR.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowL.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowL.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowL.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowR.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowR.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowR.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowT.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowT.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowT.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTL.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTL.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTL.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTR..png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTR..png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTR..png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTR.png
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTR.png?rev=406128&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/images/shadowTR.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/layout.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/layout.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/layout.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/layout.js Sat May 13 09:36:25 2006
@@ -0,0 +1,117 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.html.layout");
+
+dojo.require("dojo.lang");
+dojo.require("dojo.string");
+dojo.require("dojo.style");
+dojo.require("dojo.html");
+
+/**
+ * Layout a bunch of child dom nodes within a parent dom node
+ * Input is an array of objects like:
+ * @ container - parent node
+ * @ layoutPriority - "top-bottom" or "left-right"
+ * @ children an array like [ {domNode: foo, layoutAlign: "bottom" }, {domNode: bar, layoutAlign: "client"} ]
+ */
+dojo.html.layout = function(container, children, layoutPriority) {
+	dojo.html.addClass(container, "dojoLayoutContainer");
+
+	// copy children array and remove elements w/out layout
+	children = dojo.lang.filter(children, function(child){
+		return dojo.lang.inArray(["top","bottom","left","right","client","flood"], child.layoutAlign)
+	});
+
+	// order the children according to layoutPriority
+	if(layoutPriority && layoutPriority!="none"){
+		var rank = function(child){
+			switch(child.layoutAlign){
+				case "flood":
+					return 1;
+				case "left":
+				case "right":
+					return (layoutPriority=="left-right") ? 2 : 3;
+				case "top":
+				case "bottom":
+					return (layoutPriority=="left-right") ? 3 : 2;
+				default:
+					return 4;
+			}
+		};
+		children.sort(function(a,b){ return rank(a)-rank(b); });
+	}
+
+	// remaining space (blank area where nothing has been written)
+	var f={
+		top: dojo.style.getPixelValue(container, "padding-top", true),
+		left: dojo.style.getPixelValue(container, "padding-left", true),
+		height: dojo.style.getContentHeight(container),
+		width: dojo.style.getContentWidth(container)
+	};
+
+	// set positions/sizes
+	dojo.lang.forEach(children, function(child){
+		var elm=child.domNode;
+		var pos=child.layoutAlign;
+
+		// set elem to upper left corner of unused space; may move it later
+		with(elm.style){
+			left = f.left+"px";
+			top = f.top+"px";
+			bottom = "auto";
+			right = "auto";
+		}
+		dojo.html.addClass(elm, "dojoAlign" + dojo.string.capitalize(pos));
+
+		// set size && adjust record of remaining space.
+		// note that setting the width of a <div> may affect it's height.
+		// TODO: same is true for widgets but need to implement API to support that
+		if ( (pos=="top")||(pos=="bottom") ) {
+			dojo.style.setOuterWidth(elm, f.width);
+			var h = dojo.style.getOuterHeight(elm);
+			f.height -= h;
+			if(pos=="top"){
+				f.top += h;
+			}else{
+				elm.style.top = f.top + f.height + "px";
+			}
+		}else if(pos=="left" || pos=="right"){
+			dojo.style.setOuterHeight(elm, f.height);
+			var w = dojo.style.getOuterWidth(elm);
+			f.width -= w;
+			if(pos=="left"){
+				f.left += w;
+			}else{
+				elm.style.left = f.left + f.width + "px";
+			}
+		} else if(pos=="flood" || pos=="client"){
+			dojo.style.setOuterWidth(elm, f.width);
+			dojo.style.setOuterHeight(elm, f.height);
+		}
+		
+		// TODO: for widgets I want to call resizeTo(), but for top/bottom
+		// alignment I only want to set the width, and have the size determined
+		// dynamically.  (The thinner you make a div, the more height it consumes.)
+		if(child.onResized){
+			child.onResized();
+		}
+	});
+};
+
+// This is essential CSS to make layout work (it isn't "styling" CSS)
+// make sure that the position:absolute in dojoAlign* overrides other classes
+dojo.style.insertCssText(
+	".dojoLayoutContainer{ position: relative; display: block; }\n" +
+	"body .dojoAlignTop, body .dojoAlignBottom, body .dojoAlignLeft, body .dojoAlignRight { position: absolute; overflow: hidden; }\n" +
+	"body .dojoAlignClient { position: absolute }\n" +
+	".dojoAlignClient { overflow: auto; }\n"
+);
+

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/shadow.js
URL: http://svn.apache.org/viewcvs/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/shadow.js?rev=406128&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/shadow.js (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/html/shadow.js Sat May 13 09:36:25 2006
@@ -0,0 +1,79 @@
+/*
+	Copyright (c) 2004-2006, The Dojo Foundation
+	All Rights Reserved.
+
+	Licensed under the Academic Free License version 2.1 or above OR the
+	modified BSD license. For more information on Dojo licensing, see:
+
+		http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.html.shadow");
+
+dojo.require("dojo.lang");
+dojo.require("dojo.uri");
+
+dojo.html.shadow = function(node) {
+	this.init(node);
+}
+
+dojo.lang.extend(dojo.html.shadow, {
+
+	shadowPng: dojo.uri.dojoUri("src/html/images/shadow"),
+	shadowThickness: 8,
+	shadowOffset: 15,
+
+	init: function(node){
+		this.node=node;
+
+		// make all the pieces of the shadow, and position/size them as much
+		// as possible (but a lot of the coordinates are set in sizeShadow
+		this.pieces={};
+		var x1 = -1 * this.shadowThickness;
+		var y0 = this.shadowOffset;
+		var y1 = this.shadowOffset + this.shadowThickness;
+		this._makePiece("tl", "top", y0, "left", x1);
+		this._makePiece("l", "top", y1, "left", x1, "scale");
+		this._makePiece("tr", "top", y0, "left", 0);
+		this._makePiece("r", "top", y1, "left", 0, "scale");
+		this._makePiece("bl", "top", 0, "left", x1);
+		this._makePiece("b", "top", 0, "left", 0, "crop");
+		this._makePiece("br", "top", 0, "left", 0);
+	},
+
+	_makePiece: function(name, vertAttach, vertCoord, horzAttach, horzCoord, sizing){
+		var img;
+		var url = this.shadowPng + name.toUpperCase() + ".png";
+		if(dojo.render.html.ie){
+			img=document.createElement("div");
+			img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"'"+
+			(sizing?", sizingMethod='"+sizing+"'":"") + ")";
+		}else{
+			img=document.createElement("img");
+			img.src=url;
+		}
+		img.style.position="absolute";
+		img.style[vertAttach]=vertCoord+"px";
+		img.style[horzAttach]=horzCoord+"px";
+		img.style.width=this.shadowThickness+"px";
+		img.style.height=this.shadowThickness+"px";
+		this.pieces[name]=img;
+		this.node.appendChild(img);
+	},
+
+	size: function(width, height){
+		var sideHeight = height - (this.shadowOffset+this.shadowThickness+1);
+		with(this.pieces){
+			l.style.height = sideHeight+"px";
+			r.style.height = sideHeight+"px";
+			b.style.width = (width-1)+"px";
+			bl.style.top = (height-1)+"px";
+			b.style.top = (height-1)+"px";
+			br.style.top = (height-1)+"px";
+			tr.style.left = (width-1)+"px";
+			r.style.left = (width-1)+"px";
+			br.style.left = (width-1)+"px";
+		}
+	}
+});
+