Search in sources :

Example 1 with elemental2.dom

use of elemental2.dom in project gwtproject by treblereel.

the class Element method scrollIntoView.

/**
 * Scrolls this element into view.
 *
 * <p>This method crawls up the DOM hierarchy, adjusting the scrollLeft and scrollTop properties
 * of each scrollable element to ensure that the specified element is completely in view. It
 * adjusts each scroll position by the minimum amount necessary.
 */
@JsOverlay
public final void scrollIntoView() {
    HTMLElement e = Js.uncheckedCast(this);
    double left = e.offsetLeft, top = e.offsetTop;
    double width = e.offsetWidth, height = e.offsetHeight;
    if (e.parentNode != e.offsetParent && e.parentNode.nodeType == 1) {
        left -= Js.<HTMLElement>uncheckedCast(e.parentNode).offsetLeft;
        top -= Js.<HTMLElement>uncheckedCast(e.parentNode).offsetTop;
    }
    elemental2.dom.Node cur = e.parentNode;
    while (cur != null && (cur.nodeType == 1)) {
        HTMLElement curEl = Js.uncheckedCast(cur);
        if (left < curEl.scrollLeft) {
            curEl.scrollLeft = left;
        }
        if (left + width > curEl.scrollLeft + curEl.clientWidth) {
            curEl.scrollLeft = (left + width) - curEl.clientWidth;
        }
        if (top < curEl.scrollTop) {
            curEl.scrollTop = top;
        }
        if (top + height > curEl.scrollTop + curEl.clientHeight) {
            curEl.scrollTop = (top + height) - curEl.clientHeight;
        }
        double offsetLeft = curEl.offsetLeft, offsetTop = curEl.offsetTop;
        if (curEl.parentNode != curEl.offsetParent && curEl.parentNode.nodeType == 1) {
            offsetLeft -= Js.<HTMLElement>uncheckedCast(curEl.parentNode).offsetLeft;
            offsetTop -= Js.<HTMLElement>uncheckedCast(curEl.parentNode).offsetTop;
        }
        left += offsetLeft - curEl.scrollLeft;
        top += offsetTop - curEl.scrollTop;
        cur = curEl.parentNode;
    }
}
Also used : HTMLElement(elemental2.dom.HTMLElement) JsOverlay(jsinterop.annotations.JsOverlay)

Example 2 with elemental2.dom

use of elemental2.dom in project gwtproject by treblereel.

the class CustomEventsTest method createCustomEvent.

private static NativeEvent createCustomEvent(String evt) {
    elemental2.dom.Event event = new Event("Event");
    event.initEvent(evt, true, false);
    return Js.uncheckedCast(event);
}
Also used : Event(elemental2.dom.Event) Event(elemental2.dom.Event) DomEvent(org.gwtproject.event.dom.client.DomEvent) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 3 with elemental2.dom

use of elemental2.dom in project gwtproject by treblereel.

the class RichTextAreaImplStandard method initElement.

@Override
public void initElement() {
    // Most browsers don"t like setting designMode until slightly _after_
    // the iframe becomes attached to the DOM. Any non-zero timeout will do
    // just fine.
    RichTextAreaImplStandard _this = this;
    _this.onElementInitializing();
    DomGlobal.setTimeout((ignore) -> {
        if (_this.elem != null) {
            HTMLIFrameElement iframe = Js.uncheckedCast(_this.elem);
            if (iframe.contentWindow != null) {
                ((JsPropertyMap) ((JsPropertyMap) iframe.contentWindow).get("document")).set("designMode", "On");
                _this.onElementInitialized();
            }
        }
    }, 1.0D, new Object[0]);
}
Also used : HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) JsPropertyMap(jsinterop.base.JsPropertyMap)

Example 4 with elemental2.dom

use of elemental2.dom in project console by hal.

the class MicroprofileHealthPreview method update.

