Example usage for com.google.gwt.core.client ScriptInjector TOP_WINDOW

List of usage examples for com.google.gwt.core.client ScriptInjector TOP_WINDOW

Introduction

In this page you can find the example usage for com.google.gwt.core.client ScriptInjector TOP_WINDOW.

Prototype

JavaScriptObject TOP_WINDOW

To view the source code for com.google.gwt.core.client ScriptInjector TOP_WINDOW.

Click Source Link

Document

Returns the top level window object.

Usage

From source file:org.ow2.proactive_grid_cloud_portal.common.client.JSUtil.java

License:Open Source License

private static void injectScriptOneAfterAnother(final List<String> pathAsList) {
    ScriptInjector.fromUrl(pathAsList.remove(0)).setWindow(ScriptInjector.TOP_WINDOW)
            .setCallback(new Callback<Void, Exception>() {
                @Override//from w w w  .j  a  v a  2s.c  o m
                public void onFailure(Exception reason) {
                }

                @Override
                public void onSuccess(Void result) {
                    if (!pathAsList.isEmpty()) {
                        injectScriptOneAfterAnother(pathAsList);
                    }
                }
            }).inject();
}

From source file:org.piwik.wrapper.client.PiwikWrapperEntryPoint.java

License:Apache License

public void onModuleLoad() {
    ScriptInjector.fromString("var _paq = _paq || [];").setWindow(ScriptInjector.TOP_WINDOW).inject();
}

From source file:org.primordion.xholon.io.gwt.HtmlScriptHelper.java

License:Open Source License

/**
 * Inject a script into the app, and execute it once.
 * @param scriptBody /*from  w ww .ja va 2  s .  c o  m*/
 * @param removeTag Whether or not to remove the HTML tag after the script is run.
 *        GWT default is true
 * @return 
 */
public static JavaScriptObject fromString(String scriptBody, boolean removeTag) {
    JavaScriptObject jso = ScriptInjector.fromString(scriptBody).setWindow(ScriptInjector.TOP_WINDOW)
            .setRemoveTag(removeTag).inject();
    return jso;
}

From source file:org.primordion.xholon.io.gwt.HtmlScriptHelper.java

License:Open Source License

/**
 * Inject a script into the app./*from  www  .  j  av  a 2  s.  c om*/
 * @param scriptBody 
 * @param removeTag Whether or not to remove the HTML tag after the script is run.
 *        GWT default is true
 * @return 
 */
public static JavaScriptObject fromUrl(String scriptUrl, boolean removeTag) {
    JavaScriptObject jso = ScriptInjector.fromUrl(scriptUrl).setWindow(ScriptInjector.TOP_WINDOW)
            .setRemoveTag(removeTag).inject();
    consoleLog(jso);
    return jso;
}

From source file:org.primordion.xholon.io.gwt.HtmlScriptHelper.java

License:Open Source License

/**
 * USE require.js INSTEAD./*from  w w w.  j a  v  a  2  s.co m*/
 * This method should only be used for very simple cases,
 * where only one script is being loaded.
 * Make a required script available.
 * Load it into a script element in html head, if it's not already loaded.
 * Do nothing if it's already loaded.
 * TYpically, this is invoked from the user's postConfigure() code.
 * @param scriptName The name of the script file (ex: 'd3.v2.min.js').
 * @param scriptPath The path to the script (ex: 'http://www.primordion.com/Xholon/webEdition/lib/').
 *   If null or missing, then a default path is assumed.
 */
