@Override
  public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent)
      throws IOException {

    ResponseWriter responseWriter = facesContext.getResponseWriter();

    Popover popover = (Popover) uiComponent;
    ClientComponent clientComponent = (ClientComponent) uiComponent;
    String clientVarName = getClientVarName(facesContext, clientComponent);
    String clientKey = clientComponent.getClientKey();

    if (clientKey == null) {
      clientKey = clientVarName;
    }

    if (popover.isHideIconRendered()) {

      // Add an "x" toolbar icon so that the popover can be hidden just like alloy:dialog can.
      responseWriter.write(LIFERAY_COMPONENT);
      responseWriter.write("('");
      responseWriter.write(clientKey);
      responseWriter.write(
          "').addToolbar([{cssClass:'close',label:'\u00D7',on:{click:function(event){Liferay.component('");
      responseWriter.write(clientKey);
      responseWriter.write("').hide();}},render:true}],'header');");
    }

    // Move the overlayBody div into the popover-content div.
    String clientId = popover.getClientId(facesContext);
    String overlayBodyClientId = clientId.concat(OVERLAY_BODY_SUFFIX);
    String escapedOverlayBodyClientId = escapeClientId(overlayBodyClientId);

    String contentBoxClientId = clientId.concat(CONTENT_BOX_SUFFIX);
    String escapedContentBoxClientId = escapeClientId(contentBoxClientId);

    responseWriter.write("A.one('#");
    responseWriter.write(escapedOverlayBodyClientId);
    responseWriter.write("').appendTo(A.one('div#");
    responseWriter.write(escapedContentBoxClientId);
    responseWriter.write(">div.popover-content'));");

    if (popover.isDismissible()) {
      encodeOverlayDismissible(responseWriter, popover, clientKey);
    }

    encodeOverlayJavaScriptCustom(responseWriter, facesContext, popover);

    if ((popover.getFor() == null) && facesContext.isProjectStage(ProjectStage.Development)) {
      logger.error("The 'for' attribute is required for alloy:popover");
    }
  }
  @Override
  public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent)
      throws IOException {

    ResponseWriter responseWriter = facesContext.getResponseWriter();

    InputSourceCode inputSourceCode = (InputSourceCode) uiComponent;
    Boolean readOnly = inputSourceCode.getReadOnly();

    ClientComponent clientComponent = (ClientComponent) uiComponent;
    String clientVarName = getClientVarName(facesContext, clientComponent);
    String clientKey = clientComponent.getClientKey();

    if (clientKey == null) {
      clientKey = clientVarName;
    }

    encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);

    if ((readOnly == null) || (!readOnly)) {

      String hiddenInputClientId = getHiddenInputClientId(facesContext, uiComponent);
      String escapedHiddenInputClientId = "#" + escapeClientId(hiddenInputClientId);

      responseWriter.write(clientVarName);
      responseWriter.write(".getSession().on('change', function() {A.one('");
      responseWriter.write(escapedHiddenInputClientId);
      responseWriter.write("').set('value',");
      responseWriter.write(clientVarName);
      responseWriter.write(".getSession().getValue())});");
    }

    responseWriter.write(clientVarName);
    responseWriter.write(".editor.setOptions({ minLines: ");
    responseWriter.write(inputSourceCode.getMinLines().toString());
    responseWriter.write("});");
    responseWriter.write(clientVarName);
    responseWriter.write(".editor.setOptions({ maxLines: ");
    responseWriter.write(inputSourceCode.getMaxLines().toString());
    responseWriter.write("});");
  }