[richfaces-svn-commits] JBoss Rich Faces SVN: r2203 - trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Aug 10 12:11:08 EDT 2007


Author: pyaschenko
Date: 2007-08-10 12:11:08 -0400 (Fri, 10 Aug 2007)
New Revision: 2203

Modified:
   trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js
   trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
   trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js
   trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
Log:
$ optimization

Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js	2007-08-10 14:23:52 UTC (rev 2202)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js	2007-08-10 16:11:08 UTC (rev 2203)
@@ -54,7 +54,7 @@
 	},
 
 	getDropzoneOptions: function() {
-		var attr = Richfaces.getNSAttribute("dropzoneoptions", this.elements.icon);
+		var attr = Richfaces.getNSAttribute("dropzoneoptions", $(this.elementID.icon));
 		if (attr) {
 			return attr.parseJSON();
 		}
@@ -105,7 +105,7 @@
 	},
 	
 	getDraggableOptions: function() {
-		var attr = Richfaces.getNSAttribute("draggableoptions", this.elements.icon);
+		var attr = Richfaces.getNSAttribute("draggableoptions", $(this.elementID.icon));
 		if (attr) {
 			return attr.parseJSON();
 		}
@@ -124,6 +124,6 @@
 
 	getElement: function() {
 		//returns <tr> holding node without children
-		return this.elements.text.parentNode;
+		return $(this.elementID.text).parentNode;
 	}
 });
\ No newline at end of file

Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js	2007-08-10 14:23:52 UTC (rev 2202)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js	2007-08-10 16:11:08 UTC (rev 2203)
@@ -5,9 +5,20 @@
 		this.parent = parent;
 		this.id = id;
 		this.switchType = switchType;
-		this.tree = $(tree);
+		this.tree = tree;
 		this.elements = {};
-		//($(id)).object = this; //dublicate: see getElements()
+		this.elementID = {};
+
+		this.elementID.children = this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW;
+		this.elementID.mainRow = this.id + Tree.ID_DEVIDER + Tree.ID_MAIN_ROW;
+		this.elementID.handle = this.id + Tree.ID_DEVIDER + Tree.ID_HANDLE;
+		this.elementID.handleImgExpanded = this.elementID.handle + Tree.ID_DEVIDER + Tree.ID_HANDLE_IMG_EXPANDED;
+		this.elementID.handleImgCollapsed = this.elementID.handle + Tree.ID_DEVIDER + Tree.ID_HANDLE_IMG_COLLAPSED;
+		this.elementID.icon = this.id + Tree.ID_DEVIDER + Tree.ID_ICON;
+		this.elementID.text = this.id + Tree.ID_DEVIDER + Tree.ID_TEXT;
+		
+		($(this.id)).object = this;
+
 		this.toggleOnClick = toggleOnClick;
 		this.getElements();
 
