private final static String COMMA = ",";
private final static String QUOT = "\"";
private final static String QUOT_COMMA = "\"" + ",";
public String constructJSVariable(FacesContext context, UIComponent component) {
UIToolTip toolTip = (UIToolTip) component;
String targetClientId = getTargetId(context, component);
Map<String, Object> options = new HashMap<String, Object>();
String eventShow = (toolTip.isAttached()) ? toolTip.getShowEvent() : "";
if (eventShow.startsWith("on")) {
eventShow = eventShow.substring(2);
}
RendererUtils utils = getUtils();
utils.addToScriptHash(options, "showEvent", eventShow);
String eventHide = (toolTip.isAttached()) ? toolTip.getHideEvent() : "";
if (eventHide.startsWith("on")) {
eventHide = eventHide.substring(2);
}
utils.addToScriptHash(options, "hideEvent", eventHide);
utils.addToScriptHash(options, "delay", toolTip.getShowDelay(), "0");
utils.addToScriptHash(options, "hideDelay", toolTip.getHideDelay(), "0");
if (AJAX_MODE.equalsIgnoreCase(toolTip.getMode())) {
JSFunctionDefinition ajaxFunc = new JSFunctionDefinition("event");
JSFunction function = AjaxRendererUtils.buildAjaxFunction(component, context);
Map<String, Object> ajaxOptions = buildEventOptions(context, toolTip);
ajaxOptions.putAll(getParamsMap(context, toolTip));
function.addParameter(ajaxOptions);
ajaxFunc.addToBody(function);
utils.addToScriptHash(options, "ajaxFunction", ajaxFunc);
}
JSFunctionDefinition hideFunc = utils.getAsEventHandler(
context, component, "onhide", "; return true;");
utils.addToScriptHash(options, "onhide", hideFunc);
JSFunctionDefinition showFunc = utils.getAsEventHandler(
context, component, "onshow", "; return true;");
utils.addToScriptHash(options, "onshow", showFunc);
utils.addToScriptHash(options, "disabled", toolTip.isDisabled(), "false");
String direction = toolTip.getDirection();
if (DIRECTION_AUTO.equalsIgnoreCase(direction)) {
direction = DIRECTION_BOTTOM_RIGHT;
}
utils.addToScriptHash(options, "direction", direction, DIRECTION_BOTTOM_RIGHT);
utils.addToScriptHash(options, "followMouse", toolTip.isFollowMouse(), "false");
utils.addToScriptHash(options, "horizontalOffset", toolTip.getHorizontalOffset(), "10");
utils.addToScriptHash(options, "verticalOffset", toolTip.getVerticalOffset(), "10");
StringBuffer ret = new StringBuffer();
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(");");