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;
}
}
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);
}
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]);
}
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);
});
}
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]);
}
}
});
}
});
}
}));
}
}
Aggregations