private String getTargetId(FacesContext context, UIComponent component) {
return component.getParent().getClientId(context);
}
public String constructJSVariable(FacesContext context, UIComponent component) {
UIToolTip toolTip = (UIToolTip)component;
String targetClientId = getTargetId(context, component);
StringBuffer ret = new StringBuffer();
String comma = ",";
String quot = "\"";
String event = toolTip.getEvent();
if(event.startsWith("on")){
event = event.substring(2);
}
Map eventsMap = new HashMap();
eventsMap.put(new JSReference("event"), event);
eventsMap.put(new JSReference("onshow"), toolTip.getOnshow());
eventsMap.put(new JSReference("oncomplete"), toolTip.getOncomplete());
eventsMap.put(new JSReference("onhide"), toolTip.getOnhide());
eventsMap.put(new JSReference("delay"), new Integer(toolTip.getShowDelay()));
eventsMap.put(new JSReference("hideDelay"), new Integer(toolTip.getHideDelay()));
JSFunction function = AjaxRendererUtils.buildAjaxFunction(component, context);
JSReference ref = new JSReference("ajaxOptions");
function.addParameter(ref);
String ajaxFunc = function.toScript();
Map ajaxOptions = buildEventOptions(context, toolTip, targetClientId);
ret.append("new ToolTip(" + ScriptUtils.toScript(eventsMap)).append(comma).append(quot).append( toolTip.getClientId(context)).append(quot).append(comma).
append(quot).append(targetClientId).append(quot).append(comma).
append(quot).append(toolTip.getMode()).append(quot).append(comma).
append(toolTip.isDisabled()).append(comma).
append(quot).append(toolTip.getDirection()).append(quot).append(comma).
append(toolTip.isFollowMouse()).append(comma).
append(toolTip.getHorizontalOffset()).append(comma).
append(toolTip.getVerticalOffset()).append(comma).
append("\"").append(ajaxFunc).append("\"").append(comma).append(ScriptUtils.toScript(ajaxOptions)).append(");");
return ret.toString();
}