You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/09/23 01:22:51 UTC

svn commit: r449122 [23/40] - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/ java/org/apache/tapestry/dojo/ java/org/apache/tapestry/dojo/form/ java/org/apache/tapestry/dojo/html/ java/org/apache/tapestry/form/ java/org/...

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/AnimatedPng.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/AnimatedPng.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/AnimatedPng.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/AnimatedPng.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,81 @@
+/*
+	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.widget.AnimatedPng");
+dojo.provide("dojo.widget.AnimatedPng");
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.HtmlWidget");
+
+
+dojo.widget.defineWidget(
+	"dojo.widget.AnimatedPng",
+	dojo.widget.HtmlWidget,
+	{
+		isContainer: false,
+
+		domNode: null,
+		width: 0,
+		height: 0,
+		aniSrc: '',
+		interval: 100,
+
+		cellWidth: 0,
+		cellHeight: 0,
+		aniCols: 1,
+		aniRows: 1,
+		aniCells: 1,
+
+		blankSrc: dojo.uri.dojoUri("src/widget/templates/images/blank.gif"),
+
+		templateString: '<img class="dojoAnimatedPng" />',
+
+		postCreate: function(){
+			this.cellWidth = this.width;
+			this.cellHeight = this.height;
+
+			var img = new Image();
+			var self = this;
+
+			img.onload = function(){ self.initAni(img.width, img.height); };
+			img.src = this.aniSrc;
+		},
+
+		initAni: function(w, h){
+
+			this.domNode.src = this.blankSrc;
+			this.domNode.width = this.cellWidth;
+			this.domNode.height = this.cellHeight;
+			this.domNode.style.backgroundImage = 'url('+this.aniSrc+')';
+			this.domNode.style.backgroundRepeat = 'no-repeat';
+
+			this.aniCols = Math.floor(w/this.cellWidth);
+			this.aniRows = Math.floor(h/this.cellHeight);
+			this.aniCells = this.aniCols * this.aniRows;
+			this.aniFrame = 0;
+
+			window.setInterval(dojo.lang.hitch(this, 'tick'), this.interval);
+		},
+
+		tick: function(){
+
+			this.aniFrame++;
+			if (this.aniFrame == this.aniCells) this.aniFrame = 0;
+
+			var col = this.aniFrame % this.aniCols;
+			var row = Math.floor(this.aniFrame / this.aniCols);
+
+			var bx = -1 * col * this.cellWidth;
+			var by = -1 * row * this.cellHeight;
+
+			this.domNode.style.backgroundPosition = bx+'px '+by+'px';
+		}
+	}
+);

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/AnimatedPng.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Button.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Button.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Button.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Button.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,353 @@
+/*
+	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.widget.Button");
+
+dojo.require("dojo.lang.extras");
+dojo.require("dojo.html.*");
+dojo.require("dojo.html.selection");
+dojo.require("dojo.widget.*");
+
+dojo.widget.defineWidget(
+	"dojo.widget.Button",
+	dojo.widget.HtmlWidget,
+	{
+		isContainer: true,
+
+		// Constructor arguments
+		caption: "",
+		disabled: false,
+	
+		templatePath: dojo.uri.dojoUri("src/widget/templates/ButtonTemplate.html"),
+		templateCssPath: dojo.uri.dojoUri("src/widget/templates/ButtonTemplate.css"),
+		
+		// button images
+		inactiveImg: "src/widget/templates/images/soriaButton-",
+		activeImg: "src/widget/templates/images/soriaActive-",
+		pressedImg: "src/widget/templates/images/soriaPressed-",
+		disabledImg: "src/widget/templates/images/soriaDisabled-",
+		width2height: 1.0/3.0,
+	
+		// attach points
+		buttonNode: null,
+		containerNode: null,
+		leftImage: null,
+		centerImage: null,
+		rightImage: null,
+	
+		fillInTemplate: function(args, frag){
+			if(this.caption != ""){
+				this.containerNode.appendChild(document.createTextNode(this.caption));
+			}
+			dojo.html.disableSelection(this.containerNode);
+		},
+
+		postCreate: function(args, frag){
+			this.sizeMyself();
+		},
+	
+		sizeMyself: function(){
+			// we cannot size correctly if any of our ancestors are hidden (display:none),
+			// so temporarily attach to document.body
+			if(this.domNode.parentNode){
+				var placeHolder = document.createElement("span");
+				dojo.html.insertBefore(placeHolder, this.domNode);
+			}
+			dojo.body().appendChild(this.domNode);
+			
+			this.sizeMyselfHelper();
+			
+			// Put this.domNode back where it was originally
+			if(placeHolder){
+				dojo.html.insertBefore(this.domNode, placeHolder);
+				dojo.html.removeNode(placeHolder);
+			}
+		},
+
+		sizeMyselfHelper: function(){
+			var mb = dojo.html.getMarginBox(this.containerNode);
+			this.height = mb.height;
+			this.containerWidth = mb.width;
+			var endWidth= this.height * this.width2height;
+	
+			this.containerNode.style.left=endWidth+"px";
+	
+			this.leftImage.height = this.rightImage.height = this.centerImage.height = this.height;
+			this.leftImage.width = this.rightImage.width = endWidth+1;
+			this.centerImage.width = this.containerWidth;
+			this.centerImage.style.left=endWidth+"px";
+			this._setImage(this.disabled ? this.disabledImg : this.inactiveImg);
+
+			if ( this.disabled ) {
+				dojo.html.prependClass(this.domNode, "dojoButtonDisabled");
+				this.domNode.removeAttribute("tabIndex");
+				dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", true);
+			} else {
+				dojo.html.removeClass(this.domNode, "dojoButtonDisabled");
+				this.domNode.setAttribute("tabIndex", "0");
+				dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", false);
+			}
+				
+			this.domNode.style.height=this.height + "px";
+			this.domNode.style.width= (this.containerWidth+2*endWidth) + "px";
+		},
+	
+		onMouseOver: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.prependClass(this.buttonNode, "dojoButtonHover");
+			this._setImage(this.activeImg);
+		},
+	
+		onMouseDown: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.prependClass(this.buttonNode, "dojoButtonDepressed");
+			dojo.html.removeClass(this.buttonNode, "dojoButtonHover");
+			this._setImage(this.pressedImg);
+		},
+		onMouseUp: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.prependClass(this.buttonNode, "dojoButtonHover");
+			dojo.html.removeClass(this.buttonNode, "dojoButtonDepressed");
+			this._setImage(this.activeImg);
+		},
+	
+		onMouseOut: function(e){
+			if( this.disabled ){ return; }
+			if( e.toElement && dojo.html.isDescendantOf(e.toElement, this.buttonNode) ){
+				return; // Ignore IE mouseOut events that dont actually leave button - Prevents hover image flicker in IE
+			}
+			dojo.html.removeClass(this.buttonNode, "dojoButtonHover");
+			this._setImage(this.inactiveImg);
+		},
+
+		onKey: function(e){
+			if (!e.key) { return; }
+			var menu = dojo.widget.getWidgetById(this.menuId);
+			if (e.key == e.KEY_ENTER || e.key == " "){
+				this.onMouseDown(e);
+				this.buttonClick(e);
+				dojo.lang.setTimeout(this, "onMouseUp", 75, e);
+				e.preventDefault();
+				e.stopPropagation();
+			}
+			if(menu && menu.isShowingNow && e.key == e.KEY_DOWN_ARROW){
+				// disconnect onBlur when focus moves into menu
+				dojo.event.disconnect(this.domNode, "onblur", this, "onBlur");
+				// allow event to propagate to menu
+			}
+		},
+
+		onFocus: function(e){
+			var menu = dojo.widget.getWidgetById(this.menuId);
+			if (menu ){
+				dojo.event.connectOnce(this.domNode, "onblur", this, "onBlur");
+			}
+		},
+
+		onBlur: function(e){
+			var menu = dojo.widget.getWidgetById(this.menuId);
+			if ( !menu ) { return; }
+	
+			if ( menu.close && menu.isShowingNow ){
+				menu.close();
+			}
+		},
+
+		buttonClick: function(e){
+			if( !this.disabled ) { this.onClick(e); }
+		},
+
+		onClick: function(e) { },
+
+		_setImage: function(prefix){
+			this.leftImage.src=dojo.uri.dojoUri(prefix + "l.gif");
+			this.centerImage.src=dojo.uri.dojoUri(prefix + "c.gif");
+			this.rightImage.src=dojo.uri.dojoUri(prefix + "r.gif");
+		},
+		
+		_toggleMenu: function(menuId){
+			var menu = dojo.widget.getWidgetById(menuId); 
+			if ( !menu ) { return; }
+			if ( menu.open && !menu.isShowingNow) {
+				var pos = dojo.html.getAbsolutePosition(this.domNode, false);
+				menu.open(pos.x, pos.y+this.height, this);
+			} else if ( menu.close && menu.isShowingNow ){
+				menu.close();
+			} else {
+				menu.toggle();
+			}
+		},
+		
+		setCaption: function(content){
+			this.caption=content;
+			this.containerNode.innerHTML=content;
+			this.sizeMyself();
+		},
+		
+		setDisabled: function(disabled){
+			this.disabled=disabled;
+			this.sizeMyself();
+		}
+	});
+
+/**** DropDownButton - push the button and a menu shows up *****/
+dojo.widget.defineWidget(
+	"dojo.widget.DropDownButton",
+	dojo.widget.Button,
+	{
+		menuId: "",
+
+		arrow: null,
+	
+		downArrow: "src/widget/templates/images/whiteDownArrow.gif",
+		disabledDownArrow: "src/widget/templates/images/whiteDownArrow.gif",
+	
+		fillInTemplate: function(args, frag){
+			dojo.widget.DropDownButton.superclass.fillInTemplate.call(this, args, frag);
+	
+			this.arrow = document.createElement("img");
+			dojo.html.setClass(this.arrow, "downArrow");
+
+			dojo.widget.wai.setAttr(this.domNode, "waiState", "haspopup", this.menuId);
+		},
+
+		sizeMyselfHelper: function(){
+			// draw the arrow (todo: why is the arror in containerNode rather than outside it?)
+			this.arrow.src = dojo.uri.dojoUri(this.disabled ? this.disabledDownArrow : this.downArrow);
+			this.containerNode.appendChild(this.arrow);
+
+			dojo.widget.DropDownButton.superclass.sizeMyselfHelper.call(this);
+		},
+
+		onClick: function (e){
+			this._toggleMenu(this.menuId);
+		}
+	});
+
+/**** ComboButton - left side is normal button, right side shows menu *****/
+dojo.widget.defineWidget(
+	"dojo.widget.ComboButton",
+	dojo.widget.Button,
+	{
+		menuId: "",
+	
+		templatePath: dojo.uri.dojoUri("src/widget/templates/ComboButtonTemplate.html"),
+	
+		// attach points
+		rightPart: null,
+		arrowBackgroundImage: null,
+	
+		// constants
+		splitWidth: 2,		// pixels between left&right part of button
+		arrowWidth: 5,		// width of segment holding down arrow
+	
+		sizeMyselfHelper: function(e){
+			var mb = dojo.html.getMarginBox(this.containerNode);
+			this.height = mb.height;
+			this.containerWidth = mb.width;
+
+			var endWidth= this.height/3;
+
+			if(this.disabled){
+				dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", true);
+				this.domNode.removeAttribute("tabIndex");
+			}
+			else {
+				dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", false);
+				this.domNode.setAttribute("tabIndex", "0");
+			}
+	
+			// left part
+			this.leftImage.height = this.rightImage.height = this.centerImage.height = 
+				this.arrowBackgroundImage.height = this.height;
+			this.leftImage.width = endWidth+1;
+			this.centerImage.width = this.containerWidth;
+			this.buttonNode.style.height = this.height + "px";
+			this.buttonNode.style.width = endWidth + this.containerWidth + "px";
+			this._setImage(this.disabled ? this.disabledImg : this.inactiveImg);
+
+			// right part
+			this.arrowBackgroundImage.width=this.arrowWidth;
+			this.rightImage.width = endWidth+1;
+			this.rightPart.style.height = this.height + "px";
+			this.rightPart.style.width = this.arrowWidth + endWidth + "px";
+			this._setImageR(this.disabled ? this.disabledImg : this.inactiveImg);
+	
+			// outer container
+			this.domNode.style.height=this.height + "px";
+			var totalWidth = this.containerWidth+this.splitWidth+this.arrowWidth+2*endWidth;
+			this.domNode.style.width= totalWidth + "px";
+		},
+	
+		_setImage: function(prefix){
+			this.leftImage.src=dojo.uri.dojoUri(prefix + "l.gif");
+			this.centerImage.src=dojo.uri.dojoUri(prefix + "c.gif");
+		},
+	
+		/*** functions on right part of button ***/
+		rightOver: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.prependClass(this.rightPart, "dojoButtonHover");
+			this._setImageR(this.activeImg);
+		},
+	
+		rightDown: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.prependClass(this.rightPart, "dojoButtonDepressed");
+			dojo.html.removeClass(this.rightPart, "dojoButtonHover");
+			this._setImageR(this.pressedImg);
+		},
+		rightUp: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.prependClass(this.rightPart, "dojoButtonHover");
+			dojo.html.removeClass(this.rightPart, "dojoButtonDepressed");
+			this._setImageR(this.activeImg);
+		},
+	
+		rightOut: function(e){
+			if( this.disabled ){ return; }
+			dojo.html.removeClass(this.rightPart, "dojoButtonHover");
+			this._setImageR(this.inactiveImg);
+		},
+
+		rightClick: function(e){
+			if( this.disabled ){ return; }
+			this._toggleMenu(this.menuId);
+		},
+	
+		_setImageR: function(prefix){
+			this.arrowBackgroundImage.src=dojo.uri.dojoUri(prefix + "c.gif");
+			this.rightImage.src=dojo.uri.dojoUri(prefix + "r.gif");
+		},
+
+		/*** keyboard functions ***/
+		
+		onKey: function(e){
+			if (!e.key) { return; }
+			var menu = dojo.widget.getWidgetById(this.menuId);
+			if(e.key== e.KEY_ENTER || e.key == " "){
+				this.onMouseDown(e);
+				this.buttonClick(e);
+				dojo.lang.setTimeout(this, "onMouseUp", 75, e);
+				e.preventDefault();
+				e.stopPropagation();
+			} else if (e.key == e.KEY_DOWN_ARROW && e.altKey){
+				this.rightDown(e);
+				this.rightClick(e);
+				dojo.lang.setTimeout(this, "rightUp", 75, e);
+				e.preventDefault();
+				e.stopPropagation();
+			} else if(menu && menu.isShowingNow && e.key == e.KEY_DOWN_ARROW){
+				// disconnect onBlur when focus moves into menu
+				dojo.event.disconnect(this.domNode, "onblur", this, "onBlur");
+				// allow event to propagate to menu
+			}
+		}
+	});

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Button.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Chart.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Chart.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Chart.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Chart.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,256 @@
+/*
+	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.widget.Chart");
+dojo.provide("dojo.widget.Chart.DataSeries");
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.gfx.color");
+dojo.require("dojo.gfx.color.hsl");
+
+// Base class for svg and vml implementations of Chart
+dojo.declare(
+	"dojo.widget.Chart",
+	null,
+	function(){
+		this.series = [];
+	},
+{
+	isContainer: false,
+
+	assignColors: function(){
+		var hue=30;
+		var sat=120;
+		var lum=120;
+		var steps = Math.round(330/this.series.length);
+
+		for(var i=0; i<this.series.length; i++){
+			var c=dojo.gfx.color.hsl2rgb(hue,sat,lum);
+			if(!this.series[i].color){
+				this.series[i].color = dojo.gfx.color.rgb2hex(c[0],c[1],c[2]);
+			}
+			hue += steps;
+		}
+	},
+	parseData: function(table){
+		var thead=table.getElementsByTagName("thead")[0];
+		var tbody=table.getElementsByTagName("tbody")[0];
+		if(!(thead&&tbody)) dojo.raise("dojo.widget.Chart: supplied table must define a head and a body.");
+
+		//	set up the series.
+		var columns=thead.getElementsByTagName("tr")[0].getElementsByTagName("th");	//	should be <tr><..>
+		
+		//	assume column 0 == X
+		for (var i=1; i<columns.length; i++){
+			var key="column"+i;
+			var label=columns[i].innerHTML;
+			var plotType=columns[i].getAttribute("plotType")||"line";
+			var color=columns[i].getAttribute("color");
+			var ds=new dojo.widget.Chart.DataSeries(key,label,plotType,color);
+			this.series.push(ds);
+		}
+
+		//	ok, get the values.
+		var rows=tbody.rows;
+		var xMin=Number.MAX_VALUE,xMax=Number.MIN_VALUE;
+		var yMin=Number.MAX_VALUE,yMax=Number.MIN_VALUE;
+		var ignore = [
+			"accesskey","align","bgcolor","class",
+			"colspan","height","id","nowrap",
+			"rowspan","style","tabindex","title",
+			"valign","width"
+		];
+
+		for(var i=0; i<rows.length; i++){
+			var row=rows[i];
+			var cells=row.cells;
+			var x=Number.MIN_VALUE;
+			for (var j=0; j<cells.length; j++){
+				if (j==0){
+					x=parseFloat(cells[j].innerHTML);
+					xMin=Math.min(xMin, x);
+					xMax=Math.max(xMax, x);
+				} else {
+					var ds=this.series[j-1];
+					var y=parseFloat(cells[j].innerHTML);
+					yMin=Math.min(yMin,y);
+					yMax=Math.max(yMax,y);
+					var o={x:x, value:y};
+					var attrs=cells[j].attributes;
+					for(var k=0; k<attrs.length; k++){
+						var attr=attrs.item(k);
+						var bIgnore=false;
+						for (var l=0; l<ignore.length; l++){
+							if (attr.nodeName.toLowerCase()==ignore[l]){
+								bIgnore=true;
+								break;
+							}
+						}
+						if(!bIgnore) o[attr.nodeName]=attr.nodeValue;
+					}
+					ds.add(o);
+				}
+			}
+		}
+		return { x:{ min:xMin, max:xMax}, y:{ min:yMin, max:yMax} };
+	}
+});
+
+/*
+ *	Every chart has a set of data series; this is the series.  Note that each
+ *	member of value is an object and in the minimum has 2 properties: .x and
+ *	.value.
+ */
+dojo.declare(
+	"dojo.widget.Chart.DataSeries",
+	null,
+	function(key, label, plotType, color){
+		this.id = "DataSeries"+dojo.widget.Chart.DataSeries.count++;
+		this.key = key;
+		this.label = label||this.id;
+		this.plotType = plotType||"line";	//	let line be the default.
+		this.color = color;
+		this.values = [];
+	},
+{
+	add: function(v){
+		if(v.x==null||v.value==null){
+			dojo.raise("dojo.widget.Chart.DataSeries.add: v must have both an 'x' and 'value' property.");
+		}
+		this.values.push(v);
+	},
+
+	clear: function(){
+		this.values=[];
+	},
+
+	createRange: function(len){
+		var idx = this.values.length-1;
+		var length = (len||this.values.length);
+		return { "index": idx, "length": length, "start":Math.max(idx-length,0) };
+	},
+
+	//	trend values
+	getMean: function(len){
+		var range = this.createRange(len);
+		if(range.index<0){ return 0; }
+		var t = 0;
+		var c = 0;
+		for(var i=range.index; i>=range.start; i--){
+			var n = parseFloat(this.values[i].value);
+			if(!isNaN(n)){ t += n; c++; }
+		}
+		t /= Math.max(c,1);
+		return t;
+	},
+
+	getMovingAverage: function(len){
+		var range = this.createRange(len);
+		if(range.index<0){ return 0; }
+		var t = 0;
+		var c = 0;
+		for(var i=range.index; i>=range.start; i--){
+			var n = parseFloat(this.values[i].value);
+			if(!isNaN(n)){ t += n; c++; }
+		}
+		t /= Math.max(c,1);
+		return t;
+	},
+
+	getVariance: function(len){
+		var range = this.createRange(len);
+		if(range.index < 0){ return 0; }
+		var t = 0; // FIXME: for tom: wtf are t, c, and s?
+		var s = 0;
+		var c = 0;
+		for(var i=range.index; i>=range.start; i--){
+			var n = parseFloat(this.values[i].value);
+			if(!isNaN(n)){
+				t += n;
+				s += Math.pow(n,2);
+				c++;
+			}
+		}
+		return (s/c)-Math.pow(t/c,2);
+	},
+
+	getStandardDeviation: function(len){
+		return Math.sqrt(this.getVariance(len));
+	},
+
+	getMax: function(len){
+		var range = this.createRange(len);
+		if(range.index < 0){ return 0; }
+		var t = 0;
+		for (var i=range.index; i>=range.start; i--){
+			var n=parseFloat(this.values[i].value);
+			if (!isNaN(n)){
+				t=Math.max(n,t);
+			}
+		}
+		return t;
+	},
+
+	getMin: function(len){
+		var range=this.createRange(len);
+		if(range.index < 0){ return 0; }
+		var t = 0;
+		for(var i=range.index; i>=range.start; i--){
+			var n = parseFloat(this.values[i].value);
+			if(!isNaN(n)){
+				t=Math.min(n,t);
+			}
+		}
+		return t;
+	},
+
+	getMedian: function(len){
+		var range = this.createRange(len);
+
+		if(range.index<0){ return 0; }
+
+		var a = [];
+		for (var i=range.index; i>=range.start; i--){
+			var n=parseFloat(this.values[i].value);
+			if (!isNaN(n)){
+				var b=false;
+				for(var j=0; j<a.length&&!b; j++){
+					if (n==a[j]) b=true; 
+				}
+				if(!b){ a.push(n); }
+			}
+		}
+		a.sort();
+		if(a.length>0){ return a[Math.ceil(a.length/2)]; }
+		return 0;
+	},
+
+	getMode: function(len){
+		var range=this.createRange(len);
+		if(range.index<0){ return 0; }
+		var o = {};
+		var ret = 0
+		var m = 0;
+		for(var i=range.index; i>=range.start; i--){
+			var n=parseFloat(this.values[i].value);
+			if(!isNaN(n)){
+				if (!o[this.values[i].value]) o[this.values[i].value] = 1;
+				else o[this.values[i].value]++;
+			}
+		}
+		for(var p in o){
+			if(m<o[p]){ m=o[p]; ret=p; }
+		}
+		return parseFloat(ret);
+	}
+});
+
+dojo["requireIf"](dojo.render.svg.capable, "dojo.widget.svg.Chart");
+dojo["requireIf"](!dojo.render.svg.capable && dojo.render.vml.capable, "dojo.widget.vml.Chart");

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Chart.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Checkbox.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Checkbox.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Checkbox.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Checkbox.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,140 @@
+/*
+	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.widget.Checkbox");
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.event.*");
+dojo.require("dojo.html.style");
+
+dojo.widget.defineWidget(
+	"dojo.widget.Checkbox",
+	dojo.widget.HtmlWidget,
+	{
+		templatePath: dojo.uri.dojoUri('src/widget/templates/Checkbox.html'),
+		templateCssPath: dojo.uri.dojoUri('src/widget/templates/Checkbox.css'),
+
+		// attributes
+		disabled: "enabled",
+		name: "",
+		checked: "",
+		tabIndex: "",
+		id: "",
+		value: "on",
+
+		postMixInProperties: function(){
+			dojo.widget.Checkbox.superclass.postMixInProperties.apply(this, arguments);
+			// set the variables referenced by the template
+			// valid HTML 4.01 and XHTML use disabled="disabled" - convert to boolean 
+			//NOTE: this doesn't catch disabled with no value if FF
+			this.disabled = (this.disabled == "disabled" || this.disabled == true);
+			// valid HTML 4.01 and XHTML require checked="checked"
+			// convert to boolean NOTE: this doesn't catch checked with no value in FF
+			this.checked = (this.checked == "checked" || this.checked == true);
+
+			// output valid checked and disabled attributes
+			this.disabledStr = this.disabled ? "disabled=\"disabled\"" : "";
+			this.checkedStr = this.checked ? "checked=\"checked\"" : "";
+
+			// set tabIndex="0" because if tabIndex=="" user won't be able to tab to the field
+
+
+			if(!this.disabled && this.tabIndex==""){ this.tabIndex="0"; }
+		},
+
+		postCreate: function(args, frag){
+			// find any associated label and create a labelled-by relationship
+			// assumes <label for="inputId">label text </label> rather than
+			// <label><input type="xyzzy">label text</label> 
+			if(this.id != ""){
+				var labels = document.getElementsByTagName("label");
+				if (labels != null && labels.length > 0){
+					for(var i=0; i<labels.length; i++){
+						if (labels[i].htmlFor == this.id){
+							labels[i].id = (labels[i].htmlFor + "label"); 
+							dojo.widget.wai.setAttr(this.domNode, "waiState", "labelledby", labels[i].id);
+							break;
+						}
+					}
+				}
+			}
+		},
+
+		fillInTemplate: function(){
+			this._setInfo();
+		},
+
+		_onClick: function(e){
+			if(this.disabled == false){
+				this.checked = !this.checked;
+				this._setInfo();
+			}
+			e.preventDefault();
+			this.onClick();
+		},
+
+		// user overridable function
+		onClick: function(){ },
+
+		onKey: function(e){
+			var k = dojo.event.browser.keys;
+			if(e.key == " "){
+	 			this._onClick(e);
+	 		}
+		},
+		
+		mouseOver: function(e){
+			this.hover(e, true);
+		},
+		
+		mouseOut: function(e){
+			this.hover(e, false);
+		},
+		
+		hover: function(e, isOver){
+			if (this.disabled == false){
+				var state = this.checked ? "On" : "Off";
+				var style = "dojoHtmlCheckbox" + state + "Hover";
+				if (isOver){
+					dojo.html.addClass(this.domNode, style);
+				}else{
+					dojo.html.removeClass(this.domNode,style);
+				}
+			}
+		},
+
+		// set CSS class string according to checked/unchecked and disabled/enabled state
+		_setInfo: function(){
+			var state = "dojoHtmlCheckbox" + (this.disabled ? "Disabled" : "") + (this.checked ? "On" : "Off");
+			dojo.html.setClass(this.domNode, "dojoHtmlCheckbox " + state);
+			this.inputNode.checked = this.checked;
+			dojo.widget.wai.setAttr(this.domNode, "waiState", "checked", this.checked);
+		}
+	}
+);
+dojo.widget.defineWidget(
+	"dojo.widget.a11y.Checkbox",
+	dojo.widget.Checkbox,
+	{	
+		templatePath: dojo.uri.dojoUri('src/widget/templates/CheckboxA11y.html'),
+		
+		postCreate: function(args, frag){
+			// nothing to do but don't want Checkbox version to run
+		},
+		
+		fillInTemplate: function(){
+		},
+		_onClick: function(){
+			this.onClick();
+		}
+	}
+);
+

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/Checkbox.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ColorPalette.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ColorPalette.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ColorPalette.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ColorPalette.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,156 @@
+/*
+	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.widget.ColorPalette");
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.Toolbar");
+dojo.require("dojo.html.layout");
+dojo.require("dojo.html.display");
+dojo.require("dojo.html.selection");
+
+dojo.widget.defineWidget(
+	"dojo.widget.ToolbarColorDialog",
+	dojo.widget.ToolbarDialog,
+{
+ 	palette: "7x10",
+
+	fillInTemplate: function (args, frag) {
+		dojo.widget.ToolbarColorDialog.superclass.fillInTemplate.call(this, args, frag);
+		this.dialog = dojo.widget.createWidget("ColorPalette", {palette: this.palette});
+		this.dialog.domNode.style.position = "absolute";
+
+		dojo.event.connect(this.dialog, "onColorSelect", this, "_setValue");
+	},
+
+	_setValue: function(color) {
+		this._value = color;
+		this._fireEvent("onSetValue", color);
+	},
+	
+	showDialog: function (e) {
+		dojo.widget.ToolbarColorDialog.superclass.showDialog.call(this, e);
+		var abs = dojo.html.getAbsolutePosition(this.domNode, true);
+		var y = abs.y + dojo.html.getBorderBox(this.domNode).height;
+		this.dialog.showAt(abs.x, y);
+	},
+	
+	hideDialog: function (e) {
+		dojo.widget.ToolbarColorDialog.superclass.hideDialog.call(this, e);
+		this.dialog.hide();
+	}
+});
+
+dojo.widget.defineWidget(
+	"dojo.widget.ColorPalette",
+	dojo.widget.HtmlWidget,
+{	
+	palette: "7x10",
+
+	bgIframe: null,
+	
+	palettes: {
+		"7x10": [["fff", "fcc", "fc9", "ff9", "ffc", "9f9", "9ff", "cff", "ccf", "fcf"],
+			["ccc", "f66", "f96", "ff6", "ff3", "6f9", "3ff", "6ff", "99f", "f9f"],
+			["c0c0c0", "f00", "f90", "fc6", "ff0", "3f3", "6cc", "3cf", "66c", "c6c"],
+			["999", "c00", "f60", "fc3", "fc0", "3c0", "0cc", "36f", "63f", "c3c"],
+			["666", "900", "c60", "c93", "990", "090", "399", "33f", "60c", "939"],
+			["333", "600", "930", "963", "660", "060", "366", "009", "339", "636"],
+			["000", "300", "630", "633", "330", "030", "033", "006", "309", "303"]],
+	
+		"3x4": [["ffffff"/*white*/, "00ff00"/*lime*/, "008000"/*green*/, "0000ff"/*blue*/],
+			["c0c0c0"/*silver*/, "ffff00"/*yellow*/, "ff00ff"/*fuchsia*/, "000080"/*navy*/],
+			["808080"/*gray*/, "ff0000"/*red*/, "800080"/*purple*/, "000000"/*black*/]]
+			//["00ffff"/*aqua*/, "808000"/*olive*/, "800000"/*maroon*/, "008080"/*teal*/]];
+	},
+
+	buildRendering: function () {
+		this.domNode = document.createElement("table");
+//		dojo.body().appendChild(this.domNode);
+		dojo.html.disableSelection(this.domNode);
+		dojo.event.connect(this.domNode, "onmousedown", function (e) {
+			e.preventDefault();
+		});
+		with (this.domNode) { // set the table's properties
+			cellPadding = "0"; cellSpacing = "1"; border = "1";
+			style.backgroundColor = "white"; //style.position = "absolute";
+		}
+		var colors = this.palettes[this.palette];
+		for (var i = 0; i < colors.length; i++) {
+			var tr = this.domNode.insertRow(-1);
+			for (var j = 0; j < colors[i].length; j++) {
+				if (colors[i][j].length == 3) {
+					colors[i][j] = colors[i][j].replace(/(.)(.)(.)/, "$1$1$2$2$3$3");
+				}
+	
+				var td = tr.insertCell(-1);
+				with (td.style) {
+					backgroundColor = "#" + colors[i][j];
+					border = "1px solid gray";
+					width = height = "15px";
+					fontSize = "1px";
+				}
+	
+				td.color = "#" + colors[i][j];
+	
+				td.onmouseover = function (e) { this.style.borderColor = "white"; }
+				td.onmouseout = function (e) { this.style.borderColor = "gray"; }
+				dojo.event.connect(td, "onmousedown", this, "click");
+	
+				td.innerHTML = "&nbsp;";
+			}
+		}
+
+		if(dojo.render.html.ie){
+			this.bgIframe = document.createElement("<iframe frameborder='0' src='javascript:void(0);'>");
+			with(this.bgIframe.style){
+				position = "absolute";
+				left = top = "0px";
+				display = "none";
+			}
+			dojo.body().appendChild(this.bgIframe);
+			dojo.html.setOpacity(this.bgIframe, 0);
+		}
+	},
+
+	click: function (e) {
+		this.onColorSelect(e.currentTarget.color);
+		e.currentTarget.style.borderColor = "gray";
+	},
+
+	onColorSelect: function (color) { },
+
+	hide: function (){
+		this.domNode.parentNode.removeChild(this.domNode);
+		if(this.bgIframe){
+			this.bgIframe.style.display = "none";
+		}
+	},
+	
+	showAt: function (x, y) {
+		with(this.domNode.style){
+			top = y + "px";
+			left = x + "px";
+			zIndex = 999;
+		}
+		dojo.body().appendChild(this.domNode);
+		if(this.bgIframe){
+			with(this.bgIframe.style){
+				display = "block";
+				top = y + "px";
+				left = x + "px";
+				zIndex = 998;
+				var s = dojo.html.getMarginBox(this.domNode);
+				width = s.width + "px";
+				height = s.height + "px";
+			}
+
+		}
+	}
+});

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ColorPalette.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ComboBox.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ComboBox.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ComboBox.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ComboBox.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,820 @@
+/*
+	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.widget.ComboBox");
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.event.*");
+dojo.require("dojo.io.*");
+dojo.require("dojo.lfx.*");
+dojo.require("dojo.html.*");
+dojo.require("dojo.html.display");
+dojo.require("dojo.html.layout");
+dojo.require("dojo.html.iframe");
+dojo.require("dojo.string");
+dojo.require("dojo.widget.html.stabile");
+dojo.require("dojo.widget.PopupContainer");
+
+dojo.widget.incrementalComboBoxDataProvider = function(url, limit, timeout){
+	this.searchUrl = url;
+	this.inFlight = false;
+	this.activeRequest = null;
+	this.allowCache = false;
+
+	this.cache = {};
+
+	this.init = function(cbox){
+		this.searchUrl = cbox.dataUrl;
+	};
+
+	this.addToCache = function(keyword, data){
+		if(this.allowCache){
+			this.cache[keyword] = data;
+		}
+	};
+
+	this.startSearch = function(searchStr, type, ignoreLimit){
+		if(this.inFlight){
+			// FIXME: implement backoff!
+		}
+		var tss = encodeURIComponent(searchStr);
+		var realUrl = dojo.string.substituteParams(this.searchUrl, {"searchString": tss});
+		var _this = this;
+		var request = dojo.io.bind({
+			url: realUrl,
+			method: "get",
+			mimetype: "text/json",
+			load: function(type, data, evt){
+				_this.inFlight = false;
+				if(!dojo.lang.isArray(data)){
+					var arrData = [];
+					for(var key in data){
+						arrData.push([data[key], key]);
+					}
+					data = arrData;
+				}
+				_this.addToCache(searchStr, data);
+				_this.provideSearchResults(data);
+			}
+		});
+		this.inFlight = true;
+	};
+};
+
+dojo.widget.ComboBoxDataProvider = function(dataPairs, limit, timeout){
+	// NOTE: this data provider is designed as a naive reference
+	// implementation, and as such it is written more for readability than
+	// speed. A deployable data provider would implement lookups, search
+	// caching (and invalidation), and a significantly less naive data
+	// structure for storage of items.
+
+	this.data = [];
+	this.searchTimeout = timeout | 500;
+	this.searchLimit = limit | 30;
+	this.searchType = "STARTSTRING"; // may also be "STARTWORD" or "SUBSTRING"
+	this.caseSensitive = false;
+	// for caching optimizations
+	this._lastSearch = "";
+	this._lastSearchResults = null;
+
+	this.init = function(cbox, node){
+		if(!dojo.string.isBlank(cbox.dataUrl)){
+			this.getData(cbox.dataUrl);
+		}else{
+			// check to see if we can populate the list from <option> elements
+			if((node)&&(node.nodeName.toLowerCase() == "select")){
+				// NOTE: we're not handling <optgroup> here yet
+				var opts = node.getElementsByTagName("option");
+				var ol = opts.length;
+				var data = [];
+				for(var x=0; x<ol; x++){
+					var keyValArr = [String(opts[x].innerHTML), String(opts[x].value)];
+					data.push(keyValArr);
+					if(opts[x].selected){ 
+						cbox.setAllValues(keyValArr[0], keyValArr[1]);
+					}
+				}
+				this.setData(data);
+			}
+		}
+	};
+
+	this.getData = function(url){
+		dojo.io.bind({
+			url: url,
+			load: dojo.lang.hitch(this, function(type, data, evt){ 
+				if(!dojo.lang.isArray(data)){
+					var arrData = [];
+					for(var key in data){
+						arrData.push([data[key], key]);
+					}
+					data = arrData;
+				}
+				this.setData(data);
+			}),
+			mimetype: "text/json"
+		});
+	};
+
+	this.startSearch = function(searchStr, type, ignoreLimit){
+		// FIXME: need to add timeout handling here!!
+		this._preformSearch(searchStr, type, ignoreLimit);
+	};
+
+	this._preformSearch = function(searchStr, type, ignoreLimit){
+		//
+		//	NOTE: this search is LINEAR, which means that it exhibits perhaps
+		//	the worst possible speed characteristics of any search type. It's
+		//	written this way to outline the responsibilities and interfaces for
+		//	a search.
+		//
+		var st = type||this.searchType;
+		// FIXME: this is just an example search, which means that we implement
+		// only a linear search without any of the attendant (useful!) optimizations
+		var ret = [];
+		if(!this.caseSensitive){
+			searchStr = searchStr.toLowerCase();
+		}
+		for(var x=0; x<this.data.length; x++){
+			if((!ignoreLimit)&&(ret.length >= this.searchLimit)){
+				break;
+			}
+			// FIXME: we should avoid copies if possible!
+			var dataLabel = new String((!this.caseSensitive) ? this.data[x][0].toLowerCase() : this.data[x][0]);
+			if(dataLabel.length < searchStr.length){
+				// this won't ever be a good search, will it? What if we start
+				// to support regex search?
+				continue;
+			}
+
+			if(st == "STARTSTRING"){
+				if(searchStr == dataLabel.substr(0, searchStr.length)){
+					ret.push(this.data[x]);
+				}
+			}else if(st == "SUBSTRING"){
+				// this one is a gimmie
+				if(dataLabel.indexOf(searchStr) >= 0){
+					ret.push(this.data[x]);
+				}
+			}else if(st == "STARTWORD"){
+				// do a substring search and then attempt to determine if the
+				// preceeding char was the beginning of the string or a
+				// whitespace char.
+				var idx = dataLabel.indexOf(searchStr);
+				if(idx == 0){
+					// implicit match
+					ret.push(this.data[x]);
+				}
+				if(idx <= 0){
+					// if we didn't match or implicily matched, march onward
+					continue;
+				}
+				// otherwise, we have to go figure out if the match was at the
+				// start of a word...
+				// this code is taken almost directy from nWidgets
+				var matches = false;
+				while(idx!=-1){
+					// make sure the match either starts whole string, or
+					// follows a space, or follows some punctuation
+					if(" ,/(".indexOf(dataLabel.charAt(idx-1)) != -1){
+						// FIXME: what about tab chars?
+						matches = true; break;
+					}
+					idx = dataLabel.indexOf(searchStr, idx+1);
+				}
+				if(!matches){
+					continue;
+				}else{
+					ret.push(this.data[x]);
+				}
+			}
+		}
+		this.provideSearchResults(ret);
+	};
+
+	this.provideSearchResults = function(resultsDataPairs){
+	};
+
+	this.addData = function(pairs){
+		// FIXME: incredibly naive and slow!
+		this.data = this.data.concat(pairs);
+	};
+
+	this.setData = function(pdata){
+		// populate this.data and initialize lookup structures
+		this.data = pdata;
+	};
+	
+	if(dataPairs){
+		this.setData(dataPairs);
+	}
+};
+
+dojo.widget.defineWidget(
+	"dojo.widget.ComboBox",
+	dojo.widget.HtmlWidget,
+	{
+		// Applies to any renderer
+		isContainer: false,
+	
+		forceValidOption: false,
+		searchType: "stringstart",
+		dataProvider: null,
+	
+		startSearch: function(searchString){},
+		selectNextResult: function(){},
+		selectPrevResult: function(){},
+		setSelectedResult: function(){},
+
+		// HTML specific stuff
+		autoComplete: true,
+		name: "", // clone in the name from the DOM node
+		textInputNode: null,
+		comboBoxValue: null,
+		comboBoxSelectionValue: null,
+		optionsListWrapper: null,
+		optionsListNode: null,
+		downArrowNode: null,
+		cbTableNode: null,
+		searchTimer: null,
+		searchDelay: 100,
+		dataUrl: "",
+		fadeTime: 200,
+		// maxListLength limits list to X visible rows, scroll on rest 
+		maxListLength: 8, 
+		// mode can also be "remote" for JSON-returning live search or "html" for
+		// dumber live search
+		mode: "local", 
+		selectedResult: null,
+		_highlighted_option: null,
+		_prev_key_backspace: false,
+		_prev_key_esc: false,
+		_gotFocus: false,
+		_mouseover_list: false,
+		dataProviderClass: "dojo.widget.ComboBoxDataProvider",
+		buttonSrc: dojo.uri.dojoUri("src/widget/templates/images/combo_box_arrow.png"),
+
+		//the old implementation has builtin fade toggle, so we mimic it here
+		dropdownToggle: "fade",
+
+		templatePath: dojo.uri.dojoUri("src/widget/templates/ComboBox.html"),
+		templateCssPath: dojo.uri.dojoUri("src/widget/templates/ComboBox.css"),
+
+
+		setValue: function(value) {
+			this.comboBoxValue.value = value;
+			if (this.textInputNode.value != value) { // prevent mucking up of selection
+				this.textInputNode.value = value;
+				// only change state and value if a new value is set
+				dojo.widget.html.stabile.setState(this.widgetId, this.getState(), true);
+				this.onValueChanged(value);
+			}
+		},
+
+		// for user to override
+		onValueChanged: function(){ },
+
+		getValue: function() {
+			return this.comboBoxValue.value;
+		},
+	
+		getState: function() {
+			return {value: this.getValue()};
+		},
+
+		setState: function(state) {
+			this.setValue(state.value);
+		},
+
+		getCaretPos: function(element){
+			// khtml 3.5.2 has selection* methods as does webkit nightlies from 2005-06-22
+			if(dojo.lang.isNumber(element.selectionStart)){
+				// FIXME: this is totally borked on Moz < 1.3. Any recourse?
+				return element.selectionStart;
+			}else if(dojo.render.html.ie){
+				// in the case of a mouse click in a popup being handled,
+				// then the document.selection is not the textarea, but the popup
+				// var r = document.selection.createRange();
+				// hack to get IE 6 to play nice. What a POS browser.
+				var tr = document.selection.createRange().duplicate();
+				var ntr = element.createTextRange();
+				tr.move("character",0);
+				ntr.move("character",0);
+				try {
+					// If control doesnt have focus, you get an exception.
+					// Seems to happen on reverse-tab, but can also happen on tab (seems to be a race condition - only happens sometimes).
+					// There appears to be no workaround for this - googled for quite a while.
+					ntr.setEndPoint("EndToEnd", tr);
+					return String(ntr.text).replace(/\r/g,"").length;
+				} catch (e) {
+					return 0; // If focus has shifted, 0 is fine for caret pos.
+				}
+				
+			}
+		},
+
+		setCaretPos: function(element, location){
+			location = parseInt(location);
+			this.setSelectedRange(element, location, location);
+		},
+
+		setSelectedRange: function(element, start, end){
+			if(!end){ end = element.value.length; }  // NOTE: Strange - should be able to put caret at start of text?
+			// Mozilla
+			// parts borrowed from http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
+			if(element.setSelectionRange){
+				element.focus();
+				element.setSelectionRange(start, end);
+			}else if(element.createTextRange){ // IE
+				var range = element.createTextRange();
+				with(range){
+					collapse(true);
+					moveEnd('character', end);
+					moveStart('character', start);
+					select();
+				}
+			}else{ //otherwise try the event-creation hack (our own invention)
+				// do we need these?
+				element.value = element.value;
+				element.blur();
+				element.focus();
+				// figure out how far back to go
+				var dist = parseInt(element.value.length)-end;
+				var tchar = String.fromCharCode(37);
+				var tcc = tchar.charCodeAt(0);
+				for(var x = 0; x < dist; x++){
+					var te = document.createEvent("KeyEvents");
+					te.initKeyEvent("keypress", true, true, null, false, false, false, false, tcc, tcc);
+					element.dispatchEvent(te);
+				}
+			}
+		},
+
+		// does the keyboard related stuff
+		_handleKeyEvents: function(evt){
+			if(evt.ctrlKey || evt.altKey || !evt.key){ return; }
+
+			// reset these
+			this._prev_key_backspace = false;
+			this._prev_key_esc = false;
+
+			var k = dojo.event.browser.keys;
+			var doSearch = true;
+
+			switch(evt.key){
+	 			case k.KEY_DOWN_ARROW:
+					if(!this.popupWidget.isShowingNow){
+						this.startSearchFromInput();
+					}
+					this.highlightNextOption();
+					dojo.event.browser.stopEvent(evt);
+					return;
+				case k.KEY_UP_ARROW:
+					this.highlightPrevOption();
+					dojo.event.browser.stopEvent(evt);
+					return;
+				case k.KEY_TAB:
+					// using linux alike tab for autocomplete
+					if(!this.autoComplete && this.popupWidget.isShowingNow && this._highlighted_option){
+						dojo.event.browser.stopEvent(evt);
+						this.selectOption({ 'target': this._highlighted_option, 'noHide': false});
+	
+						// put caret last
+						this.setSelectedRange(this.textInputNode, this.textInputNode.value.length, null);
+					}else{
+						this.selectOption();
+						return;
+					}
+					break;
+				case k.KEY_ENTER:
+					// prevent submitting form if we press enter with list open
+					if(this.popupWidget.isShowingNow){
+						dojo.event.browser.stopEvent(evt);
+					}
+					// fallthrough
+				case " ":
+					if(this.popupWidget.isShowingNow && this._highlighted_option){
+						dojo.event.browser.stopEvent(evt);
+						this.selectOption();
+						this.hideResultList();
+						return;
+					}
+					break;
+				case k.KEY_ESCAPE:
+					this.hideResultList();
+					this._prev_key_esc = true;
+					return;
+				case k.KEY_BACKSPACE:
+					this._prev_key_backspace = true;
+					if(!this.textInputNode.value.length){
+						this.setAllValues("", "");
+						this.hideResultList();
+						doSearch = false;
+					}
+					break;
+				case k.KEY_RIGHT_ARROW: // fall through
+				case k.KEY_LEFT_ARROW: // fall through
+					doSearch = false;
+					break;
+				default:// non char keys (F1-F12 etc..)  shouldn't open list
+					if(evt.charCode==0){
+						doSearch = false;
+					}
+			}
+
+			if(this.searchTimer){
+				clearTimeout(this.searchTimer);
+			}
+			if(doSearch){
+				// if we have gotten this far we dont want to keep our highlight
+				this.blurOptionNode();
+	
+				// need to wait a tad before start search so that the event bubbles through DOM and we have value visible
+				this.searchTimer = setTimeout(dojo.lang.hitch(this, this.startSearchFromInput), this.searchDelay);
+			}
+		},
+
+		// When inputting characters using an input method, such as Asian  
+		// languages, it will generate this event instead of onKeyDown event 
+		compositionEnd: function(evt){
+			evt.key = evt.keyCode;
+			this._handleKeyEvents(evt);
+		},
+
+		onKeyUp: function(evt){
+			this.setValue(this.textInputNode.value);
+		},
+
+		setSelectedValue: function(value){
+			// FIXME, not sure what to do here!
+			this.comboBoxSelectionValue.value = value;
+		},
+
+		setAllValues: function(value1, value2){
+			this.setValue(value1);
+			this.setSelectedValue(value2);
+		},
+
+		// does the actual highlight
+		focusOptionNode: function(node){
+			if(this._highlighted_option != node){
+				this.blurOptionNode();
+				this._highlighted_option = node;
+				dojo.html.addClass(this._highlighted_option, "dojoComboBoxItemHighlight");
+			}
+		},
+
+		// removes highlight on highlighted
+		blurOptionNode: function(){
+			if(this._highlighted_option){
+				dojo.html.removeClass(this._highlighted_option, "dojoComboBoxItemHighlight");
+				this._highlighted_option = null;
+			}
+		},
+
+		highlightNextOption: function(){
+			if((!this._highlighted_option) || !this._highlighted_option.parentNode){
+				this.focusOptionNode(this.optionsListNode.firstChild);
+			}else if(this._highlighted_option.nextSibling){
+				this.focusOptionNode(this._highlighted_option.nextSibling);
+			}
+			dojo.html.scrollIntoView(this._highlighted_option);
+		},
+
+		highlightPrevOption: function(){
+			if(this._highlighted_option && this._highlighted_option.previousSibling){
+				this.focusOptionNode(this._highlighted_option.previousSibling);
+			}else{
+				this._highlighted_option = null;
+				this.hideResultList();
+				return;
+			}
+			dojo.html.scrollIntoView(this._highlighted_option);
+		},
+
+		itemMouseOver: function(evt){
+			if (evt.target === this.optionsListNode) { return; }
+			this.focusOptionNode(evt.target);
+			dojo.html.addClass(this._highlighted_option, "dojoComboBoxItemHighlight");
+		},
+
+		itemMouseOut: function(evt){
+			if (evt.target === this.optionsListNode) { return; }
+			this.blurOptionNode();
+		},
+
+		// reset button size; this function is called when the input area has changed size
+		onResize: function(){
+			var inputSize = dojo.html.getBorderBox(this.textInputNode);
+			var buttonSize = { width: inputSize.height, height: inputSize.height};
+			dojo.html.setMarginBox(this.downArrowNode, buttonSize);
+		},
+
+		postMixInProperties: function(args, frag){
+			this.inherited("postMixInProperties", [args, frag]); 
+
+			// set image size before instantiating template;
+			// changing it afterwards doesn't work on FF
+			var inputNode = this.getFragNodeRef(frag);
+			var inputSize = dojo.html.getBorderBox(inputNode);
+			this.initialButtonSize = inputSize.height + "px";
+		},
+
+		fillInTemplate: function(args, frag){
+			// For inlining a table we need browser specific CSS
+			dojo.html.applyBrowserClass(this.domNode);
+
+			var source = this.getFragNodeRef(frag); 
+			if (! this.name && source.name){ this.name = source.name; } 
+			this.comboBoxValue.name = this.name; 
+			this.comboBoxSelectionValue.name = this.name+"_selected";
+
+			dojo.html.copyStyle(this.textInputNode, source);
+
+			var dpClass;
+			if(this.mode == "remote"){
+				dpClass = dojo.widget.incrementalComboBoxDataProvider;
+			}else if(typeof this.dataProviderClass == "string"){
+				dpClass = dojo.evalObjPath(this.dataProviderClass)
+			}else{
+				dpClass = this.dataProviderClass;
+			}
+			this.dataProvider = new dpClass();
+			this.dataProvider.init(this, this.getFragNodeRef(frag));
+
+			this.popupWidget = new dojo.widget.createWidget("PopupContainer", 
+				{toggle: this.dropdownToggle, toggleDuration: this.toggleDuration});
+			dojo.event.connect(this, 'destroy', this.popupWidget, 'destroy');
+			this.optionsListNode = this.popupWidget.domNode;
+			this.domNode.appendChild(this.optionsListNode);
+			dojo.html.addClass(this.optionsListNode, 'dojoComboBoxOptions');
+			dojo.event.connect(this.optionsListNode, 'onclick', this, 'selectOption');
+			dojo.event.connect(this.optionsListNode, 'onmouseover', this, '_onMouseOver');
+			dojo.event.connect(this.optionsListNode, 'onmouseout', this, '_onMouseOut');
+			
+			dojo.event.connect(this.optionsListNode, "onmouseover", this, "itemMouseOver");
+			dojo.event.connect(this.optionsListNode, "onmouseout", this, "itemMouseOut");
+		},
+
+		focus: function(){
+			// summary
+			//	set focus to input node from code
+			this.tryFocus();
+		},
+
+		openResultList: function(results){
+			this.clearResultList();
+			if(!results.length){
+				this.hideResultList();
+			}
+
+			if(	(this.autoComplete)&&
+				(results.length)&&
+				(!this._prev_key_backspace)&&
+				(this.textInputNode.value.length > 0)){
+				var cpos = this.getCaretPos(this.textInputNode);
+				// only try to extend if we added the last character at the end of the input
+				if((cpos+1) > this.textInputNode.value.length){
+					// only add to input node as we would overwrite Capitalisation of chars
+					this.textInputNode.value += results[0][0].substr(cpos);
+					// build a new range that has the distance from the earlier
+					// caret position to the end of the first string selected
+					this.setSelectedRange(this.textInputNode, cpos, this.textInputNode.value.length);
+				}
+			}
+
+			var even = true;
+			while(results.length){
+				var tr = results.shift();
+				if(tr){
+					var td = document.createElement("div");
+					td.appendChild(document.createTextNode(tr[0]));
+					td.setAttribute("resultName", tr[0]);
+					td.setAttribute("resultValue", tr[1]);
+					td.className = "dojoComboBoxItem "+((even) ? "dojoComboBoxItemEven" : "dojoComboBoxItemOdd");
+					even = (!even);
+					this.optionsListNode.appendChild(td);
+				}
+			}
+
+			// show our list (only if we have content, else nothing)
+			this.showResultList();
+		},
+
+		onFocusInput: function(){
+			this._hasFocus = true;
+		},
+
+		onBlurInput: function(){
+			this._hasFocus = false;
+			this._handleBlurTimer(true, 500);
+		},
+
+		// collect all blur timers issues here
+		_handleBlurTimer: function(/*Boolean*/clear, /*Number*/ millisec){
+			if(this.blurTimer && (clear || millisec)){
+				clearTimeout(this.blurTimer);
+			}
+			if(millisec){ // we ignore that zero is false and never sets as that never happens in this widget
+				this.blurTimer = dojo.lang.setTimeout(this, "checkBlurred", millisec);
+			}
+		},
+	
+		// these 2 are needed in IE and Safari as inputTextNode loses focus when scrolling optionslist
+		_onMouseOver: function(evt){
+			if(!this._mouseover_list){
+				this._handleBlurTimer(true, 0);
+				this._mouseover_list = true;
+			}
+		},
+
+		_onMouseOut:function(evt){
+			var relTarget = evt.relatedTarget;
+			if(!relTarget || relTarget.parentNode!=this.optionsListNode){
+				this._mouseover_list = false;
+				this._handleBlurTimer(true, 100);
+				this.tryFocus();
+			}
+		},
+
+		_isInputEqualToResult: function(result){
+			var input = this.textInputNode.value;
+			if(!this.dataProvider.caseSensitive){
+				input = input.toLowerCase();
+				result = result.toLowerCase();
+			}
+			return (input == result);
+		},
+
+		_isValidOption: function(){
+			var tgt = dojo.html.firstElement(this.optionsListNode);
+			var isValidOption = false;
+			var tgt = dojo.html.firstElement(this.optionsListNode);
+			var isValidOption = false;
+			while(!isValidOption && tgt){
+				if(this._isInputEqualToResult(tgt.getAttribute("resultName"))){
+					isValidOption = true;
+				}else{
+					tgt = dojo.html.nextElement(tgt);
+				}
+			}
+			return isValidOption;
+		},
+
+		checkBlurred: function(){
+			if(!this._hasFocus && !this._mouseover_list){
+				this.hideResultList();
+				// clear the list if the user empties field and moves away.
+				if(!this.textInputNode.value.length){
+					this.setAllValues("", "");
+					return;
+				}
+
+				var isValidOption = this._isValidOption();
+				// enforce selection from option list
+				if(this.forceValidOption && !isValidOption){
+					this.setAllValues("", "");
+					return;
+				}
+				if(!isValidOption){// clear
+					this.setSelectedValue("");
+				}
+			}
+		},
+
+		sizeBackgroundIframe: function(){
+			var mb = dojo.html.getMarginBox(this.optionsListNode);
+			if( mb.width==0 || mb.height==0 ){
+				// need more time to calculate size
+				dojo.lang.setTimeout(this, "sizeBackgroundIframe", 100);
+				return;
+			}
+		},
+
+		selectOption: function(evt){
+			var tgt = null;
+			if(!evt){
+				evt = { target: this._highlighted_option };
+			}
+
+			if(!dojo.html.isDescendantOf(evt.target, this.optionsListNode)){
+				// handle autocompletion where the the user has hit ENTER or TAB
+	
+				// if the input is empty do nothing
+				if(!this.textInputNode.value.length){
+					return;
+				}
+				tgt = dojo.html.firstElement(this.optionsListNode);
+
+				// user has input value not in option list
+				if(!tgt || !this._isInputEqualToResult(tgt.getAttribute("resultName"))){
+					return;
+				}
+				// otherwise the user has accepted the autocompleted value
+			}else{
+				tgt = evt.target; 
+			}
+
+			while((tgt.nodeType!=1)||(!tgt.getAttribute("resultName"))){
+				tgt = tgt.parentNode;
+				if(tgt === dojo.body()){
+					return false;
+				}
+			}
+
+			this.textInputNode.value = tgt.getAttribute("resultName");
+			this.selectedResult = [tgt.getAttribute("resultName"), tgt.getAttribute("resultValue")];
+			this.setAllValues(tgt.getAttribute("resultName"), tgt.getAttribute("resultValue"));
+			if(!evt.noHide){
+				this.hideResultList();
+				this.setSelectedRange(this.textInputNode, 0, null);
+			}
+			this.tryFocus();
+		},
+
+		clearResultList: function(){
+			if(this.optionsListNode.innerHTML){
+				this.optionsListNode.innerHTML = "";  // browser natively knows how to collect this memory
+			}
+		},
+
+		hideResultList: function(){
+			this.popupWidget.close();
+		},
+
+		showResultList: function(){
+			// Our dear friend IE doesnt take max-height so we need to calculate that on our own every time
+			var childs = this.optionsListNode.childNodes;
+			if(childs.length){
+				var visibleCount = this.maxListLength;
+				if(childs.length < visibleCount){
+					visibleCount = childs.length;
+				}
+
+				with(this.optionsListNode.style)
+				{
+					display = "";
+					if(visibleCount == childs.length){
+						//no scrollbar is required, so unset height to let browser calcuate it,
+						//as in css, overflow is already set to auto
+						height = "";
+					}else{
+						//show it first to get the correct dojo.style.getOuterHeight(childs[0])
+						//FIXME: shall we cache the height of the item?
+						height = visibleCount * dojo.html.getMarginBox(childs[0]).height +"px";
+					}
+					width = (dojo.html.getMarginBox(this.domNode).width-2)+"px";
+					
+				}
+				this.popupWidget.open(this.cbTableNode, this, this.downArrowNode);
+			}else{
+				this.hideResultList();
+			}
+		},
+
+		handleArrowClick: function(){
+			this._handleBlurTimer(true, 0);
+			this.tryFocus();
+			if(this.popupWidget.isShowingNow){
+				this.hideResultList();
+			}else{
+				// forces full population of results, if they click
+				// on the arrow it means they want to see more options
+				this.startSearch("");
+			}
+		},
+
+		tryFocus: function(){
+			try {
+				this.textInputNode.focus();
+			} catch (e) {
+				// element isn't focusable if disabled, or not visible etc - not easy to test for.
+	 		};
+		},
+
+		startSearchFromInput: function(){
+			this.startSearch(this.textInputNode.value);
+		},
+
+		postCreate: function(){
+			dojo.event.connect(this, "startSearch", this.dataProvider, "startSearch");
+			dojo.event.connect(this.dataProvider, "provideSearchResults", this, "openResultList");
+			dojo.event.connect(this.textInputNode, "onblur", this, "onBlurInput");
+			dojo.event.connect(this.textInputNode, "onfocus", this, "onFocusInput");
+
+			var s = dojo.widget.html.stabile.getState(this.widgetId);
+			if (s) {
+				this.setState(s);
+			}
+		}
+	}
+);
+
+

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ComboBox.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ContentPane.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ContentPane.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ContentPane.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ContentPane.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,560 @@
+/*
+	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
+*/
+
+// This widget doesn't do anything; is basically the same as <div>.
+// It's useful as a child of LayoutContainer, SplitContainer, or TabContainer.
+// But note that those classes can contain any widget as a child.
+
+dojo.provide("dojo.widget.ContentPane");
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.io.*");
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.string");
+dojo.require("dojo.string.extras");
+dojo.require("dojo.html.style");
+
+dojo.widget.defineWidget(
+	"dojo.widget.ContentPane",
+	dojo.widget.HtmlWidget,
+	function(){
+		// per widgetImpl variables
+		this._styleNodes =  [];
+		this._onLoadStack = [];
+		this._onUnLoadStack = [];
+		this._callOnUnLoad = false;
+		this.scriptScope; // undefined for now
+		this._ioBindObj;
+
+		// loading option
+		this.bindArgs = {}; // example bindArgs="preventCache:false;" overrides cacheContent
+	}, {
+		isContainer: true,
+
+		// loading options
+		adjustPaths: true, // fix relative paths in content to fit in this page
+		href: "", // only usable on construction, use setUrl or setContent after that
+		extractContent: true,	// extract visible content from inside of <body> .... </body>
+		parseContent:	true,	// construct all widgets that is in content
+		cacheContent:	true,
+		preload: false,	// force load of data even if pane is hidden
+		refreshOnShow: false,	// use with cacheContent: false
+		handler: "", // generate pane content from a java function
+		executeScripts: false,	// if true scripts in content will be evaled after content is innerHTML'ed
+		loadingMessage: "Loading...",
+
+		postCreate: function(args, frag, parentComp){
+			if (this.handler!==""){
+				this.setHandler(this.handler);
+			}
+			if(this.isShowing() || this.preload){
+				this.loadContents(); 
+			}
+		},
+	
+		show: function(){
+			// if refreshOnShow is true, reload the contents every time; otherwise, load only the first time
+			if(this.refreshOnShow){
+				this.refresh();
+			}else{
+				this.loadContents();
+			}
+			dojo.widget.ContentPane.superclass.show.call(this);
+		},
+	
+		refresh: function(){
+			this.isLoaded=false;
+			this.loadContents();
+		},
+	
+		loadContents: function() {
+			if ( this.isLoaded ){
+				return;
+			}
+			if ( dojo.lang.isFunction(this.handler)) {
+				this._runHandler();
+			} else if ( this.href != "" ) {
+				this._downloadExternalContent(this.href, this.cacheContent && !this.refreshOnShow);
+			}
+		},
+		
+		setUrl: function(/*String or dojo.uri.Uri*/ url) {
+			// summary:
+			// 	Reset the (external defined) content of this pane and replace with new url
+			this.href = url;
+			this.isLoaded = false;
+			if ( this.preload || this.isShowing() ){
+				this.loadContents();
+			}
+		},
+
+		abort: function(){
+			// summary
+			//	abort download of content
+			var bind = this._ioBindObj;
+			if(!bind || !bind.abort){ return; }
+			bind.abort();
+			delete this._ioBindObj;
+		},
+	
+		_downloadExternalContent: function(url, useCache) {
+			this.abort();
+			this._handleDefaults(this.loadingMessage, "onDownloadStart");
+			var self = this;
+			this._ioBindObj = dojo.io.bind(
+				this._cacheSetting({
+					url: url,
+					mimetype: "text/html",
+					handler: function(type, data, xhr){
+						delete self._ioBindObj; // makes sure abort doesnt clear cache
+						if(type=="load"){
+							self.onDownloadEnd.call(self, url, data);
+						}else{
+							// XHR insnt a normal JS object, IE doesnt have prototype on XHR so we cant extend it or shallowCopy it
+							var e = {
+								responseText: xhr.responseText,
+								status: xhr.status,
+								statusText: xhr.statusText,
+								responseHeaders: xhr.getAllResponseHeaders(),
+								_text: "Error loading '" + url + "' (" + xhr.status + " "+  xhr.statusText + ")"
+							};
+							self._handleDefaults.call(self, e, "onDownloadError");
+							self.onLoad();
+						}
+					}
+				}, useCache)
+			);
+		},
+	
+		_cacheSetting: function(bindObj, useCache){
+			for(var x in this.bindArgs){
+				if(dojo.lang.isUndefined(bindObj[x])){
+					bindObj[x] = this.bindArgs[x];
+				}
+			}
+
+			if(dojo.lang.isUndefined(bindObj.useCache)){ bindObj.useCache = useCache; }
+			if(dojo.lang.isUndefined(bindObj.preventCache)){ bindObj.preventCache = !useCache; }
+			if(dojo.lang.isUndefined(bindObj.mimetype)){ bindObj.mimetype = "text/html"; }
+			return bindObj;
+		},
+
+		// called when setContent is finished
+		onLoad: function(e){
+			this._runStack("_onLoadStack");
+			this.isLoaded=true;
+		},
+	
+		// called before old content is cleared
+		onUnLoad: function(e){
+			this._runStack("_onUnLoadStack");
+			delete this.scriptScope;
+		},
+	
+		_runStack: function(stName){
+			var st = this[stName]; var err = "";
+			var scope = this.scriptScope || window;
+			for(var i = 0;i < st.length; i++){
+				try{
+					st[i].call(scope);
+				}catch(e){ 
+					err += "\n"+st[i]+" failed: "+e.description;
+				}
+			}
+			this[stName] = [];
+	
+			if(err.length){
+				var name = (stName== "_onLoadStack") ? "addOnLoad" : "addOnUnLoad";
+				this._handleDefaults(name+" failure\n "+err, "onExecError", true);
+			}
+		},
+	
+		addOnLoad: function(/*Function or Object ?*/ obj, /*Function*/ func){
+			// summary
+			// 	same as to dojo.addOnLoad but does not take "function_name" as a string
+			this._pushOnStack(this._onLoadStack, obj, func);
+		},
+	
+		addOnUnLoad: function(/*Function or Object ?*/ obj, /*Function*/ func){
+			// summary
+			// 	same as to dojo.addUnOnLoad but does not take "function_name" as a string
+			this._pushOnStack(this._onUnLoadStack, obj, func);
+		},
+	
+		_pushOnStack: function(stack, obj, func){
+			if(typeof func == 'undefined') {
+				stack.push(obj);
+			}else{
+				stack.push(function(){ obj[func](); });
+			}
+		},
+	
+		destroy: function(){
+			// make sure we call onUnLoad
+			this.onUnLoad();
+			dojo.widget.ContentPane.superclass.destroy.call(this);
+		},
+	
+		// called when content script eval error or Java error occurs, preventDefault-able
+		onExecError: function(e){ /*stub*/ },
+	
+		// called on DOM faults, require fault etc in content, preventDefault-able
+		onContentError: function(e){ /*stub*/ },
+	
+		// called when download error occurs, preventDefault-able
+		onDownloadError: function(e){ /*stub*/ },
+	
+		// called before download starts, preventDefault-able
+		onDownloadStart: function(e){ /*stub*/ },
+	
+		// called when download is finished
+		onDownloadEnd: function(/*String*/ url, /*content*/ data){
+			data = this.splitAndFixPaths(data, url);
+			this.setContent(data);
+		},
+	
+		// usefull if user wants to prevent default behaviour ie: _setContent("Error...")
+		_handleDefaults: function(e, handler, useAlert){
+			if(!handler){ handler = "onContentError"; }
+
+			if(dojo.lang.isString(e)){ e = {_text: e}; }
+
+			if(!e._text){ e._text = e.toString(); }
+
+			e.toString = function(){ return this._text; };
+
+			if(typeof e.returnValue != "boolean"){
+				e.returnValue = true; 
+			}
+			if(typeof e.preventDefault != "function"){
+				e.preventDefault = function(){ this.returnValue = false; };
+			}
+			// call our handler
+			this[handler](e);
+			if(e.returnValue){
+				if(useAlert){
+					alert(e.toString());
+				}else{
+					// makes sure scripts can clean up after themselves, before we setContent
+					if(this._callOnUnLoad){ this.onUnLoad(); } 
+					this._callOnUnLoad = false; // makes sure we dont try to call onUnLoad again on this event,
+												// ie onUnLoad before 'Loading...' but not before clearing 'Loading...'
+					this._setContent(e.toString());
+				}
+			}
+		},
+	
+		// pathfixes, require calls, css stuff and neccesary content clean
+		splitAndFixPaths: function(/*String*/s, /*dojo.uri.Uri?*/url){
+			// summary:
+			// 	fixes all relative paths in (hopefully) all cases for example images, remote scripts, links etc.
+			// 	splits up content in different pieces, scripts, title, style, link and whats left becomes .xml
+
+			// init vars
+			var titles = [], scripts = [],tmp = [];
+			var match = [], requires = [], attr = [], styles = [];
+			var str = '', path = '', fix = '', tagFix = '', tag = '', origPath = '';
+	
+			if(!url) { url = "./"; } // point to this page if not set
+
+			if(s){ // make sure we dont run regexes on empty content
+
+				/************** <title> ***********/
+				// khtml is picky about dom faults, you can't attach a <style> or <title> node as child of body
+				// must go into head, so we need to cut out those tags
+				var regex = /<title[^>]*>([\s\S]*?)<\/title>/i;
+				while(match = regex.exec(s)){
+					titles.push(match[1]);
+					s = s.substring(0, match.index) + s.substr(match.index + match[0].length);
+				};
+		
+				/************** adjust paths *****************/
+				if(this.adjustPaths){
+					// attributepaths one tag can have multiple paths example:
+					// <input src="..." style="url(..)"/> or <a style="url(..)" href="..">
+					// strip out the tag and run fix on that.
+					// this guarantees that we won't run replace on another tag's attribute + it was easier do
+					var regexFindTag = /<[a-z][a-z0-9]*[^>]*\s(?:(?:src|href|style)=[^>])+[^>]*>/i;
+					var regexFindAttr = /\s(src|href|style)=(['"]?)([\w()\[\]\/.,\\'"-:;#=&?\s@]+?)\2/i;
+					// these are the supported protocols, all other is considered relative
+					var regexProtocols = /^(?:[#]|(?:(?:https?|ftps?|file|javascript|mailto|news):))/;
+		
+					while(tag = regexFindTag.exec(s)){
+						str += s.substring(0, tag.index);
+						s = s.substring((tag.index + tag[0].length), s.length);
+						tag = tag[0];
+			
+						// loop through attributes
+						tagFix = '';
+						while(attr = regexFindAttr.exec(tag)){
+							path = ""; origPath = attr[3];
+							switch(attr[1].toLowerCase()){
+								case "src":// falltrough
+								case "href":
+									if(regexProtocols.exec(origPath)){
+										path = origPath;
+									} else {
+										path = (new dojo.uri.Uri(url, origPath).toString());
+									}
+									break;
+								case "style":// style
+									path = dojo.html.fixPathsInCssText(origPath, url);
+									break;
+								default:
+									path = origPath;
+							}
+			
+							fix = " " + attr[1] + "=" + attr[2] + path + attr[2];
+		
+							// slices up tag before next attribute check
+							tagFix += tag.substring(0, attr.index) + fix;
+							tag = tag.substring((attr.index + attr[0].length), tag.length);
+						}
+						str += tagFix + tag; //dojo.debug(tagFix + tag);
+					}
+					s = str+s;
+				}
+
+				/****************  cut out all <style> and <link rel="stylesheet" href=".."> **************/
+				regex = /(?:<(style)[^>]*>([\s\S]*?)<\/style>|<link ([^>]*rel=['"]?stylesheet['"]?[^>]*)>)/i;
+				while(match = regex.exec(s)){
+					if(match[1] && match[1].toLowerCase() == "style"){
+						styles.push(dojo.html.fixPathsInCssText(match[2],url));
+					}else if(attr = match[3].match(/href=(['"]?)([^'">]*)\1/i)){
+						styles.push({path: attr[2]});
+					}
+					s = s.substring(0, match.index) + s.substr(match.index + match[0].length);
+				};
+
+				/***************** cut out all <script> tags, push them into scripts array ***************/
+				var regex = /<script([^>]*)>([\s\S]*?)<\/script>/i;
+				var regexSrc = /src=(['"]?)([^"']*)\1/i;
+				var regexDojoJs = /.*(\bdojo\b\.js(?:\.uncompressed\.js)?)$/;
+				var regexInvalid = /(?:var )?\bdjConfig\b(?:[\s]*=[\s]*\{[^}]+\}|\.[\w]*[\s]*=[\s]*[^;\n]*)?;?|dojo\.hostenv\.writeIncludes\(\s*\);?/g;
+				var regexRequires = /dojo\.(?:(?:require(?:After)?(?:If)?)|(?:widget\.(?:manager\.)?registerWidgetPackage)|(?:(?:hostenv\.)?setModulePrefix|registerModulePath)|defineNamespace)\((['"]).*?\1\)\s*;?/;
+
+				while(match = regex.exec(s)){
+					if(this.executeScripts && match[1]){
+						if(attr = regexSrc.exec(match[1])){
+							// remove a dojo.js or dojo.js.uncompressed.js from remoteScripts
+							// we declare all files named dojo.js as bad, regardless of path
+							if(regexDojoJs.exec(attr[2])){
+								dojo.debug("Security note! inhibit:"+attr[2]+" from  beeing loaded again.");
+							}else{
+								scripts.push({path: attr[2]});
+							}
+						}
+					}
+					if(match[2]){
+						// remove all invalid variables etc like djConfig and dojo.hostenv.writeIncludes()
+						var sc = match[2].replace(regexInvalid, "");
+						if(!sc){ continue; }
+		
+						// cut out all dojo.require (...) calls, if we have execute 
+						// scripts false widgets dont get there require calls
+						// takes out possible widgetpackage registration as well
+						while(tmp = regexRequires.exec(sc)){
+							requires.push(tmp[0]);
+							sc = sc.substring(0, tmp.index) + sc.substr(tmp.index + tmp[0].length);
+						}
+						if(this.executeScripts){
+							scripts.push(sc);
+						}
+					}
+					s = s.substr(0, match.index) + s.substr(match.index + match[0].length);
+				}
+
+				/********* extract content *********/
+				if(this.extractContent){
+					match = s.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
+					if(match) { s = match[1]; }
+				}
+	
+				/******** scan for scriptScope in html eventHandlers and replace with link to this pane *********/
+				if(this.executeScripts){
+					var regex = /(<[a-zA-Z][a-zA-Z0-9]*\s[^>]*\S=(['"])[^>]*[^\.\]])scriptScope([^>]*>)/;
+					str = "";
+					while(tag = regex.exec(s)){
+						tmp = ((tag[2]=="'") ? '"': "'");
+						str += s.substring(0, tag.index);
+						s = s.substr(tag.index).replace(regex, "$1dojo.widget.byId("+ tmp + this.widgetId + tmp + ").scriptScope$3");
+					}
+					s = str + s;
+				}
+	 		}
+
+			return {"xml": 		s, // Object
+				"styles":		styles,
+				"titles": 		titles,
+				"requires": 	requires,
+				"scripts": 		scripts,
+				"url": 			url};
+		},
+	
+		
+		_setContent: function(cont){
+			this.destroyChildren();
+	
+			// remove old stylenodes from HEAD
+			for(var i = 0; i < this._styleNodes.length; i++){
+				if(this._styleNodes[i] && this._styleNodes[i].parentNode){
+					this._styleNodes[i].parentNode.removeChild(this._styleNodes[i]);
+				}
+			}
+			this._styleNodes = [];
+	
+			var node = this.containerNode || this.domNode;
+			while(node.firstChild){
+				try{
+					dojo.event.browser.clean(node.firstChild);
+				}catch(e){}
+				node.removeChild(node.firstChild);
+			}
+			try{
+				if(typeof cont != "string"){
+					node.innerHTML = "";
+					node.appendChild(cont);
+				}else{
+					node.innerHTML = cont;
+				}
+			}catch(e){
+				e._text = "Could'nt load content:"+e.description;
+				this._handleDefaults(e, "onContentError");
+			}
+		},
+	
+		setContent: function(/*String or DOMNode*/ data){
+			// summary:
+			// 	Destroys old content and sets new content, and possibly initialize any widgets within 'data'
+			this.abort();
+			if(this._callOnUnLoad){ this.onUnLoad(); }// this tells a remote script clean up after itself
+			this._callOnUnLoad = true;
+	
+			if(!data || dojo.html.isNode(data)){
+				// if we do a clean using setContent(""); or setContent(#node) bypass all parsing, extractContent etc
+				this._setContent(data);
+				this.onResized();
+				this.onLoad();
+			}else{
+				// need to run splitAndFixPaths? ie. manually setting content
+				// adjustPaths is taken care of inside splitAndFixPaths
+				if(typeof data.xml != "string"){ 
+					this.href = ""; // so we can refresh safely
+					data = this.splitAndFixPaths(data); 
+				}
+
+				this._setContent(data.xml);
+
+				// insert styles from content (in same order they came in)
+				for(var i = 0; i < data.styles.length; i++){
+					if(data.styles[i].path){
+						this._styleNodes.push(dojo.html.insertCssFile(data.styles[i].path));
+					}else{
+						this._styleNodes.push(dojo.html.insertCssText(data.styles[i]));
+					}
+				}
+	
+				if(this.parseContent){
+					for(var i = 0; i < data.requires.length; i++){
+						try{
+							eval(data.requires[i]);
+						} catch(e){
+							e._text = "ContentPane: error in package loading calls, " + (e.description||e);
+							this._handleDefaults(e, "onContentError", true);
+						}
+					}
+				}
+				// need to allow async load, Xdomain uses it
+				// is inline function because we cant send args to dojo.addOnLoad
+				var _self = this;
+				function asyncParse(){
+					if(_self.executeScripts){
+						_self._executeScripts(data.scripts);
+					}
+	
+					if(_self.parseContent){
+						var node = _self.containerNode || _self.domNode;
+						var parser = new dojo.xml.Parse();
+						var frag = parser.parseElement(node, null, true);
+						// createSubComponents not createComponents because frag has already been created
+						dojo.widget.getParser().createSubComponents(frag, _self);
+					}
+	
+					_self.onResized();
+					_self.onLoad();
+				}
+				// try as long as possible to make setContent sync call
+				if(dojo.hostenv.isXDomain && data.requires.length){
+					dojo.addOnLoad(asyncParse);
+				}else{
+					asyncParse();
+				}
+			}
+		},
+	
+		// Generate pane content from given java function
+		setHandler: function(handler) {
+			var fcn = dojo.lang.isFunction(handler) ? handler : window[handler];
+			if(!dojo.lang.isFunction(fcn)) {
+				// FIXME: needs testing! somebody with java knowledge needs to try this
+				this._handleDefaults("Unable to set handler, '" + handler + "' not a function.", "onExecError", true);
+				return;
+			}
+			this.handler = function() {
+				return fcn.apply(this, arguments);
+			}
+		},
+	
+		_runHandler: function() {
+			var ret = true;
+			if(dojo.lang.isFunction(this.handler)) {
+				this.handler(this, this.domNode);
+				ret = false;
+			}
+			this.onLoad();
+			return ret;
+		},
+	
+		_executeScripts: function(scripts) {
+			// loop through the scripts in the order they came in
+			var self = this;
+			var tmp = "", code = "";
+			for(var i = 0; i < scripts.length; i++){
+				if(scripts[i].path){ // remotescript
+					dojo.io.bind(this._cacheSetting({
+						"url": 		scripts[i].path,
+						"load":     function(type, scriptStr){
+								dojo.lang.hitch(self, tmp = scriptStr);
+						},
+						"error":    function(type, error){
+								error._text = type + " downloading remote script";
+								self._handleDefaults.call(self, error, "onExecError", true);
+						},
+						"mimetype": "text/plain",
+						"sync":     true
+					}, this.cacheContent));
+					code += tmp;
+				}else{
+					code += scripts[i];
+				}
+			}
+	
+			try{
+				// initialize a new anonymous container for our script, dont make it part of this widgets scope chain
+				// instead send in a variable that points to this widget, usefull to connect events to onLoad, onUnLoad etc..
+				delete this.scriptScope;
+				this.scriptScope = new (new Function('_container_', code+'; return this;'))(self);
+			}catch(e){
+				e._text = "Error running scripts from content:\n"+e.description;
+				this._handleDefaults(e, "onExecError", true);
+			}
+		}
+	}
+);

Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/widget/ContentPane.js
------------------------------------------------------------------------------
    svn:eol-style = native