[richfaces-svn-commits] JBoss Rich Faces SVN: r783 - in trunk/richfaces/panelmenu/src/main: java/org/richfaces/component/panelmenu and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed May 16 12:02:53 EDT 2007


Author: sergeyhalipov
Date: 2007-05-16 12:02:53 -0400 (Wed, 16 May 2007)
New Revision: 783

Modified:
   trunk/richfaces/panelmenu/src/main/config/component/panelMenu.xml
   trunk/richfaces/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenu.java
   trunk/richfaces/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java
   trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
Log:
Panel menu: Add support for "hovered..." attributes.

Modified: trunk/richfaces/panelmenu/src/main/config/component/panelMenu.xml
===================================================================
--- trunk/richfaces/panelmenu/src/main/config/component/panelMenu.xml	2007-05-16 14:07:37 UTC (rev 782)
+++ trunk/richfaces/panelmenu/src/main/config/component/panelMenu.xml	2007-05-16 16:02:53 UTC (rev 783)
@@ -240,6 +240,12 @@
 	    	<defaultvalue><![CDATA[""]]></defaultvalue>
 	    </property>	  
 	    <property>
+	    	<name>hoveredGroupStyle</name>
+	    	<classname>java.lang.String</classname>
+	    	<description></description>
+	    	<defaultvalue><![CDATA[""]]></defaultvalue>
+	    </property>	 
+	    <property>
 	    	<name>hoveredGroupClass</name>
 	    	<classname>java.lang.String</classname>
 	    	<description></description>

Modified: trunk/richfaces/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenu.java
===================================================================
--- trunk/richfaces/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenu.java	2007-05-16 14:07:37 UTC (rev 782)
+++ trunk/richfaces/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenu.java	2007-05-16 16:02:53 UTC (rev 783)
@@ -76,6 +76,8 @@
 	public abstract void setHoveredItemClass(String hoveredItemClass);
 	public abstract String getHoveredItemStyle();
 	public abstract void setHoveredItemStyle(String hoveredItemStyle);
+	public abstract String getHoveredGroupStyle();
+	public abstract void setHoveredGroupStyle(String hoveredItemStyle);
 	public abstract String getHoveredGroupClass();
 	public abstract void setHoveredGroupClass(String hoveredGroupClass);
 	public abstract String getOnitemhover();

Modified: trunk/richfaces/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java
===================================================================
--- trunk/richfaces/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java	2007-05-16 14:07:37 UTC (rev 782)
+++ trunk/richfaces/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java	2007-05-16 16:02:53 UTC (rev 783)
@@ -89,10 +89,22 @@
 				if (!parentRendered){
 					child.getAttributes().put("rendered",Boolean.FALSE);
 				}
+				
+				UIPanelMenu parentMenu = findMenu(child);
 				String onopen = child instanceof UIPanelMenuGroup ? 
-						findMenu(child).getOngroupexpand() : "";
+						parentMenu.getOngroupexpand() : "";
 				String onclose = child instanceof UIPanelMenuGroup ? 
