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

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

Introduction

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

Prototype

public void setType(String type) 

Source Link

Document

The content type of the script language.

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();
            }/*from w  w  w .  j av a2  s.  c o m*/
        }
    }

    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.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  ww . j  av a2 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);//from w  w w .j av a2s  .com
    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 ww  . ja v  a 2 s.  c o 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.j a v a2  s.com

    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();//from w  ww .j a  v a2 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.gwt.sample.vanfood.client.TwitterPopup.java

public TwitterPopup(Vendor vendor) {

    super(true);//  w  ww.  j a v a2  s  .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);

}

From source file:com.googlecode.gwt.charts.client.ajaxloader.AjaxLoader.java

License:Apache License

/**
 * Adds a script element to the DOM that loads the Ajax API Loader main
 * script "jsapi".//from   ww w  . j a va 2s  .  c om
 * 
 * @param apiKey
 *            Optional API key value (pass null to omit the key). See
 *            http://code.google.com/apis/ajaxsearch/signup.html
 * @returns <code>true</code> if the API has already been loaded. Otherwise,
 *          returns <code>false</code>, meaning that the application should
 *          wait for a callback.
 */
private static boolean injectJsapi(String apiKey, String hostname) {
    if (alreadyInjected) {
        return true;
    }
    boolean alreadyLoaded = nativeCreateCallback();
    alreadyInjected = true;
    if (alreadyLoaded) {
        return true;
    }
    Document doc = Document.get();
    String key = (apiKey == null) ? "" : ("key=" + apiKey + "&");
    hostname = (hostname == null) ? "www.google.com" : hostname;
    String src = getProtocol() + "//" + hostname + "/jsapi?" + key + "callback=__gwt_AjaxLoader_onLoad";
    ScriptElement script = doc.createScriptElement();
    script.setSrc(src);
    script.setType("text/javascript");
    doc.getBody().appendChild(script);
    return false;
}

From source file:com.googlecode.gwt.charts.client.apiloader.ApiLoader.java

License:Apache License

/**
 * Adds a script element to the DOM that loads the API Loader main script "jsapi".
 * //w w  w  .ja v  a  2 s. co m
 * @param apiKey
 *        Optional API key value (pass null to omit the key). See
 *        http://code.google.com/apis/ajaxsearch/signup.html
 * @returns <code>true</code> if the API has already been loaded. Otherwise,
 *          returns <code>false</code>, meaning that the application should
 *          wait for a callback.
 */
private boolean injectJsApi(String apiKey) {
    if (alreadyInjected) {
        return true;
    }
    boolean alreadyLoaded = createCallback(this);
    alreadyInjected = true;
    if (alreadyLoaded) {
        return true;
    }
    Document doc = Document.get();
    String key = (apiKey == null) ? "" : ("key=" + apiKey + "&");
    String protocol = (Window.Location.getProtocol().equals("https:")) ? "https:" : "http:";
    String src = protocol + "//" + HOSTNAME + "/jsapi?" + key + "callback=__gwt_charts_AjaxLoader_onLoad";
    ScriptElement script = doc.createScriptElement();
    script.setSrc(src);
    script.setType("text/javascript");
    doc.getBody().appendChild(script);
    return false;
}