Example usage for com.google.gwt.dom.client LinkElement TAG

List of usage examples for com.google.gwt.dom.client LinkElement TAG

Introduction

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

Prototype

String TAG

To view the source code for com.google.gwt.dom.client LinkElement TAG.

Click Source Link

Usage

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Reads CSS strings and resources injected by {@link Styles#inject} from
 * the UIDL stream.//from w  ww  . j a  v  a 2 s .  com
 * 
 * @param uidl
 *            The uidl which contains "css-resource" and "css-string" tags
 */
private void injectCSS(UIDL uidl) {

    /*
     * Search the UIDL stream for CSS resources and strings to be injected.
     */
    for (Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
        UIDL cssInjectionsUidl = (UIDL) it.next();

        // Check if we have resources to inject
        if (cssInjectionsUidl.getTag().equals("css-resource")) {
            String url = getWidget().connection.translateVaadinUri(cssInjectionsUidl.getStringAttribute("url"));
            LinkElement link = LinkElement.as(DOM.createElement(LinkElement.TAG));
            link.setRel("stylesheet");
            link.setHref(url);
            link.setType("text/css");
            getHead().appendChild(link);
            // Check if we have CSS string to inject
        } else if (cssInjectionsUidl.getTag().equals("css-string")) {
            for (Iterator<?> it2 = cssInjectionsUidl.getChildIterator(); it2.hasNext();) {
                StyleInjector.injectAtEnd((String) it2.next());
                StyleInjector.flush();
            }
        }
    }
}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Internal helper for removing any stylesheet with the given URL
 * /*ww  w  . jav a2  s.c  o  m*/
 * @since 7.3
 * @param url
 *            the url to match with existing stylesheets
 */
private void removeStylesheet(String url) {
    NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG);
    for (int i = 0; i < linkTags.getLength(); i++) {
        LinkElement link = LinkElement.as(linkTags.getItem(i));
        if (!"stylesheet".equals(link.getRel())) {
            continue;
        }
        if (!"text/css".equals(link.getType())) {
            continue;
        }
        if (url.equals(link.getHref())) {
            getHead().removeChild(link);
        }
    }
}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Finds a link tag for a style sheet with the given URL
 * /*from   w w w.  j  a v  a 2 s. c  om*/
 * @since 7.3
 * @param url
 *            the URL of the style sheet
 * @return the link tag or null if no matching link tag was found
 */
private LinkElement findStylesheetTag(String url) {
    NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG);
    for (int i = 0; i < linkTags.getLength(); i++) {
        final LinkElement link = LinkElement.as(linkTags.getItem(i));
        if ("stylesheet".equals(link.getRel()) && "text/css".equals(link.getType())
                && url.equals(link.getHref())) {
            return link;
        }
    }
    return null;
}

From source file:fr.putnami.pwt.core.theme.client.DefaultThemeController.java

License:Open Source License

/**
 * Removes all link tags in the head if not initialized.
 *//*from   w  ww  . jav a 2  s.  c  om*/
private void removeCssLinks() {
    if (this.isInit) {
        return;
    }
    this.isInit = true;
    // Remove all existing link element
    NodeList<Element> links = this.getHead().getElementsByTagName(LinkElement.TAG);
    int size = links.getLength();
    for (int i = 0; i < size; i++) {
        LinkElement elem = LinkElement.as(links.getItem(0));
        if ("stylesheet".equals(elem.getRel())) {
            elem.removeFromParent();
        }
    }
}