Example usage for com.google.gwt.dom.client ScriptElement setSrc

List of usage examples for com.google.gwt.dom.client ScriptElement setSrc

Introduction

In this page you can find the example usage for com.google.gwt.dom.client ScriptElement setSrc.

Prototype

public void setSrc(@IsTrustedResourceUri String src) 

Source Link

Document

URI designating an external script.

Usage

From source file:com.arcbees.facebook.client.JavaScriptFacebook.java

License:Apache License

@Override
public void injectFacebookApi(final FacebookCallback facebookCallback) {

    String locale = "en_US";

    // get the correct locale from meta tag gwt:property facebooklocale
    final NodeList<Element> metas = Document.get().getElementsByTagName("meta");

    for (int i = 0; i < metas.getLength(); i++) {
        final MetaElement m = MetaElement.as(metas.getItem(i));

        if ("gwt:property".equals(m.getName())) {
            String content = m.getContent();
            if (content.contains("facebooklocale")) {
                locale = content.replaceFirst(".*\\=", "").trim();
            }//  www.jav  a2s. c om
        }
    }

    Element firstElement = Document.get().getBody().getFirstChildElement();

    Element fbRoot = Document.get().createDivElement();
    fbRoot.setId(FB_ROOT);

    firstElement.getParentNode().insertBefore(fbRoot, firstElement);

    ScriptElement fbScript = Document.get().createScriptElement();
    fbScript.setSrc(FB_SCRIPT_SRC1 + locale + FB_SCRIPT_SRC2);
    fbScript.setType(FB_SCRIPT_TYPE);

    fbRoot.getParentNode().insertAfter(fbScript, fbRoot);

    Timer ensureFbIsLoaded = new Timer() {
        @Override
        public void run() {
            if (isLoaded()) {
                facebookCallback.onSuccess();

                cancel();
            }
        }
    };

    ensureFbIsLoaded.scheduleRepeating(100);
}

From source file:com.clouway.gwtphonegap.client.channel.ChannelFactory.java

License:Apache License

/**
 * Creates a {@link Channel} with the given client ID, passing it to the given
 * {@link ChannelCreatedCallback}.//from w w  w  .j a  va2  s. c o  m
 *
 * <p>
 * If a Channel has already been created, this will immediately be passed to
 * the callback, so only one Channel will ever be created by this method.
 * </p>
 */
public static void createChannel(final String clientId, final ChannelCreatedCallback callback) {
    ScriptElement script = Document.get().createScriptElement();
    script.setSrc(CHANNEL_SRC);
    Document.get().getElementsByTagName("head").getItem(0).appendChild(script);

    new Timer() {
        @Override
        public void run() {
            if (scriptLoaded()) {
                channel = createChannelImpl(clientId);
                callback.onChannelCreated(channel);
                this.cancel();
            }
        }
    }.scheduleRepeating(100);
}

From source file:com.data2semantics.yasgui.client.helpers.GoogleAnalytics.java

License:Open Source License

public static void init(String userAccount) {

    Element firstScript = Document.get().getElementsByTagName("script").getItem(0);

    ScriptElement config = Document.get()
            .createScriptElement("var _gaq = _gaq || [];_gaq.push(['_setAccount', '" + userAccount
                    + "']);_gaq.push(['_trackPageview']);");

    firstScript.getParentNode().insertBefore(config, firstScript);

    ScriptElement script = Document.get().createScriptElement();

    // Add the google analytics script.
    script.setSrc(("https:".equals(Window.Location.getProtocol()) ? "https://ssl" : "http://www")
            + ".google-analytics.com/ga.js");
    script.setType("text/javascript");
    script.setAttribute("async", "true");

    firstScript.getParentNode().insertBefore(script, firstScript);
}

From source file:com.denormans.googleanalyticsgwt.api.GoogleAnalytics.java

License:Apache License

private static boolean injectAnalytics(@Nullable final String defaultTrackerID) {
    if (defaultTrackerID != null) {
        setupDefaultTrackerID(defaultTrackerID);
    }//from  w w w  .  j a  v a  2 s  .c o  m

    if (IsAlreadyInjected) {
        return true;
    }

    IsAlreadyInjected = true;

    boolean isAlreadyLoaded = get() != null;
    if (isAlreadyLoaded) {
        return true;
    }

    String src;
    if (isSSL()) {
        src = "https://ssl.google-analytics.com/ga.js";
    } else {
        src = "http://www.google-analytics.com/ga.js";
    }

    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc(src);
    script.setType("text/javascript");
    script.setAttribute("async", "true");

    doc.getBody().appendChild(script);

    return false;
}

From source file:com.extjs.gxt.ui.client.data.ScriptTagProxy.java

License:sencha.com license

public void load(DataReader<D> reader, Object loadConfig, AsyncCallback<D> callback) {
    this.callback = callback;
    this.reader = reader;
    this.config = loadConfig;

    String transId = "transId" + ID++;
    String prepend = url.indexOf("?") != -1 ? "&" : "?";
    String u = url + prepend + "callback=" + CALLBACK_CONTAINER + "." + transId + generateUrl(loadConfig);

    createCallback(this, CALLBACK_CONTAINER, transId);

    ScriptElement script = Document.get().createScriptElement();
    script.setId(transId);/*  w ww  .ja v a2s  .co m*/
    script.setType("text/javascript");
    head.appendChild(script);

    script.setSrc(u);
}

