Search in sources :

Example 1 with Document

use of elemental.dom.Document in project flow by vaadin.

the class SystemErrorHandler method handleError.

private Element handleError(String caption, String message, String details, String querySelector) {
    Document document = Browser.getDocument();
    Element systemErrorContainer = document.createDivElement();
    systemErrorContainer.setClassName("v-system-error");
    if (caption != null) {
        Element captionDiv = document.createDivElement();
        captionDiv.setClassName("caption");
        captionDiv.setTextContent(caption);
        systemErrorContainer.appendChild(captionDiv);
        Console.error(caption);
    }
    if (message != null) {
        Element messageDiv = document.createDivElement();
        messageDiv.setClassName("message");
        messageDiv.setTextContent(message);
        systemErrorContainer.appendChild(messageDiv);
        Console.error(message);
    }
    if (details != null) {
        Element detailsDiv = document.createDivElement();
        detailsDiv.setClassName("details");
        detailsDiv.setTextContent(details);
        systemErrorContainer.appendChild(detailsDiv);
        Console.error(details);
    }
    if (querySelector != null) {
        Element baseElement = document.querySelector(querySelector);
        // error will not be displayed
        if (baseElement != null) {
            // if the baseElement has a shadow root, add the warning to
            // the shadow - otherwise add it to the baseElement
            findShadowRoot(baseElement).orElse(baseElement).appendChild(systemErrorContainer);
        }
    } else {
        document.getBody().appendChild(systemErrorContainer);
    }
    return systemErrorContainer;
}
Also used : Element(elemental.dom.Element) Document(elemental.dom.Document)

Example 2 with Document

use of elemental.dom.Document in project flow by vaadin.

the class ResourceLoader method initLoadedResourcesFromDom.

/**
 * Populates the resource loader with the scripts currently added to the
 * page.
 */
private void initLoadedResourcesFromDom() {
    Document document = Browser.getDocument();
    // detect already loaded scripts and stylesheets
    NodeList scripts = document.getElementsByTagName("script");
    for (int i = 0; i < scripts.getLength(); i++) {
        ScriptElement element = (ScriptElement) scripts.item(i);
        String src = element.getSrc();
        if (src != null && src.length() != 0) {
            loadedResources.add(src);
        }
    }
    NodeList links = document.getElementsByTagName("link");
    for (int i = 0; i < links.getLength(); i++) {
        LinkElement linkElement = (LinkElement) links.item(i);
        String rel = linkElement.getRel();
        String href = linkElement.getHref();
        if (("stylesheet".equalsIgnoreCase(rel) || "import".equalsIgnoreCase(rel)) && href != null && href.length() != 0) {
            loadedResources.add(href);
        }
    }
}
Also used : NodeList(elemental.dom.NodeList) LinkElement(elemental.html.LinkElement) ScriptElement(elemental.html.ScriptElement) Document(elemental.dom.Document)

Aggregations

Document (elemental.dom.Document)2 Element (elemental.dom.Element)1 NodeList (elemental.dom.NodeList)1 LinkElement (elemental.html.LinkElement)1 ScriptElement (elemental.html.ScriptElement)1