-						findMenu(child).getOngroupcollapse() : "";
+						parentMenu.getOngroupcollapse() : "";
+				String hoveredStyle = (child instanceof UIPanelMenuGroup ? 
+						parentMenu.getHoveredGroupStyle() : parentMenu.getHoveredItemStyle())
+						+ ";" + (child instanceof UIPanelMenuGroup ? 
+								((UIPanelMenuGroup)child).getHoverStyle() : ((UIPanelMenuItem)child).getHoverStyle());
+				String hoveredClass = (child instanceof UIPanelMenuGroup ? 
+						parentMenu.getHoveredGroupClass() : parentMenu.getHoveredItemClass())
+						+ " " + (child instanceof UIPanelMenuGroup ? 
+								((UIPanelMenuGroup)child).getHoverClass() : ((UIPanelMenuItem)child).getHoverClass());
+				String [] hoveredStyles = hoveredStyle.split(";");
+				String [] hoveredClasses = hoveredClass.split(" ");
 				
 				
 				if (childRendered && parentRendered){
@@ -104,8 +116,33 @@
 								.append((String) child.getParent().getClientId(context))
 								.append("'},{type:" + (child instanceof UIPanelMenuItem ? "\"item\"":"\"node\""))
 								.append(",onopen:"+(onopen.equals("") ? "\"\"" : "\"" + onopen + "\"")+",onclose:"+(onclose.equals("") ? "\"\"" : "\"" + onclose + "\""))
-								.append("}," + levels.get(child.getClientId(context)));
+								.append("},{");
+							
+						
+						for (int i = 0; i < hoveredStyles.length; i++)
+							if (!"".equals(hoveredStyles[i])) {
+								String [] temp = hoveredStyles[i].split(":");
+								String cssName = temp[0].trim();
+								String cssValue = temp[1].trim();
+								buffer.append("\"" + cssName + "\": \"" + cssValue + "\"");
+								if (i != hoveredStyles.length - 1)
+									buffer.append(",");
+							}
+						
+						buffer.append("},");
+						if (hoveredClasses.length > 0) {
+							buffer.append("new Array(");
+							for (int i = 0; i < hoveredClasses.length; i++)
+								if (!"".equals(hoveredClasses[i])) {;
+									buffer.append("\"" + hoveredClasses[i] + "\"");
+									if (i != hoveredClasses.length - 1)
+										buffer.append(",");
+								}
+							buffer.append("),");
+						} else
+							buffer.append("new Array(),");
 	
+						buffer.append(levels.get(child.getClientId(context)));
 						switchOnImagesIfNeeded(context,child,buffer);
 						
 						addActionIfNeeded(context,child,buffer);

Modified: trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
===================================================================
--- trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js	2007-05-16 14:07:37 UTC (rev 782)
+++ trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js	2007-05-16 16:02:53 UTC (rev 783)
@@ -17,56 +17,58 @@
 		PanelMenuStorage[myId] = this;}}; 
 PanelMenuItem = Class.create();
 PanelMenuItem.prototype = {
-	initialize: function(ids, options, level, haveDynamicIcon, action, opened, iconAlign, iconExpanded, iconCollapsed, iconSpacer){
-	if (!ids.parentId){return};
-	this.type = options.type;
-	this.onopen = options.onopen;
-	this.onclose = options.onclose;
-	this.tdhider = $("tdhide"+ids.myId);
-	this.tablehider = $("tablehide"+ids.myId);
-	this.haveDynamicIcon = haveDynamicIcon;
-	if (this.haveDynamicIcon==true)
-		this.iconswitcher = $("icon"+ids.myId);
-	this.childObj = new Array();
-	this.parentObj = PanelMenuStorage[ids.parentId];
-	this.parentObj.childObj.push(this);
-	this.obj = $(ids.myId);
-	this.content = this._getDirectChildrenByTag(this.obj,"TD")[level+1];
-	this.iconAlign = iconAlign;
-	if (level == 0){
-		this.tdhider.style.display = "";
-		this.tablehider.style.display = "";
-	} else if (this._getDirectChildrenByTag(this.content,"INPUT")[0].value!="closed"){
-		this.tdhider.style.display = "";
-		this.tablehider.style.display = "";
-	}
-	this.iconCollapsed = iconCollapsed;
-	this.iconExpanded = iconExpanded;
-	this.iconSpacer = iconSpacer;
-	if(action){
-		this.action = action;
-	}
-	PanelMenuStorage[ids.myId] = this;
-	this._attachBehaviors();
-	this.inputs = this._getDirectChildrenByTag(this.content,"INPUT");	
-		for (var i=0;i<this.inputs.length;i++){
-			if (this.inputs[i].name.indexOf("panelMenuState")!=-1){
-				this.inputState = this.inputs[i];
-			} else if (this.inputs[i].name.indexOf("panelMenuAction")!=-1){
-				this.inputAction = this.inputs[i];
-			}
-		}	
-	if (opened){
-		if (this.parentObj.is=='panelMenu')
-			this.parentObj.lastExpanded = this;
-		this.expand();
-	} else {
-		this.expanded = false;
-	}
-	if (this.parentObj.type=="node"&&this.parentObj.expanded){
-		if (this.type=="node")
-		this.tdhider.style.display="";
-	}
+	initialize: function(ids, options, hoveredStyles, hoveredClasses, level, haveDynamicIcon, action, opened, iconAlign, iconExpanded, iconCollapsed, iconSpacer){
+		if (!ids.parentId){return};
+		this.type = options.type;
+		this.onopen = options.onopen;
+		this.onclose = options.onclose;
+		this.hoveredStyles = hoveredStyles;
+		this.hoveredClasses = hoveredClasses;
+		this.tdhider = $("tdhide"+ids.myId);
+		this.tablehider = $("tablehide"+ids.myId);
+		this.haveDynamicIcon = haveDynamicIcon;
+		if (this.haveDynamicIcon==true)
+			this.iconswitcher = $("icon"+ids.myId);
+		this.childObj = new Array();
+		this.parentObj = PanelMenuStorage[ids.parentId];
+		this.parentObj.childObj.push(this);
+		this.obj = $(ids.myId);
+		this.content = this._getDirectChildrenByTag(this.obj,"TD")[level+1];
+		this.iconAlign = iconAlign;
+		if (level == 0){
+			this.tdhider.style.display = "";
+			this.tablehider.style.display = "";
+		} else if (this._getDirectChildrenByTag(this.content,"INPUT")[0].value!="closed"){
+			this.tdhider.style.display = "";
+			this.tablehider.style.display = "";
+		}
+		this.iconCollapsed = iconCollapsed;
+		this.iconExpanded = iconExpanded;
+		this.iconSpacer = iconSpacer;
+		if(action){
+			this.action = action;
+		}
+		PanelMenuStorage[ids.myId] = this;
+		this._attachBehaviors();
+		this.inputs = this._getDirectChildrenByTag(this.content,"INPUT");	
+			for (var i=0;i<this.inputs.length;i++){
+				if (this.inputs[i].name.indexOf("panelMenuState")!=-1){
+					this.inputState = this.inputs[i];
+				} else if (this.inputs[i].name.indexOf("panelMenuAction")!=-1){
+					this.inputAction = this.inputs[i];
+				}
+			}	
+		if (opened){
+			if (this.parentObj.is=='panelMenu')
+				this.parentObj.lastExpanded = this;
+			this.expand();
+		} else {
+			this.expanded = false;
+		}
+		if (this.parentObj.type=="node"&&this.parentObj.expanded){
+			if (this.type=="node")
+			this.tdhider.style.display="";
+		}
 	},
 
 	collapse: function(){
@@ -97,7 +99,8 @@
 				this.childObj[i].hide();
 				this.childObj[i].tdhider.style.display="none";
 				this.childObj[i].tablehider.style.display="none";
-			}}
+			}
+		}
 		this.expanded = false;
 	}, 
 	hide: function(){ 
@@ -228,7 +231,22 @@
 			}
 		}
 	},
