Author: konstantin.mishin
Date: 2009-07-29 06:18:40 -0400 (Wed, 29 Jul 2009)
New Revision: 15041
Modified:
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererDelegate.java
branches/community/3.3.X/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js
branches/community/3.3.X/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/renderkit/html/MenuItemRendererBaseTest.java
Log:
RF-7508
Modified:
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java 2009-07-29
10:18:40 UTC (rev 15041)
@@ -89,7 +89,7 @@
context.getResponseWriter().write(buffer.toString());
}
- protected abstract void appendMenuScript(FacesContext context, UIComponent component,
StringBuffer buffer);
+ protected abstract JSFunction getMenuScriptFunction(FacesContext context, UIComponent
component);
protected String getLayerScript(FacesContext context, UIComponent component) {
StringBuffer buffer = new StringBuffer();
@@ -107,24 +107,49 @@
if (component instanceof UIMenuGroup) {
options = new HashMap<String, Object>();
buffer.append(".");
- function = new JSFunction("asSubMenu");
- function.addParameter(component.getParent().getClientId(context)+"_menu");
- function.addParameter(component.getClientId(context));
+ JSFunction subMenuFunction = new JSFunction("asSubMenu");
+ subMenuFunction.addParameter(component.getParent().getClientId(context)+"_menu");
+ subMenuFunction.addParameter(component.getClientId(context));
utils.addToScriptHash(options, "evtName",
component.getAttributes().get("event"), "onmouseover");
utils.addToScriptHash(options, "direction",
component.getAttributes().get("direction"), "auto");
utils.addToScriptHash(options, "onopen",
component.getAttributes().get("onopen"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
utils.addToScriptHash(options, "onclose",
component.getAttributes().get("onclose"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
if (!options.isEmpty()) {
- function.addParameter(options);
+ subMenuFunction.addParameter(options);
}
- function.appendScript(buffer);
+ subMenuFunction.appendScript(buffer);
} else {
- appendMenuScript(context, component, buffer);
+ buffer.append(".");
+ JSFunction menuFunction = getMenuScriptFunction(context, component);
+ Map<String, Object> menuOptions = getMenuOptions(component);
+ if (!menuOptions.isEmpty()) {
+ menuFunction.addParameter(menuOptions);
+ }
+ menuFunction.appendScript(buffer);
}
return buffer.toString();
}
- protected Object getItemScriptObject(FacesContext context, UIComponent kid) {
+ protected Map<String, Object> getMenuOptions(UIComponent component) {
+ Map<String, Object> options = new HashMap<String, Object>();
+ RendererUtils utils = getUtils();
+ utils.addToScriptHash(options, "direction",
component.getAttributes().get("direction"), "auto");
+ utils.addToScriptHash(options, "jointPoint",
component.getAttributes().get("jointPoint"), "auto");
+ utils.addToScriptHash(options, "verticalOffset",
component.getAttributes().get("verticalOffset"), "0");
+ utils.addToScriptHash(options, "horizontalOffset",
component.getAttributes().get("horizontalOffset"), "0");
+ utils.addToScriptHash(options, "oncollapse",
component.getAttributes().get("oncollapse"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onexpand",
component.getAttributes().get("onexpand"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onitemselect",
component.getAttributes().get("onitemselect"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "ongroupactivate",
component.getAttributes().get("ongroupactivate"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
+
+ utils.addToScriptHash(options, "selectItemClass",
component.getAttributes().get("selectItemClass"));
+ utils.addToScriptHash(options, "itemClass",
component.getAttributes().get("itemClass"));
+ utils.addToScriptHash(options, "selectItemStyle",
component.getAttributes().get("selectItemStyle"));
+ utils.addToScriptHash(options, "itemStyle",
component.getAttributes().get("itemStyle"));
+ return options;
+ }
+
+ protected Object getItemScriptObject(FacesContext context, UIComponent kid) {
String itemId = null;
List<Object> scriptObject = null;
boolean closeOnClick = true;
@@ -160,11 +185,8 @@
utils.addToScriptHash(options, "flagGroup", flagGroup);
utils.addToScriptHash(options, "styleClass",
kid.getAttributes().get("styleClass"));
utils.addToScriptHash(options, "style",
kid.getAttributes().get("style"));
- utils.addToScriptHash(options, "itemClass",
kid.getAttributes().get("itemClass"));
- utils.addToScriptHash(options, "itemStyle",
kid.getAttributes().get("itemStyle"));
utils.addToScriptHash(options, "disabledItemClass",
kid.getAttributes().get("disabledItemClass"));
utils.addToScriptHash(options, "disabledItemStyle",
kid.getAttributes().get("disabledItemStyle"));
- utils.addToScriptHash(options, "selectItemClass",
kid.getAttributes().get("selectItemClass"));
utils.addToScriptHash(options, "labelClass",
kid.getAttributes().get("labelClass"));
utils.addToScriptHash(options, "selectedLabelClass",
kid.getAttributes().get("selectedLabelClass"));
utils.addToScriptHash(options, "disabledLabelClass",
kid.getAttributes().get("disabledLabelClass"));
Modified:
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java 2009-07-29
10:18:40 UTC (rev 15041)
@@ -30,7 +30,6 @@
import org.ajax4jsf.renderkit.ComponentsVariableResolver;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.richfaces.component.UIMenuGroup;
-import org.richfaces.component.UIMenuItem;
import org.richfaces.component.util.ViewUtil;
@@ -106,14 +105,4 @@
return delegate.getParentMenu(context, menuGroup);
}
- protected String collectInlineStyles(FacesContext context, UIMenuItem menuItem,
boolean isOnmouseover) {
- return delegate.collectInlineStyles(context, menuItem, isOnmouseover);
- }
-
- @Deprecated
- protected String processInlineStyles(FacesContext context,
- UIMenuGroup menuGroup, boolean isOnmouseover) {
-
- return delegate.processInlineStyles(context, menuGroup, isOnmouseover);
- }
}
Modified:
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2009-07-29
10:18:40 UTC (rev 15041)
@@ -200,11 +200,6 @@
null, ScriptHashVariableWrapper.EVENT_HANDLER);
}
- variables.setVariable("onmouseoutInlineStyles",
- collectInlineStyles(context, menuItem, false));
- variables.setVariable("onmouseoverInlineStyles",
- collectInlineStyles(context, menuItem, true));
-
//-----------------------------------
StringBuilder scriptValue = new StringBuilder();
String mode = resolveSubmitMode(menuItem);
@@ -341,16 +336,7 @@
return MenuComponent.MODE_SERVER;
}
-
- protected String collectInlineStyles(FacesContext context, UIMenuItem menuItem,
boolean isOnmouseover) {
- return delegate.collectInlineStyles(context, menuItem, isOnmouseover);
- }
- @Deprecated
- protected String processInlineStyles(FacesContext context, UIMenuItem menuItem,
boolean isOnmouseover) {
- return delegate.processInlineStyles(context, menuItem, isOnmouseover);
- }
-
protected UIComponent getParentMenu(FacesContext context, UIMenuItem menuItem) {
return delegate.getParentMenu(context, menuItem);
}
Modified:
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererDelegate.java
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererDelegate.java 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererDelegate.java 2009-07-29
10:18:40 UTC (rev 15041)
@@ -51,7 +51,6 @@
selectItemClass = (String)
parentMenu.getAttributes().get("selectItemClass");
}
- String selectClass = (String) menuItem.getAttributes().get("selectClass");
String styleClass = (String) menuItem.getAttributes().get("styleClass");
String style = (String) menuItem.getAttributes().get("style");
String labelClass = (String) menuItem.getAttributes().get("labelClass");
@@ -69,10 +68,8 @@
variables.setVariable("menuItemItemLabelClass",
concatClasses("rich-menu-item-label-disabled", labelClass));
variables.setVariable("menuItemItemFolderClass",
"rich-menu-item-folder-disabled");
} else {
- variables.setVariable("menuItemCustomClass", concatClasses(styleClass,
itemClass));
variables.setVariable("menuItemClass", concatClasses("rich-menu-item
rich-menu-item-enabled", styleClass, itemClass));
variables.setVariable("menuItemStyle", concatStyles(itemStyle, style));
- variables.setVariable("menuItemHoverClass", concatClasses(styleClass,
selectClass, selectItemClass));
variables.setVariable("menuItemLabelClass",
concatClasses("rich-menu-item-label", labelClass));
variables.setVariable("selectLabelClass", selectedLabelClass);
variables.setVariable("menuGroupClass", concatClasses("rich-menu-group
rich-menu-group-enabled", itemClass, styleClass));
@@ -81,37 +78,11 @@
variables.setVariable("menuGroupItemIconClass",
"rich-menu-item-icon-enabled rich-menu-group-icon");
variables.setVariable("menuGroupItemLabelClass",
concatClasses("rich-menu-item-label rich-menu-group-label", labelClass));
variables.setVariable("menuGroupItemFolderClass",
"rich-menu-item-folder rich-menu-group-folder");
- variables.setVariable("onmouseoutInlineStyles", collectInlineStyles(context,
menuItem, false));
- variables.setVariable("onmouseoverInlineStyles",
collectInlineStyles(context, menuItem, true));
variables.setVariable("menuGroupHoverClass",
concatClasses(itemClass, selectItemClass, styleClass));
}
}
- protected String collectInlineStyles(FacesContext context, UIComponent menuItem, boolean
isOnmouseover) {
- String style = (String) menuItem.getAttributes().get("style");
- String selectStyle = (String) menuItem.getAttributes().get("selectStyle");
-
- UIComponent parentMenu = getParentMenu(context, menuItem);
- String selectItemStyle = null;
- String itemStyle = null;
- if (parentMenu != null) {
- selectItemStyle = (String)
parentMenu.getAttributes().get("selectItemStyle");
- itemStyle = (String) parentMenu.getAttributes().get("itemStyle");
- }
-
- if (isOnmouseover) {
- return concatStyles(style, itemStyle, selectItemStyle, selectStyle);
- } else {
- return concatStyles(style, itemStyle);
- }
- }
-
- @Deprecated
- protected String processInlineStyles(FacesContext context, UIComponent menuItem, boolean
isOnmouseover) {
- return ("$('" + menuItem.getClientId(context) +
"').style.cssText='" + collectInlineStyles(context, menuItem,
isOnmouseover) + "';");
- }
-
protected UIComponent getParentMenu(FacesContext context, UIComponent menuItem) {
UIComponent parent = menuItem.getParent();
while (null != parent) {
Modified:
branches/community/3.3.X/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js 2009-07-29
10:18:40 UTC (rev 15041)
@@ -1312,8 +1312,9 @@
this.menu = menu;
this.mouseOver = false;
+ this.getElement().oncontextmenu = this.getIcon().oncontextmenu
+ = this.getLabel().oncontextmenu = function(event) {Event.stop(event); return false;};
-
var binding;
binding = new RichFaces.Menu.Layer.Binding (
@@ -1402,6 +1403,13 @@
this.highLightGroup(true);
}
RichFaces.Menu.Items.onmouseover(this);
+ var menuOptions = this.menu.options;
+ element.className = 'rich-menu-item rich-menu-item-hover '
+ + this.options.styleClass || "" + " " + this.options.selectClass
|| "" + " " + menuOptions.selectItemClass || "";
+ element.style.cssText = this.options.style || "" + "; " +
menuOptions.itemStyle || ""
+ + this.options.selectStyle || "" + "; " +
menuOptions.selectItemStyle || "";
+ this.getIcon().className='rich-menu-item-icon rich-menu-item-icon-selected ' +
(this.options.iconClass || '');
+ Element.addClassName(this.getLabel(), 'rich-menu-item-label-selected');
},
onmouseout : function(event) {
Event.extend(event);
@@ -1424,6 +1432,12 @@
this.highLightGroup(false);
}
RichFaces.Menu.Items.onmouseout(this);
+ var menuOptions = this.menu.options;
+ element.className = 'rich-menu-item rich-menu-item-enabled '
+ + this.options.styleClass || "" + " " + menuOptions.itemClass ||
"";
+ element.style.cssText = this.options.style || "" + "; " +
menuOptions.itemStyle || "";
+ this.getIcon().className='rich-menu-item-icon ' + this.options.iconClass ||
"";
+ Element.removeClassName(this.getLabel(), 'rich-menu-item-label-selected');
},
highLightGroup: function(light) {
if (light) {
@@ -1506,19 +1520,6 @@
element.className = 'rich-menu-group rich-menu-group-enabled ' + (menuGroupClass
? menuGroupClass : '');
element.style.cssText = menuGroupStyle;
}
-
-RichFaces.Menu.itemMouseOut = function(event, element, classes) {
- if (RichFaces.Menu.isWithin(event, element)) {
- return;
- }
-
- element.className = 'rich-menu-item rich-menu-item-enabled ' +
(classes.styleClass || '');
- element.style.cssText = classes.style || "";
- $(element.id + ':icon').className='rich-menu-item-icon ' +
(classes.iconClass || '');
- Element.removeClassName($(element.id + ':anchor'),
'rich-menu-item-label-selected');
-
-}
-
RichFaces.Menu.groupMouseOver = function(event, element, menuGroupHoverClass,
menuGroupStyle) {
if (RichFaces.Menu.isWithin(event, element)) {
return;
@@ -1526,16 +1527,4 @@
element.className = 'rich-menu-group rich-menu-group-enabled ' +
(menuGroupHoverClass ? menuGroupHoverClass : '');
element.style.cssText = menuGroupStyle;
-}
-
-RichFaces.Menu.itemMouseOver = function(event, element, classes) {
- if (RichFaces.Menu.isWithin(event, element)) {
- return;
- }
-
- element.className = 'rich-menu-item rich-menu-item-hover ' + (classes.styleClass
|| '');
- element.style.cssText = classes.style || "";
-
- $(element.id + ':icon').className='rich-menu-item-icon
rich-menu-item-icon-selected ' + (classes.iconClass || '');
- Element.addClassName($(element.id + ':anchor'),
'rich-menu-item-label-selected');
-}
+}
\ No newline at end of file
Modified:
branches/community/3.3.X/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx 2009-07-29
10:18:40 UTC (rev 15041)
@@ -42,8 +42,7 @@
<div id="#{clientId}"
class="#{menuItemClass}"
style="#{menuItemStyle}"
- onclick="Event.stop(event);"
- onContextMenu="return false;" >
+ onclick="Event.stop(event);" >
<jsp:scriptlet><![CDATA[
} else {
@@ -57,27 +56,12 @@
*/
]]></jsp:scriptlet>
- <c:scriptObject var="onmouseoutClasses">
- <c:scriptOption name="styleClass"
value="#{menuItemCustomClass}"/>
- <c:scriptOption name="style"
value="#{onmouseoutInlineStyles}"/>
- <c:scriptOption attributes="iconClass"/>
- </c:scriptObject>
- <c:scriptObject var="onmouseoverClasses">
- <c:scriptOption name="styleClass"
value="#{menuItemHoverClass}"/>
- <c:scriptOption name="style"
value="#{onmouseoverInlineStyles}"/>
- <c:scriptOption attributes="iconClass"/>
- </c:scriptObject>
<div id="#{clientId}"
class="#{menuItemClass}"
- onmouseout="RichFaces.Menu.itemMouseOut(event, this, #{onmouseoutClasses});"
- onmouseover="RichFaces.Menu.itemMouseOver(event, this,
#{onmouseoverClasses});"
-
onmouseup="Event.stop(event); #{component.attributes['onmouseup']}"
onmousedown="Event.stop(event);
#{component.attributes['onmousedown']}"
onclick="#{onclick}"
- onContextMenu="Event.stop(event); return false;"
-
style="#{menuItemStyle}">
<f:call name="utils.encodeAttributes">
<f:parameter value="onmousemove" />
@@ -90,8 +74,7 @@
<span id="#{clientId}:icon"
class="rich-menu-item-icon #{iconDisabledClasses}
#{component.attributes['iconClass']}"
- style="#{component.attributes['iconStyle']}"
- onContextMenu="Event.stop(event); return false;">
+ style="#{component.attributes['iconStyle']}">
<jsp:scriptlet><![CDATA[
UIComponent iconFacet = getIconFacet((org.richfaces.component.UIMenuItem)
component);
@@ -111,9 +94,7 @@
</span>
<span id="#{clientId}:anchor"
- class="#{menuItemLabelClass}"
- onContextMenu="Event.stop(event); return false;"
- >
+ class="#{menuItemLabelClass}">
#{component.attributes['value']}
<f:call name="renderChildren" />
</span>
Modified:
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2009-07-29
10:18:40 UTC (rev 15041)
@@ -241,8 +241,6 @@
String onclickAttr = div.getAttributeValue(HTML.onclick_ATTRIBUTE);
assertNotNull(onclickAttr);
assertTrue(onclickAttr.length() > 0);
- classAttr = div.getAttributeValue(HTML.onmouseover_ATTRIBUTE);
- assertTrue(classAttr.contains("menuItemSelectStyle"));
}
/**
Modified:
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/renderkit/html/MenuItemRendererBaseTest.java
===================================================================
---
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/renderkit/html/MenuItemRendererBaseTest.java 2009-07-29
10:18:35 UTC (rev 15040)
+++
branches/community/3.3.X/ui/menu-components/src/test/java/org/richfaces/renderkit/html/MenuItemRendererBaseTest.java 2009-07-29
10:18:40 UTC (rev 15041)
@@ -106,32 +106,6 @@
}
/**
- * Test for processInlineStyles method.
- */
- public void testProcessInlineStylesMethod() throws Exception {
- String style = "some style";
- String selectStyle = "some select style";
- String result = renderer.processInlineStyles(facesContext, menuItem,true);
-
- assertNotNull(result);
- assertTrue(result.startsWith("$('menuItem').style.cssText="));
-
- menuItem.getAttributes().put("selectStyle", selectStyle);
- result = renderer.processInlineStyles(facesContext, menuItem, false);
- assertTrue(!result.contains(selectStyle));
- assertTrue(!result.contains(style));
-
- result = renderer.processInlineStyles(facesContext, menuItem, true);
- assertTrue(result.contains(selectStyle));
- assertTrue(!result.contains(style));
-
- menuItem.getAttributes().put("style", style);
- result = renderer.processInlineStyles(facesContext, menuItem, true);
- assertTrue(result.contains(selectStyle));
- assertTrue(result.contains(style));
- }
-
- /**
* Test for getComponentClass methods.
*/
public void testGetComponentClassMethod() throws Exception {