public static void requireScript(String scriptName, String scriptPath) {
    if ((scriptName == null) || (scriptName.length() == 0)) {
        return;
    }
    if (!scriptName.endsWith(".js")) {
        scriptName = scriptName + ".js";
    }
    if ((scriptPath == null) || (scriptPath.length() == 0)) {
        scriptPath = DEFAULT_REQUIRE_PATH;
    } else if (!(scriptPath.startsWith("http://")) && !(scriptPath.startsWith("https://"))) {
        // this may be a malicious URI, perhaps starting with "javascript:"
        return;
    }
    if ("http://127.0.0.1:9876/xholon/lib/".equals(scriptPath)) {
        // for use with devmode
        scriptPath = "http://127.0.0.1:8888/xholon/lib/";
    }
    if (!isLoaded(scriptName)) {
        final JavaScriptObject jso = ScriptInjector.fromUrl(scriptPath + scriptName)
                .setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(false)
                .setCallback(new Callback<Void, Exception>() {
                    public void onSuccess(Void result) {
                        consoleLog("Script load success.");
                    }

                    public void onFailure(Exception reason) {
                        consoleLog("Script load failed.");
                        // TODO if it's a 404 or other error where the script can't be loaded, delete the script tag
                        // the following code won't compile "error: variable jso might not have been initialized"
                        /*if (jso != null) {
                          Node scriptNode = (Node)jso.cast();
                          consoleLog(scriptNode);
                          scriptNode.removeFromParent();
                        }*/
                    }
                }).inject();
        consoleLog(jso); // nodeName/tagName="SCRIPT" localName="script"
    }
}

From source file:org.swellrt.web.wave.atmosphere.WaveSocketAtmosphere.java

License:Apache License

@Override
public void connect() {

    if (socket == null) {

        // Build the atmosphere.js URL using the Websocket URL
        final String scriptHost = urlBase.startsWith("wss://") ? "https://" + urlBase.substring(6)
                : "http://" + urlBase.substring(5);

        String scriptUrl = new String(scriptHost);

        // Remove trailing '/' before add context
        if (scriptUrl.lastIndexOf("/") == scriptUrl.length() - 1)
            scriptUrl = scriptUrl.substring(0, scriptUrl.length() - 1);

        scriptUrl += "/atmosphere/atmosphere.js";

        ScriptInjector.fromUrl(scriptUrl).setCallback(new Callback<Void, Exception>() {
            public void onFailure(Exception reason) {
                throw new IllegalStateException("atmosphere.js load failed!");
            }/*  w w  w .j  a va 2 s.  c  o  m*/

            public void onSuccess(Void result) {
                // We assume Atmosphere is going to work only with http(s) schemas
                socket = AtmosphereSocket.create(WaveSocketAtmosphere.this, scriptHost,
                        true ? "websocket" : "long-polling", "long-polling", clientVersion, sessionId);
                socket.connect();
            }

        }).setWindow(ScriptInjector.TOP_WINDOW).inject();

    } else {
        socket.connect();
    }
}

From source file:org.uberfire.client.promise.PromisePolyfillBootstrapper.java

License:Apache License

static void ensurePromiseApiIsAvailable() {
    if (!isPromiseApiAvailable()) {
        ScriptInjector.fromString(PromisePolyfillClientBundle.INSTANCE.promisePolyfill().getText())
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
    }//  w w w. j  av a 2 s .  c o m
}

From source file:org.uberfire.client.views.pfly.sys.PatternFlyBootstrapper.java

License:Apache License

/**
 * Uses GWT's ScriptInjector to put jQuery in the page if it isn't already. All Errai IOC beans that rely on
 * GWTBootstrap 3 widgets should call this before creating their first such widget.
 *///from  w  ww.j  av a  2s.c  om
public static void ensurejQueryIsAvailable() {
    if (!isjQueryLoaded()) {
        ScriptInjector.fromString(GwtBootstrap3ClientBundle.INSTANCE.jQuery().getText())
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
    }
}

From source file:org.uberfire.client.views.pfly.sys.PatternFlyBootstrapper.java

License:Apache License

public static void ensurePrettifyIsAvailable() {
    if (!isPrettifyLoaded()) {
        ScriptInjector.fromString(PatternFlyClientBundle.INSTANCE.prettify().getText())
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
    }//from  w  w  w  .  j  a v a2 s .c  om
}

From source file:org.uberfire.client.views.pfly.sys.PatternFlyBootstrapper.java

License:Apache License

public static void ensureBootstrapSelectIsAvailable() {
    if (!isBootstrapSelectLoaded()) {
        ScriptInjector.fromString(PatternFlyClientBundle.INSTANCE.bootstrapSelect().getText())
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
    }//  ww  w  .  j  a v a2  s  .  com
}