@Override
public void update(SubsystemMetadata item) {
    ResourceAddress addressWeb = MICROPROFILE_HEALTH_TEMPLATE.resolve(statementContext);
    Operation operation = new Operation.Builder(addressWeb, CHECK).build();
    // clear the previous state and remove the DOM children to populate with new values
    elements.clear();
    Elements.removeChildrenFrom(section);
    dispatcher.execute(operation, result -> {
        String outcome = result.get(STATUS).asString();
        if (UP.equals(outcome)) {
            section.appendChild(outcomeUp.element());
        } else {
            section.appendChild(outcomeDown.element());
        }
        section.appendChild(p().textContent(resources.messages().microprofileHealthPreviewDescription()).element());
        List<ModelNode> checks = new ArrayList<>();
        ModelNode modelChecks = result.get(CHECKS);
        int max = 10;
        if (modelChecks.isDefined()) {
            checks = modelChecks.asList();
            if (checks.size() < 10) {
                max = checks.size();
            }
        }
        // checks may return an empty list
        if (!checks.isEmpty()) {
            // show the first 10 checks in the preview pane
            for (int i = 0; i < max; i++) {
                ModelNode check = checks.get(i);
                String name = check.get(NAME).asString();
                String state = check.get(STATUS).asString();
                section.appendChild(h(2, name).element());
                Map<String, String> dataMap = new HashMap<>();
                if (check.hasDefined("data")) {
                    check.get("data").asPropertyList().forEach(data -> {
                        String key = data.getName();
                        String val = data.getValue().asString();
                        dataMap.put(key, val);
                    });
                }
                HTMLElement checkElement = checkElement(state, dataMap);
                section.appendChild(checkElement);
            }
        } else {
            section.appendChild(p().textContent(resources.messages().microprofileHealthNoChecks()).element());
        }
        elements.add(section);
    });
}
Also used : HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 5 with elemental2.dom

use of elemental2.dom in project console by hal.

the class DataTable method attach.

/**
 * Initialized the {@link Api} instance using the {@link Options} given at constructor argument. Make sure to call this
 * method before using any of the API methods. It's safe to call the methods multiple times (the initialization will happen
 * only once).
 */
@Override
public void attach() {
    if (api == null) {
        options.id = id;
        api = Api.<T>select(HASH + id).dataTable(options);
        api.on(DRAW, CallbackUnionType.of((DrawCallback) (evt, settings) -> {
            Map<String, InlineActionHandler<T>> columnActionHandler = options.columnActionHandler;
            elemental2.dom.Element table = document.getElementById(options.id);
            if (table != null && columnActionHandler != null && !columnActionHandler.isEmpty()) {
                Elements.stream(table.querySelectorAll("." + columnAction)).filter(htmlElements()).map(asHtmlElement()).forEach(link -> {
                    InlineActionHandler<T> columnAction = columnActionHandler.get(link.id);
                    if (columnAction != null) {
                        bind(link, click, event -> {
                            event.stopPropagation();
                            // find enclosing tr
                            HTMLElement e = link;
                            while (e != null && e != document.body && !"tr".equalsIgnoreCase(e.tagName)) {
                                e = (HTMLElement) e.parentNode;
                            }
                            if (e != null) {
                                T[] array = api.rows(e).data().toArray();
                                if (array.length != 0) {
                                    columnAction.action(array[0]);
                                }
                            }
                        });
                    }
                });
            }
        }));
    }
}
Also used : Element(elemental2.dom.Element) RESET(org.jboss.hal.ballroom.table.RefreshMode.RESET) HTMLElement(elemental2.dom.HTMLElement) DrawCallback(org.jboss.hal.ballroom.table.Api.DrawCallback)

Aggregations

HTMLElement (elemental2.dom.HTMLElement)5 Test (org.junit.Test)5 Element (elemental2.dom.Element)4 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)3 HTMLDivElement (elemental2.dom.HTMLDivElement)3 HTMLIFrameElement (elemental2.dom.HTMLIFrameElement)2 HTMLInputElement (elemental2.dom.HTMLInputElement)2 HTMLLabelElement (elemental2.dom.HTMLLabelElement)2 KeyboardEvent (elemental2.dom.KeyboardEvent)2 Strings (com.google.common.base.Strings)1 SafeUri (com.google.gwt.safehtml.shared.SafeUri)1 UriUtils (com.google.gwt.safehtml.shared.UriUtils)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 DOMRect (elemental2.dom.DOMRect)1 DomGlobal.document (elemental2.dom.DomGlobal.document)1 Event (elemental2.dom.Event)1 HTMLHeadElement (elemental2.dom.HTMLHeadElement)1 HTMLLinkElement (elemental2.dom.HTMLLinkElement)1 HTMLScriptElement (elemental2.dom.HTMLScriptElement)1 HTMLUListElement (elemental2.dom.HTMLUListElement)1