@@ -23,55 +34,56 @@
 	},
 
 	observeEvents: function() {
-		Event.observe(this.elements.icon, "mousedown", this.eventSelectionClick);
-		Event.observe(this.elements.text, "mousedown", this.eventSelectionClick);
-		Event.observe(this.elements.icon, "mouseout", this.eventMouseOut);
-		Event.observe(this.elements.text, "mouseout", this.eventMouseOut);
-		Event.observe(this.elements.icon, "mouseover", this.eventMouseOver);
-		Event.observe(this.elements.text, "mouseover", this.eventMouseOver);
+		var eIcon = $(this.elementID.icon);
+		var eText = $(this.elementID.text);
+		if (eIcon) {
+			Event.observe(eIcon, "mousedown", this.eventSelectionClick);
+			Event.observe(eIcon, "mouseout", this.eventMouseOut);
+			Event.observe(eIcon, "mouseover", this.eventMouseOver);
+			if (this.eventRightClick) {
+				eIcon.oncontextmenu = this.eventRightClick;
+			}			
+		}
+		if (eText)
+		{
+			Event.observe(eText, "mousedown", this.eventSelectionClick);
+			Event.observe(eText, "mouseout", this.eventMouseOut);
+			Event.observe(eText, "mouseover", this.eventMouseOver);
+			if (this.eventRightClick) {
+				eText.oncontextmenu = this.eventRightClick;
+			}			
+		}
 
 		if (this.switchType=="client" && this.childs.length > 0) {
 			this.eventCollapsionClick = this.toggleCollapsion.bindAsEventListener(this);
 			if (this.toggleOnClick) {
-				if (this.elements.mainRow)
-					Event.observe(this.elements.mainRow, "click", this.eventCollapsionClick);
+					Event.observe(this.elementID.mainRow, "click", this.eventCollapsionClick);
 			} else {
-				if (this.elements.handle)
-					Event.observe(this.elements.handle, "click", this.eventCollapsionClick);
+				//if (this.elements.handle)
+					Event.observe(this.elementID.handle, "click", this.eventCollapsionClick);
 			}
 		}
-
-		if (this.eventRightClick) {
-			this.elements.icon.oncontextmenu = this.eventRightClick;
-			this.elements.text.oncontextmenu = this.eventRightClick;
-		}
 	},
 
 	getElements: function() {
-		($(this.id)).object = this; 
-		this.nodeStateInput = $(this.id + "NodeExpanded");
+		
 		this.childs = [];
-		var childsRowId = this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW;
-		var mainRowId = this.id + Tree.ID_DEVIDER + Tree.ID_MAIN_ROW;
-		this.elements.row = $(childsRowId);
-		var handleId = this.id + Tree.ID_DEVIDER + Tree.ID_HANDLE;
-		this.elements.handle = $(handleId);
-		this.elements.handleImgExpanded = $(handleId + Tree.ID_DEVIDER + Tree.ID_HANDLE_IMG_EXPANDED);
-		this.elements.handleImgCollapsed = $(handleId + Tree.ID_DEVIDER + Tree.ID_HANDLE_IMG_COLLAPSED);
-		this.elements.icon = $(this.id + Tree.ID_DEVIDER + Tree.ID_ICON);
-		this.elements.text = $(this.id + Tree.ID_DEVIDER + Tree.ID_TEXT);
 
-		var contextMenu = Richfaces.getNSAttribute("oncontextmenu", this.elements.icon);
+		var contextMenu = Richfaces.getNSAttribute("oncontextmenu", $(this.elementID.icon));
 		if (contextMenu && contextMenu.length > 0) {
 			this.onContextMenu = new Function(contextMenu + "; return true;");
 		}
-
-		var childsTd = $(childsRowId/* + Tree.ID_DEVIDER + Tree.ID_CHILDS_TD*/);
+		
+		var childsTd = $(this.elementID.children);
+		
 		if (childsTd) {
-            for(var child = childsTd.firstChild; child != null; child = child.nextSibling ) {
+			var child = childsTd.firstChild;
+			while ( child != null )
+			{
                 if (child.nodeType == 1 && child.tagName.toLowerCase() == "table") {
                     this.addChild(new Tree.Item(child.id, this.tree, this, this.childs.length, this.switchType, this.toggleOnClick));
                 }
+                child = child.nextSibling;
             }
             /*
             for (var i = 0; i < childsTd.childNodes.length; i++) {
@@ -82,8 +94,6 @@
 			}
 			*/
 		}
-
-		this.elements.mainRow = $(mainRowId);
 	},
 
 	addChild: function(child) {
@@ -109,37 +119,43 @@
 
 	toggleCollapsion: function() {
 
-		if (this.hasChilds()) Element.toggle(this.elements.row);
+		var row=this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW; 
+		if (this.hasChilds()) Element.toggle(row);
 
 		// Rerender main row to avoid bad representation in Opera and Konqueror/Safari
-		if (this.elements.mainRow) {
-			Element.hide(this.elements.mainRow);
-			Element.show(this.elements.mainRow);
+		var e = $(this.elementID.mainRow)
+		if (e) {
+			Element.hide(e);
+			Element.show(e);
 		}
+		
+		var nodeStateInput = $(this.id + "NodeExpanded");
 
+		var eIcon = $(this.elementID.icon);
+
 		if (this.isCollapsed()) {
-			this.elements.handleImgExpanded.style.display="none";
-			this.elements.handleImgCollapsed.style.display="";
-			if(Element.hasClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED)) {
-				Element.removeClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED);
-				Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED);
+			Element.hide(this.elementID.handleImgExpanded);
+			Element.show(this.elementID.handleImgCollapsed);
+			if( eIcon && Element.hasClassName(eIcon, Tree.CLASS_ITEM_EXPANDED)) {
+				Element.removeClassName(eIcon, Tree.CLASS_ITEM_EXPANDED);
+				Element.addClassName(eIcon, Tree.CLASS_ITEM_COLLAPSED);
 			}
 
-			if (this.nodeStateInput) {
-				this.nodeStateInput.value = "false";
+			if (nodeStateInput) {
+				nodeStateInput.value = "false";
 			}
 
 			this.fireCollapsionEvent();
 		} else {
-			this.elements.handleImgExpanded.style.display="";
-			this.elements.handleImgCollapsed.style.display="none";
-			if(Element.hasClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED)) {
-				Element.removeClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED);
-				Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED);
+			Element.show(this.elementID.handleImgExpanded);
+			Element.hide(this.elementID.handleImgCollapsed);
+			if(eIcon && Element.hasClassName(eIcon, Tree.CLASS_ITEM_COLLAPSED)) {
+				Element.removeClassName(eIcon, Tree.CLASS_ITEM_COLLAPSED);
+				Element.addClassName(eIcon, Tree.CLASS_ITEM_EXPANDED);
 			}
 
-			if (this.nodeStateInput) {
-				this.nodeStateInput.value = "true";
+			if (nodeStateInput) {
+				nodeStateInput.value = "true";
 			}
 
 			this.fireExpansionEvent();
@@ -148,26 +164,29 @@
 	},
 
 	getRichAttribute: function(name) {
-		return Richfaces.getNSAttribute(name, this.elements.icon);
+		return Richfaces.getNSAttribute(name, $(this.elementID.icon));
 	},
 
 	collapse: function() {
 		if (!this.isCollapsed() && this.switchType!="client") {
 			if (this.toggleOnClick) {
-				if (this.elements.mainRow)
-					this.elements.mainRow.onclick();
+				var e = $(this.elementID.mainRow);				
+				if (e)
+					e.onclick();
 			} else {
-				if (this.elements.handle)
-					this.elements.handle.onclick();
+				var e = $(this.elementID.handle);
+				if (e)
+					e.onclick();
 			}
 		}
 		if (this.hasChilds() && !this.isCollapsed()) {
-			Element.hide(this.elements.row);
-			this.elements.handleImgExpanded.style.display="none";
-			this.elements.handleImgCollapsed.style.display="";
-			if(Element.hasClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED)) {
-				Element.removeClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED);
-				Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED);
+			Element.hide(this.elementID.children);
+			Element.hide(this.elementID.handleImgExpanded);
+			Element.show(this.elementID.handleImgCollapsed);
+			var eIcon = $(this.elementID.icon);		
+			if(eIcon && Element.hasClassName(eIcon, Tree.CLASS_ITEM_EXPANDED)) {
+				Element.removeClassName(eIcon, Tree.CLASS_ITEM_EXPANDED);
+				Element.addClassName(eIcon, Tree.CLASS_ITEM_COLLAPSED);
 			}
 		}
 
@@ -177,20 +196,23 @@
 	expand: function() {
 		if (this.isCollapsed() && this.switchType!="client") {
 			if (this.toggleOnClick) {
-				if (this.elements.mainRow)
-					this.elements.mainRow.onclick();
+				var e = $(this.elementID.mainRow);
+				if (e)
+					e.onclick();
 			} else {
-				if (this.elements.handle)
-					this.elements.handle.onclick();
+				var e = $(this.elementID.handle);
+				if (e)
+					e.onclick();
 			}
 		}
 		if (this.hasChilds() && this.isCollapsed()) {
-			Element.show(this.elements.row);
-			this.elements.handleImgExpanded.style.display="";
-			this.elements.handleImgCollapsed.style.display="none";
-			if(Element.hasClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED)) {
-				Element.removeClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED);
-				Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED);
+			Element.show(this.elementID.children);
+			Element.show(this.elementID.handleImgExpanded);
+			Element.hide(this.elementID.handleImgCollapsed);
+			var eIcon = $(this.elementID.icon);
+			if(eIcon && Element.hasClassName(eIcon, Tree.CLASS_ITEM_COLLAPSED)) {
+				Element.removeClassName(eIcon, Tree.CLASS_ITEM_COLLAPSED);
+				Element.addClassName(eIcon, Tree.CLASS_ITEM_EXPANDED);
 			}
 		}
 
