Example usage for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript.

Prototype

void prependJavaScript(CharSequence javascript);

Source Link

Document

Adds javascript that will be evaluated on the client side before components are replaced.

Usage

From source file:org.wicketstuff.yui.markup.html.container.YuiWindows.java

License:Apache License

/**
 * Add a window.//from   w  w w.java 2 s .com
 * <p>
 * If this is called during an AJAX call, the changes are automatically
 * added to the ajax request target.
 * 
 * @param window the new window (not null)
 * @return the component id of the new window (used to remove it)
 */
public String addWindow(final IYuiWindow window) {
    YuiPanel yuiPanel = new YuiPanel(getRepeater().newChildId()) {
        @Override
        protected String getOpts() {
            return newOptions(window.getDimension(), window.getAdditionalOpts());
        }

        @Override
        protected String getResizeOpts() {
            return "{handles : ['br'], proxy: true, status: true, animate: false}";
        }

        @Override
        protected Component newBodyPanel(String id) {
            return window.newBody(id);
        }

        @Override
        protected Component newFooterPanel(String id) {
            return window.newFooter(id);
        }

        @Override
        protected Component newHeaderPanel(String id) {
            return window.newHeader(id);
        }

        @Override
        protected void onHide(AjaxRequestTarget target, String type) {
            getRepeater().remove(this);
            removeElementFromDom(target, getMarkupId());
        }
    };
    yuiPanel.setOutputMarkupId(true);
    yuiPanel.setUsesOverlayManager(true);
    getRepeater().add(yuiPanel);

    AjaxRequestTarget target = AjaxRequestTarget.get();
    if (target != null) {
        String createDiv = "(function(){var c=document.createElement('div');c.id='%s';Wicket.$('%s').appendChild(c)})();";
        target.prependJavascript(String.format(createDiv, yuiPanel.getMarkupId(), getMarkupId()));
        target.addComponent(yuiPanel);
        // TODO: find out why javascript of yuiPanel's header contributor
        // fails during the AJAX update in FireFox, works fine in IE.
    }

    return yuiPanel.getId();
}

From source file:org.wicketstuff.yui.markup.html.cropp.ImageCropper.java

License:Apache License

protected WebMarkupContainer newLinkComponent(String id) {
    return new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override// ww  w .  j  a  va 2 s  . c  om
        public void onClick(AjaxRequestTarget target) {
            target.prependJavascript("" + callbackBehavior.getEventHandler());
        }
    };
}