+	
+	addHoverStyles: function(e) {
+		if (this.hoveredStyles) {
+			Element.setStyle(this.obj, this.hoveredStyles);
+		}
+		if (this.hoveredClasses)
+			for (i = 0; i < this.hoveredClasses.length; i++)
+				this.obj.addClassName(this.hoveredClasses[i]);
+	},
    
+   removeHoverStyles: function(e) {
+   		if (this.hoveredClasses)
+			for (var i = 0; i < this.hoveredClasses.length; i++)
+				this.obj.removeClassName(this.hoveredClasses[i]);
+	},
+   
    _getDirectChildrenByTag: function(e, tagName) {
       var allKids = e.childNodes;
       var kids = new Array();
@@ -251,6 +269,8 @@
 	}, 
    
  	_attachBehaviors: function() {
-		this.obj.onclick = this.itemClicked.bindAsEventListener(this);
+		Event.observe(this.obj, "click", this.itemClicked.bindAsEventListener(this), false);
+		Event.observe(this.obj, "mouseover", this.addHoverStyles.bindAsEventListener(this), false);
+		Event.observe(this.obj, "mouseout", this.removeHoverStyles.bindAsEventListener(this), false);
 	}
 };
\ No newline at end of file




More information about the richfaces-svn-commits mailing list