@@ -198,8 +220,9 @@
 	},
 
 	isCollapsed: function() {
-		if (this.elements.row != null) {
-			return this.elements.row.style.display == "none";
+		var e = $(this.elementID.children);
+		if (e) {
+			return e.style.display == "none";
 		} else {
 			return true;
 		}
@@ -208,11 +231,12 @@
 	processMouseOut: function(e) {
 		if (this.isMouseIn) {
 			this.isMouseIn = false;
-			var hClass = Richfaces.getNSAttribute("highlightedclass", this.elements.text);
+			var eText = $(this.elementID.text);
+			var hClass = Richfaces.getNSAttribute("highlightedclass", eText);
 			if (hClass) {
 				var classNames = hClass.split(' ')
 				for (var i = 0; i < classNames.length; i++) {
-					Element.removeClassName(this.elements.text, classNames[i]);
+					Element.removeClassName(eText, classNames[i]);
 				}
 				if (window.drag){
 					this.dragLeave(e);
@@ -224,11 +248,12 @@
 	processMouseOver: function(e) {
 		if(!this.isMouseIn) {
 			this.isMouseIn = true;
-			var hClass = Richfaces.getNSAttribute("highlightedclass", this.elements.text);
+			var eText = $(this.elementID.text);
+			var hClass = Richfaces.getNSAttribute("highlightedclass", eText);
 			if (hClass) {
 				var classNames = hClass.split(' ')
 				for (var i = 0; i < classNames.length; i++) {
-					Element.addClassName(this.elements.text, classNames[i]);
+					Element.addClassName(eText, classNames[i]);
 				}
 				if (window.drag) {
 					this.dragEnter(e);
@@ -274,19 +299,20 @@
 
 			alert(s);
 			*/
-
-			var sClass = Richfaces.getNSAttribute("selectedclass", this.elements.text);
+			
+			var eText = $(this.elementID.text);
+			var sClass = Richfaces.getNSAttribute("selectedclass", eText);
 			if (sClass) {
 
 				var classNames = sClass.split(' ')
 				for (var i = 0; i < classNames.length; i++) {
-					Element.addClassName(this.elements.text, classNames[i]);
+					Element.addClassName(eText, classNames[i]);
 				}
 				this.tree.input.value = this.id;
 				this.tree.selectionManager.activeItem = this;
 
 				if (this.tree.options.onSelection) this.tree.options.onSelection(this.id);
-				this.tree.showNode(this.elements.text.parentNode);
+				this.tree.showNode(eText.parentNode);
 
 				if (e && e["originatingEventType"] == "mousedown" /* can be keydown */) {
 					this.startDrag(e);
@@ -298,15 +324,16 @@
 	},
 
 	isSelected: function() {
-		return Element.hasClassName(this.elements.text, Tree.CLASS_ITEM_SELECTED);
+		return Element.hasClassName(this.elementID.text, Tree.CLASS_ITEM_SELECTED);
 	},
 
 	deselect: function() {
-		var sClass = Richfaces.getNSAttribute("selectedclass", this.elements.text);
+		var eText = $(this.elementID.text);
+		var sClass = Richfaces.getNSAttribute("selectedclass", eText);
 		if (sClass) {
 			var classNames = sClass.split(' ')
 			for (var i = 0; i < classNames.length; i++) {
-				Element.removeClassName(this.elements.text, classNames[i]);
+				Element.removeClassName(eText, classNames[i]);
 			}
 		}
 	},

Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js	2007-08-10 14:23:52 UTC (rev 2202)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js	2007-08-10 16:11:08 UTC (rev 2203)
@@ -46,10 +46,11 @@
 	},
 
 	restoreSelection: function() {
-		var e = $(this.tree.input.value);
-		if (this.tree.input.value && e) {
-			this.setSelection((e).object);
-		}		
+		if (this.tree.input.value)
+		{
+			var e = $(this.tree.input.value);
+			if (e) this.setSelection(e.object);
+		}
 	},
 	
 	processPreventLostFocus: function() {

Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js	2007-08-10 14:23:52 UTC (rev 2202)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js	2007-08-10 16:11:08 UTC (rev 2203)
@@ -42,7 +42,10 @@
 		);
 		this.options = options;
 
+		//var d = new Date();
 		this.getElements();
+		//alert(new Date().getTime() - d.getTime());
+
 		this.selectionManager = new Tree.SelectionManager(this);
 		this.selectionManager.restoreSelection();
 
@@ -109,9 +112,7 @@
 	},
 
 	getElements: function() {
-		var contentId = this.id;
-
-		this.elements.contentTd = $(contentId + 
+		this.elements.contentTd = $(this.id + 
 			Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW/* + Tree.ID_DEVIDER + Tree.ID_CHILDS_TD*/);
 
 		if (this.elements.contentTd) {




More information about the richfaces-svn-commits mailing list