You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2007/09/27 20:26:51 UTC

svn commit: r580142 - in /incubator/xap/trunk/codebase/src/xap: bridges/basic/AbstractWidgetBridge.js util/CssUtils.js widgets/dojo/TreeTable.js

Author: jmargaris
Date: Thu Sep 27 13:26:47 2007
New Revision: 580142

URL: http://svn.apache.org/viewvc?rev=580142&view=rev
Log:
From Michael Mikhaylov: optimizations for CSS class manipulation on components.

Modified:
    incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js
    incubator/xap/trunk/codebase/src/xap/util/CssUtils.js
    incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js

Modified: incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js?rev=580142&r1=580141&r2=580142&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js Thu Sep 27 13:26:47 2007
@@ -26,6 +26,7 @@
 Xap.require("xap.session.ClientEvent");
 Xap.require("dojo.html.*");
 Xap.require("xap.util.ArrayHelper");
+Xap.require("xap.util.CssUtils");
 
  /*
  * TO_DO:  1.) Find better names for the methods that return DOM nodes (to be used as parents and children), will
@@ -86,6 +87,11 @@
  * </ol>
 **/ 
 xap.bridges.basic.AbstractWidgetBridge.prototype.init = function() {
+
+	// this doesn't do anything anyways
+	// xap.taghandling.AbstractTagImpl.prototype.init.call( this );
+
+
 	if ( !this._getNameToSetterMap()  ){
 		this.initialiseAttributeMaps() ;
 	} //If we needed to initialise the maps.==first use of this bridge class in session
@@ -117,7 +123,6 @@
 	this.parseInitialChildren( this.getElement() );
 	this.resetSize();
 	
-	xap.taghandling.AbstractTagImpl.prototype.init.call( this );
 }
 
 /**
@@ -372,9 +377,9 @@
 			//      "xapButton" + "Contents"+"MouseOver" 
 			// or
 			//      "xapButton" + ""+"MouseOver" 			
-			dojo.html.addClass(
+			xap.util.CssUtils.addClass(
 							pNode,
-							classNameStubs[ii]+pNodeLabel + pStateName);
+							classNameStubs[ii] + pNodeLabel + pStateName);
 		}	
 	}
 }
@@ -395,9 +400,9 @@
 			// or
 			//      "xapButton" + ""+"MouseOver" 			 
 			// ---the class to apply to a button's "root dom node"
-			dojo.html.removeClass(
+			xap.util.CssUtils.removeClass(
 							pNode,
-							classNameStubs[ii]+pNodeLabel + pStateName);
+							classNameStubs[ii] + pNodeLabel + pStateName);
 		}		
 	}
 }
@@ -1202,7 +1207,7 @@
 		}	
 		for( var idx=0; idx<arrClassStr.length ; ++idx){
 			//  For example:   aButton.contentsNode -->   myStyleContents
-			dojo.html.addClass( node ,arrClassStr[idx]+nodeLabel);
+			xap.util.CssUtils.addClass( node ,arrClassStr[idx] + nodeLabel);
 		}
 	}
 }
@@ -1262,10 +1267,9 @@
 	// surprisingly:
 	for(var nodeLabel in nodeMap){
 		for( var ii=0; ii<possibleStates.length; ++possibleStates){
-			dojo.html.removeClass(
+			xap.util.CssUtils.removeClass(
 								nodeMap[nodeLabel],
-								classStr +nodeLabel + possibleStates[ii]
-									);
+								classStr + nodeLabel + possibleStates[ii]);
 		}
 	}
 }
@@ -1290,10 +1294,9 @@
 		}	
 		for(var jj=0; jj<iClasses.length; ++jj){	
 			for( var ii=0; ii<possibleStates.length; ++ii){
-				dojo.html.removeClass(
+				xap.util.CssUtils.removeClass(
 								node,
-								iClasses[jj] +nodeLabel + possibleStates[ii]
-									);
+								iClasses[jj] +nodeLabel + possibleStates[ii]);
 			}
 		}
 	}

Modified: incubator/xap/trunk/codebase/src/xap/util/CssUtils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/util/CssUtils.js?rev=580142&r1=580141&r2=580142&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/util/CssUtils.js (original)
+++ incubator/xap/trunk/codebase/src/xap/util/CssUtils.js Thu Sep 27 13:26:47 2007
@@ -76,3 +76,100 @@
 	} 	
 	return null;
 };
+
+
+
+/**
+ *
+ *	This is the rewrite of DoJo's xxxClass() functions.
+ *
+ */
+
+xap.util.CssUtils.RE_LEADING_SPACES  = /^\s*/;
+xap.util.CssUtils.RE_TRAILING_SPACES = /\s*$/;
+
+xap.util.CssUtils.RE_BOTH_ENDS_SPACES = /^\s+|\s+$/g;
+
+
+/**
+ * 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;
+ */
+xap.util.CssUtils.getClass = function(/* HTMLElement */node){
+	
+	if(!node){ return ''; }
+	
+	var cs = node.className;
+	
+	if(!cs){
+		// get class string from an attribute
+		cs = node.getAttribute('class');
+	}
+	
+	// return trimmed string or ''
+	if(cs) {
+		// trim string to single trailing space
+		return cs.replace(xap.util.CssUtils.RE_BOTH_ENDS_SPACES, '');	
+	} else {
+		return '';
+	}
+};
+
+
+
+/**
+ * Replaces existing classes with
+ * the list given in the 2nd argument.
+ */
+xap.util.CssUtils.setClass = function(/* HTMLElement */node, /* string */classStr){
+	node.className = classStr.replace(xap.util.CssUtils.RE_BOTH_ENDS_SPACES, '');
+};
+
+
+/**
+ *  Returns an array of CSS classes currently assigned directly to the node in question.
+ * 	Returns an empty array if no classes are found;
+ *	@return and array of class names
+ */
+xap.util.CssUtils.getClasses = function(/* HTMLElement */node) {
+	var cs = xap.util.CssUtils.getClass(node);
+	return (cs === '') ? [] : cs.replace(xap.util.CssUtils.RE_BOTH_ENDS_SPACES, '').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.
+ */
+xap.util.CssUtils.hasClass = function(/* HTMLElement */node, /* string */classname){
+	var spacedClassName = classname.replace(xap.util.CssUtils.RE_LEADING_SPACES, '').replace(xap.util.CssUtils.RE_TRAILING_SPACES, ' ');
+	var spacedNodeClassName = xap.util.CssUtils.getClass(node).replace(xap.util.CssUtils.RE_TRAILING_SPACES, ' ');
+	return (spacedNodeClassName.indexOf(spacedClassName) >= 0);
+};
+
+
+/**
+ *
+ * Adds the specified class to the end of the class list on the
+ * passed &node;. Returns &true; or &false; indicating success or failure.
+ */
+xap.util.CssUtils.addClass = function(/* HTMLElement */node, /* string */classStr){
+	return xap.util.CssUtils.hasClass(node, classStr) ? 
+		false : xap.util.CssUtils.setClass(node, xap.util.CssUtils.getClass(node) +
+			classStr.replace(xap.util.CssUtils.RE_LEADING_SPACES, ' '));
+};
+
+
+/**
+ *
+ * Removes the className from the node;.
+ */
+xap.util.CssUtils.removeClass = function(/* HTMLElement */node, /* string */classStr) {
+	var cs = classStr.replace(xap.util.CssUtils.RE_BOTH_ENDS_SPACES, '');
+	xap.util.CssUtils.setClass(node,
+		xap.util.CssUtils.getClass(node).replace(cs, ''));
+};
+
+ 
+ 

Modified: incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js?rev=580142&r1=580141&r2=580142&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js Thu Sep 27 13:26:47 2007
@@ -31,6 +31,7 @@
 Xap.require("dojo.style");
 Xap.require("dojo.event");
 Xap.require("xap.util.ArrayHelper");
+Xap.require("xap.util.CssUtils");
 
 dojo.widget.tags.addParseTreeHandler("dojo:TreeTable");
 dojo.widget.tags.addParseTreeHandler("dojo:TableColumn");
@@ -350,7 +351,7 @@
 		this.headerDiv.style.width="100%";
 		this.headerDiv.style.position="relative";
 		this.headerDiv.style.textAlign="left";
-		dojo.html.addClass(this.headerDiv,'xapHeaderBackground');	
+		xap.util.CssUtils.addClass(this.headerDiv,'xapHeaderBackground');	
 
 		this.headerTable = document.createElement("table");
 		this.headerDiv.appendChild(this.headerTable);
@@ -373,7 +374,7 @@
 		this.headerBody.appendChild(this.headerRow);
 		for (var i = 0; i<this._columns.length; i++){
 			var cell = document.createElement("td");
-			dojo.html.addClass(cell,'xapHeaderWrapper');	
+			xap.util.CssUtils.addClass(cell,'xapHeaderWrapper');	
 			this.headerRow.appendChild(cell);
 			cell.style.whiteSpace = "nowrap";
 			if (this._columns[i]._header && this._columns[i]._header._rootDomNode){	
@@ -437,10 +438,10 @@
 		}
 	
 		if (isAlternateRow){
-			dojo.html.addClass(row.domNode,this._alternateRowClass);
+			xap.util.CssUtils.addClass(row.domNode,this._alternateRowClass);
 		}
 		else{
-			dojo.html.removeClass(row.domNode,this._alternateRowClass);
+			xap.util.CssUtils.removeClass(row.domNode,this._alternateRowClass);
 		}
 		
 		isAlternateRow = ! isAlternateRow;
@@ -585,7 +586,7 @@
 	 	if (this._selectionMode=="singleRow"){
 	 		this.clearSelection();
 	 	}
-	 	dojo.html.addClass(row.domNode,"selectedRow");
+	 	xap.util.CssUtils.addClass(row.domNode,"selectedRow");
 	 	this._selectedItems.push(row);
 	 	return true;
 	 },
@@ -602,7 +603,7 @@
 	 
 	 clearSelection : function(){
 	 	for (var i =0; i<this._selectedItems.length; i++){
-	 		dojo.html.removeClass(this._selectedItems[i].domNode,"selectedRow");
+	 		xap.util.CssUtils.removeClass(this._selectedItems[i].domNode,"selectedRow");
 	 		this.onDeselectRow(this._selectedItems[i]);
 	 	}
 	 	this._selectedItems = [];
@@ -649,9 +650,9 @@
 		//blank out the sort icon on the column we previously sorted
 		if (this._lastSortedColumn && (this._lastSortedColumn != column)){
 			var oldHint = this._lastSortedColumn ._header.getImgHint();
-			dojo.html.removeClass(oldHint,'xapSortDescendingImage');
-			dojo.html.removeClass(oldHint,'xapSortAscendingImage');	
-			dojo.html.addClass(oldHint,'xapSortNoneImage');	
+			xap.util.CssUtils.removeClass(oldHint,'xapSortDescendingImage');
+			xap.util.CssUtils.removeClass(oldHint,'xapSortAscendingImage');	
+			xap.util.CssUtils.addClass(oldHint,'xapSortNoneImage');	
 		}
 
 		var dataType = column._dataType || "string";
@@ -688,13 +689,13 @@
 		var headerHint = column._header.getImgHint();
 		if (!column._sort || column._sort=='descending'){
 			column._sort = "ascending";
-			dojo.html.removeClass(headerHint,'xapSortDescendingImage');
-			dojo.html.addClass(headerHint,'xapSortAscendingImage');	
+			xap.util.CssUtils.removeClass(headerHint,'xapSortDescendingImage');
+			xap.util.CssUtils.addClass(headerHint,'xapSortAscendingImage');	
 		}
 		else{
 			column._sort = "descending";
-			dojo.html.removeClass(headerHint,'xapSortAscendingImage');	
-			dojo.html.addClass(headerHint,'xapSortDescendingImage');
+			xap.util.CssUtils.removeClass(headerHint,'xapSortAscendingImage');	
+			xap.util.CssUtils.addClass(headerHint,'xapSortDescendingImage');
 			this._rows.reverse();
 		}
 
@@ -766,7 +767,7 @@
 	
 	setHeader: function( xapLabel ){
 		this._header = xapLabel;
-		dojo.html.addClass(xapLabel.getImgHint(),'xapSortNoneImage');
+		xap.util.CssUtils.addClass(xapLabel.getImgHint(),'xapSortNoneImage');
 		dojo.event.connect(xapLabel._rootDomNode, "onclick", this, "onClickCallback");
 		
 		// if there are explicit widths then save those
@@ -905,12 +906,12 @@
 		}		// Add column CSS class
 		// Use tdCount variable to locate column
 		if (this._table && this._table._columns && this._table._columns.length > 0 ) {
-			dojo.html.addClass(td, this._table._columns[tdCount]._localCSSClassName);
+			xap.util.CssUtils.addClass(td, this._table._columns[tdCount]._localCSSClassName);
 		}
 
 		// Add regular cell CSS class
 		if (this._table && this._table._tableCellClass) {
-			dojo.html.addClass(td, this._table._tableCellClass);
+			xap.util.CssUtils.addClass(td, this._table._tableCellClass);
 		}
 						
 		//TODO should we use style.textAlign instead of this
@@ -937,7 +938,7 @@
 		
 		var newClass = "";
 		if (this._imageClass){
-			dojo.html.removeClass(this._indentSpan, this._imageClass);
+			xap.util.CssUtils.removeClass(this._indentSpan, this._imageClass);
 		}
 		if (this._rows.length==0){
 			newClass = ""; // eventually add a class here to fix the indenting
@@ -948,7 +949,7 @@
 		else{
 			newClass = "ImgNodeCollapsed";
 		}
-		dojo.html.addClass(this._indentSpan, newClass);
+		xap.util.CssUtils.addClass(this._indentSpan, newClass);
 		this._imageClass=  newClass;
 	},