From source file:com.ghusse.dolomite.core.SignedJsonpRequest.java

License:Apache License

/**
 * Finally sends the request.//from   w  w  w.  j  av a2  s  . co m
 * @param baseUri     Uri where to send the request
 * @param arguments   Arguments of the request
 */
void send(final String baseUri, final Map<String, String> arguments) {
    registerCallbacks(CALLBACKS);

    String prefix = CALLBACKS_NAME + "." + callbackId;
    arguments.put(this.callbackParam, prefix + ".onSuccess");

    if (failureCallbackParam != null) {
        arguments.put(this.failureCallbackParam, prefix + ".onFailure");
    }

    UrlBuilder.sign(arguments, this.signatureParam, this.secret);

    final String uri = UrlBuilder.getUri(baseUri, arguments);

    ScriptElement script = Document.get().createScriptElement();
    script.setType("text/javascript");
    script.setId(callbackId);
    script.setSrc(uri.toString());
    timer = new Timer() {
        @Override
        public void run() {
            onFailure(new TimeoutException("Timeout while calling " + baseUri));
        }
    };
    timer.schedule(timeout);
    getHeadElement().appendChild(script);
}

From source file:com.github.gwtbootstrap.showcase.client.NonResShowcase.java

License:Apache License

public void onModuleLoad() {
    initWidget(uiBinder.createAndBindUi(this));
    // addSectionToContainer("Get Started", "setup", new Setup());
    // addSectionToContainer("Get Support", "support", new Support());
    addSectionToContainer("Buttons", "buttons", new Buttons());
    addSectionToContainer("Grid System", "gridSystem", new GridSystem());
    addSectionToContainer("Navigation", "navigation", new Navigation());
    addSectionToContainer("Hero Unit", "hero", new HeroUnit());
    addSectionToContainer("Forms", "forms", new Forms());
    addSectionToContainer("Page Header", "pageheader", new PageHeader());
    addSectionToContainer("Progress Bar", "progressbar", new ProgressBar());
    addSectionToContainer("Alerts", "alerts", new Alerts());
    addSectionToContainer("Pagination", "pagination", new Pagination());
    addSectionToContainer("Dropdown", "dropdown", new Dropdown());
    addSectionToContainer("Modal", "modal", new Modal());
    addSectionToContainer("Datepicker", "datepicker", new Datepicker());
    addSectionToContainer("Datetimepicker", "datetimepicker", new Datetimepicker());
    addSectionToContainer("Tooltip", "tooltip", new Tooltips());
    addSectionToContainer("Popover", "popover", new Popovers());
    addSectionToContainer("Icons", "icons", new Icons());

    RootPanel.get("content").add(this);
    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("https://apis.google.com/js/plusone.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);/*from  w w w  .ja  v  a2s .c o m*/

    github_buttons.getElement().setInnerHTML(
            "<iframe src=\"http://markdotto.github.com/github-buttons/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=watch&count=true\"\n"
                    + "                                allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"110px\" height=\"20px\"></iframe>"
                    + "<br /><iframe src=\"http://markdotto.github.com/github-buttons/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=fork&count=true\"\n"
                    + "  allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"95px\" height=\"20px\"></iframe>");

    JavaScriptInjector.inject(
            "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");");
    JavaScriptInjector.inject(
            "(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));");

    Scheduler.get().scheduleFinally(new ScheduledCommand() {

        @Override
        public void execute() {
            History.fireCurrentHistoryState();
        }
    });
}

From source file:com.github.gwtbootstrap.showcase.client.Showcase.java

License:Apache License

public void onModuleLoad() {

    CustomResources res = GWT.create(CustomResources.class);
    res.showcase().ensureInjected();//www.  ja  v a 2 s  .  c  om
    ClientFactory factory = GWT.create(ClientFactory.class);

    subnav = factory.getSubnav();

    initWidget(uiBinder.createAndBindUi(this));

    ActivityMapper activityMapper = new AppActivityMapper(factory);

    ActivityManager activityManager = new ActivityManager(activityMapper, factory.getEventBus());

    activityManager.setDisplay(main);
    PlaceHistoryMapper mapper = factory.getPlaceHistoryMapper();
    final PlaceHistoryHandler handler = new PlaceHistoryHandler(mapper);
    handler.register(factory.getPlaceController(), factory.getEventBus(), new OverviewPlace(""));

    final Map<Menus, NavLink> map = new EnumMap<Menus, NavLink>(Menus.class);
    for (Menus menu : Menus.values()) {
        NavLink link = new NavLink(menu.getDisplay());
        link.setHref("#" + menu.getName() + ":");

        if (menu == Menus.GWT) {
            nav.add(new Divider());
        }
        nav.add(link);

        map.put(menu, link);
    }

    factory.getEventBus().addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {

        @Override
        public void onPlaceChange(PlaceChangeEvent event) {
            Place place = event.getNewPlace();

            if (place instanceof HasMenuPlace) {
                HasMenuPlace menuPlace = (HasMenuPlace) place;

                for (Map.Entry<Menus, NavLink> entry : map.entrySet()) {
                    if (entry.getKey().equals(menuPlace.getMenu())) {
                        entry.getValue().setActive(true);
                    } else {
                        entry.getValue().setActive(false);
                    }
                }

            }
        }
    });

    // addSectionToContainer("Get Started", "setup", new Setup());
    // addSectionToContainer("Get Support", "support", new Support());
    // addSectionToContainer("Buttons", "buttons", new Buttons());
    // addSectionToContainer("Grid System", "gridSystem", new GridSystem());
    // addSectionToContainer("Navigation", "navigation", new Navigation());
    // addSectionToContainer("Hero Unit", "hero", new HeroUnit());
    // addSectionToContainer("Forms", "forms", new Forms());
    // addSectionToContainer("Page Header", "pageheader", new PageHeader());
    // addSectionToContainer("Progress Bar", "progressbar", new
    // ProgressBar());
    // addSectionToContainer("Alerts", "alerts", new Alerts());
    // addSectionToContainer("Pagination", "pagination", new Pagination());
    // addSectionToContainer("Dropdown", "dropdown", new Dropdown());
    // addSectionToContainer("Modal", "modal", new Modal());
    // addSectionToContainer("Datepicker", "datepicker", new Datepicker());
    // addSectionToContainer("Tooltip", "tooltip", new Tooltips());
    // addSectionToContainer("Popover", "popover", new Popovers());
    // addSectionToContainer("Icons", "icons", new Icons());

    RootPanel.get("content").add(this);
    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("https://apis.google.com/js/plusone.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);

    //        github_buttons
    //                .getElement()
    //                .setInnerHTML(
    //                        "<iframe src=\"http://ghbtns.com/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=watch&count=true\"\n"
    //                                + "                                allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"110px\" height=\"20px\"></iframe>"
    //                                + "<br /><iframe src=\"http://ghbtns.com/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=fork&count=true\"\n"
    //                                + "  allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"95px\" height=\"20px\"></iframe>");

    JavaScriptInjector.inject(
            "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");");
    JavaScriptInjector.inject(
            "(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));");

    String token = History.getToken();
    if (!token.equals("")) {
        History.newItem("");
        History.newItem(token);
    }
}

From source file:com.google.appinventor.client.jsonp.JsonpConnection.java

License:Open Source License

/**
 * Sends a JSONP request by embedding a SCRIPT tag into the document.
 *
 * @param id the id used for the script tag and to identify the callback
 * @param request the request to be made
 * @param parameters the parameters for the request
 * @param function a function that transforms the response into the type
 *        that the callback needs/*w  ww  . j  av a2s. co  m*/
 * @param callback the callback that should be called with the transformed
 *        response
 */
private <T> void sendJsonpRequest(String id, String request, Map<String, Object> parameters,
        final Function<String, ? extends T> function, final AsyncCallback<T> callback) {
    Preconditions.checkNotNull(id);

    // Prepare an intermediate callback that converts the String result to T.
    if (callback != null) {
        Preconditions.checkNotNull(function);
        CALLBACKS.put(id, new AsyncCallback<String>() {
            @Override
            public void onSuccess(String jsonResult) {
                T result;
                try {
                    result = function.apply(jsonResult);
                } catch (RuntimeException e) {
                    callback.onFailure(e);
                    return;
                }
                callback.onSuccess(result);
            }

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }
        });
    }

    // Insert a script tag into the document.
    Document document = Document.get();
    ScriptElement script = document.createScriptElement();
    String uri = makeURI(request, parameters, id);
    script.setSrc(uri);
    script.setId(id);
    Element bodyElement = document.getElementsByTagName("body").getItem(0);
    Element previous = document.getElementById(id);
    if (previous != null) {
        bodyElement.replaceChild(script, previous);
    } else {
        bodyElement.appendChild(script);
    }
}

From source file:com.google.gwt.sample.vanfood.client.TwitterPopup.java

public TwitterPopup(Vendor vendor) {

    super(true);//from   www.j  a  va 2s.c  o  m
    this.setStyleName("PopupPanel");

    int left = (Window.getClientWidth()) / 3;
    int top = (Window.getClientHeight()) / 2;
    this.setPopupPosition(left, top);

    String vendorName = null;
    try {
        vendorName = vendor.getName();
    } catch (Exception e) {

    }
    if ((vendorName == null) || (vendorName.equalsIgnoreCase("Name not available")))
        vendorName = "a street vendor";
    Label desc = new Label("You've added " + vendorName + " to your favourites list." + "\n"
            + "(Click outside the box to close)");
    mainPanel.add(desc);

    String url = "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"I just added "
            + vendorName + " to my list of favourite street vendors\" target=\"_blank\">Tweet</a>";
    HTML html = new HTML(url);

    mainPanel.add(html);

    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("http://platform.twitter.com/widgets.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);

    this.add(mainPanel);

}