Author: konstantin.mishin
Date: 2009-06-05 12:18:59 -0400 (Fri, 05 Jun 2009)
New Revision: 14540
Modified:
branches/community/3.3.X/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
branches/community/3.3.X/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
branches/community/3.3.X/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java
Log:
RF-7327
Modified:
branches/community/3.3.X/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
===================================================================
---
branches/community/3.3.X/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2009-06-05
15:53:54 UTC (rev 14539)
+++
branches/community/3.3.X/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2009-06-05
16:18:59 UTC (rev 14540)
@@ -42,6 +42,7 @@
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxComponentRendererBase;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.ScriptHashVariableWrapper;
import org.ajax4jsf.resource.InternetResource;
import org.richfaces.component.UIToolTip;
import org.richfaces.skin.Skin;
@@ -150,7 +151,7 @@
}
public Map<String, Object> buildEventOptions(FacesContext context,
- UIComponent component, String targetId) {
+ UIComponent component) {
Map<String, Object> eventOptions = AjaxRendererUtils.buildEventOptions(
context, component);
String jsVarName = "_toolTip";
@@ -254,62 +255,61 @@
UIToolTip toolTip = (UIToolTip) component;
String targetClientId = getTargetId(context, component);
+ Map<String, Object> options = new HashMap<String, Object>();
+ //Map<JSReference, Object> eventsMap = new HashMap<JSReference,
Object>();
- Map<JSReference, Object> eventsMap = new HashMap<JSReference,
Object>();
-
String eventShow = (toolTip.isAttached()) ? toolTip.getShowEvent() :
"";
if (eventShow.startsWith("on")) {
eventShow = eventShow.substring(2);
}
- eventsMap.put(new JSReference("showEvent"), eventShow);
-
+ getUtils().addToScriptHash(options, "showEvent", eventShow,
"mouseover", ScriptHashVariableWrapper.DEFAULT);
String eventHide = (toolTip.isAttached()) ? toolTip.getHideEvent() :
"";
if (eventHide.startsWith("on")) {
eventHide = eventHide.substring(2);
}
- eventsMap.put(new JSReference("hideEvent"), eventHide);
+ getUtils().addToScriptHash(options, "hideEvent", eventHide, null,
ScriptHashVariableWrapper.DEFAULT);
- eventsMap.put(new JSReference("delay"), new
Integer(toolTip.getShowDelay()));
- eventsMap.put(new JSReference("hideDelay"), new
Integer(toolTip.getHideDelay()));
+ getUtils().addToScriptHash(options, "delay", toolTip.getShowDelay(),
"0", ScriptHashVariableWrapper.DEFAULT);
+ getUtils().addToScriptHash(options, "hideDelay",
toolTip.getHideDelay(), "0", ScriptHashVariableWrapper.DEFAULT);
- JSFunctionDefinition ajaxFunc = null;
if (AJAX_MODE.equalsIgnoreCase(toolTip.getMode())) {
- ajaxFunc = new JSFunctionDefinition("event",
"ajaxOptions");
+ JSFunctionDefinition ajaxFunc = new JSFunctionDefinition("event",
"ajaxOptions");
JSFunction function = AjaxRendererUtils.buildAjaxFunction(component,
context);
JSReference ref = new JSReference("ajaxOptions");
function.addParameter(ref);
ajaxFunc.addToBody(function);
- }
+ getUtils().addToScriptHash(options, "ajaxFunction", ajaxFunc, null,
ScriptHashVariableWrapper.DEFAULT);
+ Map<String, Object> ajaxOptions = buildEventOptions(context, toolTip);
+ ajaxOptions.putAll(getParamsMap(context, toolTip));
+ getUtils().addToScriptHash(options, "ajaxOptions", ajaxOptions,
null, ScriptHashVariableWrapper.DEFAULT);
+ }
- Map<String, Object> ajaxOptions = buildEventOptions(context, toolTip,
targetClientId);
- ajaxOptions.putAll(getParamsMap(context, toolTip));
- Map<JSReference, Object> funcMap = new HashMap<JSReference,
Object>();
JSFunctionDefinition completeFunc = getUtils().getAsEventHandler(
context, component, "oncomplete", "; return true;");
- funcMap.put(new JSReference("oncomplete"), completeFunc);
+ getUtils().addToScriptHash(options, "oncomplete", completeFunc, null,
ScriptHashVariableWrapper.DEFAULT);
JSFunctionDefinition hideFunc = getUtils().getAsEventHandler(
context, component, "onhide", "; return true;");
- funcMap.put(new JSReference("onhide"), hideFunc);
+ getUtils().addToScriptHash(options, "onhide", hideFunc, null,
ScriptHashVariableWrapper.DEFAULT);
JSFunctionDefinition showFunc = getUtils().getAsEventHandler(
context, component, "onshow", "; return true;");
- funcMap.put(new JSReference("onshow"), showFunc);
+ getUtils().addToScriptHash(options, "onshow", showFunc, null,
ScriptHashVariableWrapper.DEFAULT);
+ getUtils().addToScriptHash(options, "disabled", toolTip.isDisabled(),
"false", ScriptHashVariableWrapper.DEFAULT);
+ getUtils().addToScriptHash(options, "direction",
toolTip.getDirection(), "bottom-right", ScriptHashVariableWrapper.DEFAULT);
+ getUtils().addToScriptHash(options, "followMouse",
toolTip.isFollowMouse(), "false", ScriptHashVariableWrapper.DEFAULT);
+ getUtils().addToScriptHash(options, "horizontalOffset",
toolTip.getHorizontalOffset(), "10", ScriptHashVariableWrapper.DEFAULT);
+ getUtils().addToScriptHash(options, "verticalOffset",
toolTip.getVerticalOffset(), "10", ScriptHashVariableWrapper.DEFAULT);
+
StringBuffer ret = new StringBuffer();
- ret.append("new
ToolTip(").append(ScriptUtils.toScript(eventsMap)).append(COMMA)
- .append(ScriptUtils.toScript(funcMap)).append(COMMA)
- .append(QUOT).append(toolTip.getClientId(context)).append(QUOT_COMMA)
- .append(QUOT).append(targetClientId).append(QUOT_COMMA)
- .append(QUOT).append(toolTip.getMode()).append(QUOT_COMMA)
- .append(toolTip.isDisabled()).append(COMMA)
- .append(QUOT).append(toolTip.getDirection()).append(QUOT_COMMA)
- .append(toolTip.isFollowMouse()).append(COMMA)
- .append(toolTip.getHorizontalOffset()).append(COMMA)
- .append(toolTip.getVerticalOffset()).append(COMMA)
- .append(ajaxFunc == null ? "null" :
ajaxFunc.toScript()).append(COMMA)
- .append(ScriptUtils.toScript(ajaxOptions)).append(");");
+ ret.append("new
ToolTip(").append(QUOT).append(toolTip.getClientId(context)).append(QUOT_COMMA)
+ .append(QUOT).append(targetClientId).append(QUOT);
+ if (!options.isEmpty()) {
+ ret.append(COMMA).append(ScriptUtils.toScript(options));
+ }
+ ret.append(");");
return ret.toString();
}
Modified:
branches/community/3.3.X/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
===================================================================
---
branches/community/3.3.X/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2009-06-05
15:53:54 UTC (rev 14539)
+++
branches/community/3.3.X/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2009-06-05
16:18:59 UTC (rev 14540)
@@ -7,30 +7,32 @@
ToolTip = Class.create();
ToolTip.prototype = {
- initialize:function(events,functions, id, parentId, mode, disabled, direction,
followMouse, horizontalOffset, verticalOffset, ajaxFunction, ajaxOptions){
- this["rich:destructor"] = "destroy";
- this.showEvent = events.showEvent;
- this.hideEvent = events.hideEvent!=""?events.hideEvent:null;
- this.onshow = functions.onshow;
- this.oncomplete = functions.oncomplete;
- this.onhide = functions.onhide;
+ //default values of options
+ showEvent: "mouseover",
+ hideEvent: null,
+ delay: 0,
+ hideDelay: 0,
+ ajaxFunction: null,
+ ajaxOptions: null,
+ oncomplete: null,
+ onhide: null,
+ onshow: null,
+ disabled: false,
+ direction: "bottom-right",
+ followMouse: false,
+ horizontalOffset: 10,
+ verticalOffset: 10,
- this.delay = events.delay;
- this.hideDelay = events.hideDelay;
+ initialize:function(id, parentId, options){
+ this["rich:destructor"] = "destroy";
this.id = id;
this.parentId = parentId;
this.parent = $(this.parentId);
- this.mode = mode;
- this.direction = direction;
- this.disabled = disabled;
- this.followMouse = followMouse;
- this.horizontalOffset = horizontalOffset;
- this.verticalOffset = verticalOffset;
- if (ajaxFunction) this.ajaxExecuteFunction = (ajaxFunction) ? ajaxFunction : function()
{};
- this.ajaxOptions = ajaxOptions;
+ Object.extend(this, options);
+
this.clientAjaxParams = {};
this.toolTip = $(id);
@@ -243,7 +245,7 @@
window.clearTimeout(this.hidingTimerHandle);
this.hidingTimerHandle = undefined;
}
- if(this.mode == 'ajax'){
+ if(this.ajaxFunction){
if(this.toolTipDefaultContent){
this.toolTipContent.innerHTML = this.toolTipDefaultContent.innerHTML;
@@ -274,13 +276,13 @@
{
this.setToolTipVisible(false);
}
- this.ajaxExecuteFunction(event, ajaxOptions);
+ this.ajaxFunction(event, ajaxOptions);
}.bind(this), this.delay);
}
else
{
this.setToolTipVisible(false);
- this.ajaxExecuteFunction(event, ajaxOptions);
+ this.ajaxFunction(event, ajaxOptions);
}
} else {
this.setToolTipPosition(e);
@@ -572,7 +574,7 @@
//this.toolTip.style.display = 'block';
if(this.isMouseOvered){
- if(this.mode == 'ajax'){
+ if(this.ajaxFunction){
this.toolTip.style.display = 'none';
if(this.clientAjaxParams){
/*
Modified:
branches/community/3.3.X/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java
===================================================================
---
branches/community/3.3.X/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java 2009-06-05
15:53:54 UTC (rev 14539)
+++
branches/community/3.3.X/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java 2009-06-05
16:18:59 UTC (rev 14540)
@@ -110,8 +110,7 @@
public void testBuildEventOptions(){
- Map eventOptions = renderer.buildEventOptions(facesContext, toolTip,
- toolTip.getParent().getClientId(facesContext));
+ Map eventOptions = renderer.buildEventOptions(facesContext, toolTip);
assertNotNull(eventOptions);
assertNotNull(eventOptions.get("oncomplete"));
}