Search in sources :

Example 1 with HTMLHeadElement

use of elemental2.dom.HTMLHeadElement in project console by hal.

the class ExtensionRegistry method jsInject.

// ------------------------------------------------------ JS methods
/**
 * Injects the script and stylesheets of an extension. This method is used during development. Normally you don't have to
 * call this method.
 *
 * @param script the extension's script.
 * @param stylesheets an optional list of stylesheets.
 */
@JsMethod(name = "inject")
@SuppressWarnings({ "HardCodedStringLiteral", "DuplicateStringLiteralInspection" })
public void jsInject(String script, @EsParam("string[]") String[] stylesheets) {
    HTMLHeadElement head = document.head;
    if (stylesheets != null && stylesheets.length != 0) {
        for (String stylesheet : stylesheets) {
            HTMLLinkElement linkElement = (HTMLLinkElement) document.createElement("link");
            linkElement.rel = "stylesheet";
            linkElement.href = stylesheet;
            head.appendChild(linkElement);
        }
    }
    HTMLScriptElement scriptElement = (HTMLScriptElement) document.createElement("script");
    scriptElement.src = script;
    scriptElement.setAttribute("async", true);
    head.appendChild(scriptElement);
}
Also used : HTMLLinkElement(elemental2.dom.HTMLLinkElement) HTMLScriptElement(elemental2.dom.HTMLScriptElement) HTMLHeadElement(elemental2.dom.HTMLHeadElement) JsMethod(jsinterop.annotations.JsMethod)

Aggregations

HTMLHeadElement (elemental2.dom.HTMLHeadElement)1 HTMLLinkElement (elemental2.dom.HTMLLinkElement)1 HTMLScriptElement (elemental2.dom.HTMLScriptElement)1 JsMethod (jsinterop.annotations.JsMethod)1