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:com.emitrom.pilot.core.formfactor.client.ResourceInjector.java

License:Apache License

/**
 * Loads a javascript file base on the file url
 *//*  w  w  w.  jav  a2s.  c om*/
public void inject() {
    if (this.cssUrl != null) {
        loadCss(this.cssUrl);
    }
    if (this.jsUrl != null) {

        ScriptInjector.fromUrl(this.jsUrl).setCallback(new Callback<Void, Exception>() {
            @Override
            public void onSuccess(Void result) {
                if (ResourceInjector.this.callBack != null) {
                    ResourceInjector.this.callBack.onJsLoaded();
                }
            }

            @Override
            public void onFailure(Exception reason) {
                Window.alert(reason.getMessage() + " for link " + jsUrl);
            }
        }).setWindow(ScriptInjector.TOP_WINDOW).inject();

    }
}

From source file:com.floatzcss.gwt.client.util.ScriptInjectorUtils.java

License:Apache License

/**
 * Load last script in tranche.//from  w  ww.j a va2 s  . c o  m
 *
 * @param tranche       Tranche number
 * @param finalCallback Callback that is executed after all scripts are loaded
 * @param script        Script to be loaded
 */
private void loadLastScript(final int tranche, final Callback<Void, Exception> finalCallback,
        final Script script) {
    script.fromUrl.setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>() {
        @Override
        public void onSuccess(Void result) {

            // Execute wait callback
            if (script.waitCallback != null) {
                if (lastError != null) {
                    script.waitCallback.onFailure(lastError);
                } else {
                    script.waitCallback.onSuccess(result);
                }
            }

            // Load next tranche of or call final injectCommand after all tranches are loaded
            if ((tranche + 1) < scheduledScripts.size()) {
                loadScripts(tranche + 1, finalCallback);

                // Execute final callback
            } else if (finalCallback != null) {
                if (lastError != null) {
                    finalCallback.onFailure(lastError);
                } else {
                    finalCallback.onSuccess(result);
                }
            }
        }

        @Override
        public void onFailure(Exception reason) {
            if (finalCallback != null) {
                finalCallback.onFailure(reason);
            }
        }
    }).inject();
}

From source file:com.floatzcss.gwt.client.util.ScriptInjectorUtils.java

License:Apache License

/**
 * Load script in tranche.//  w  ww .j  a va 2 s  .c  om
 *
 * @param script Script to be loaded
 */
private void loadScript(Script script) {
    script.fromUrl.setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>() {
        @Override
        public void onSuccess(Void result) {
            // Nothing to do here, we don wait
        }

        @Override
        public void onFailure(Exception reason) {
            // Store error for later
            if (lastError == null) {
                lastError = reason;
            }
        }
    }).inject();
}

From source file:com.floatzcss.gwt.client.util.ScriptInjectorUtils.java

License:Apache License

/**
 * Inject fromUrl.//from w w w.j a va 2  s .c  o  m
 * <p>
 * After the last injected fromUrl {@link #flush()} must be executed.
 * </p>
 *
 * @param url Url of the fromUrl
 * @return Reference for chaining
 */
public ScriptInjectorUtils inject(String url) {
    scripts.add(new Script(ScriptInjector.fromUrl(url).setWindow(ScriptInjector.TOP_WINDOW), false));
    return this;
}

From source file:com.getuikit.gwt.client.UIKit.java

License:Open Source License

public static void injectFormPassword() {
    if (!componentFormPasswordInjected) {
        CssHelper.loadCss(GWT.getModuleBaseURL() + "css/components/form-password.almost-flat.css");
        ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "js/components/form-password.js")
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
    }//  ww  w  .  j  a va 2s. c om
}

From source file:com.getuikit.gwt.client.UIKit.java

License:Open Source License

public static void sticky(final Element el) {
    if (!componentStickyInjected) {
        ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "js/components/sticky.js")
                .setCallback(new Callback<Void, Exception>() {
                    @Override//from  w  w  w.  j a va  2s . c  o  m
                    public void onFailure(Exception e) {
                        GWT.log("Error while trying to inject UIKit sticky.js");
                    }

                    @Override
                    public void onSuccess(Void aVoid) {
                        _sticky(el);
                    }
                }).setWindow(ScriptInjector.TOP_WINDOW).inject();
    } else {
        _sticky(el);
    }
}

From source file:com.getuikit.gwt.client.UIKit.java

License:Open Source License

public static void notification(final String message, final STATUS status, final int timeout,
        final POSITION pos) {
    if (!componentNotifyInjected) {
        CssHelper.loadCss(GWT.getModuleBaseURL() + "css/components/notify.almost-flat.css");
        ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "js/components/notify.js")
                .setCallback(new Callback<Void, Exception>() {
                    @Override// w w w . j a va 2  s.co  m
                    public void onFailure(Exception e) {
                        GWT.log("Error injecting UIKit Notification JS");
                    }

                    @Override
                    public void onSuccess(Void aVoid) {
                        _notify(message, status.toString(), timeout, pos.toString());
                    }
                }).setWindow(ScriptInjector.TOP_WINDOW).inject();
    } else {
        _notify(message, status.toString(), timeout, pos.toString());
    }
}

From source file:com.github.christianlacerda.client.GwtBootstrapTour.java

License:Apache License

@Override
public void onModuleLoad() {
    if (!isjQueryLoaded()) {
        ScriptInjector.fromString(Resources.INSTANCE.jQuery().getText()).setWindow(ScriptInjector.TOP_WINDOW)
                .inject();//w w w . j a v  a2  s  . c  om
    }
    ScriptInjector.fromString(Resources.INSTANCE.bootstrapTour().getText()).setWindow(ScriptInjector.TOP_WINDOW)
            .inject();
}

From source file:com.github.gwtcannonjs.client.CANNON.java

License:Open Source License

public static void injectRuntime() {
    if (!runtimeInjected) {
        ScriptInjector.fromString(RuntimeResource.INSTANCE.source().getText())
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
        runtimeInjected = true;/*from ww  w  . j  a  va 2 s.  c o m*/
    }
}

From source file:com.github.gwtcannonjs.client.CANNON.java

License:Open Source License

public static void injectDemoRuntime() {
    if (!demoRuntimeInjected) {
        injectRuntime();//from   w  ww.j  a  v  a  2 s  .c o m
        ScriptInjector.fromString(DemoRuntimeResource.INSTANCE.source().getText())
                .setWindow(ScriptInjector.TOP_WINDOW).inject();
        runtimeInjected = true;
    }
}