com.google.gwt.dom.client.Element.hasAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.google.gwt.dom.client.Element.hasAttribute()方法的一些代码示例,展示了Element.hasAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.hasAttribute()方法的具体详情如下:
包路径:com.google.gwt.dom.client.Element
类名称:Element
方法名:hasAttribute

Element.hasAttribute介绍

[英]Determines whether an element has an attribute with a given name.

Note that IE, prior to version 8, will return false-positives for names that collide with element properties (e.g., style, width, and so forth).
[中]确定元素是否具有具有给定名称的属性。
请注意,对于与元素属性(例如样式、宽度等)冲突的名称,IE在版本8之前将返回误报。

代码示例

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Retrieves the root of a previously rendered element contained within the {@code parent}.
 * The {@code parent} must either contain the previously rendered DOM structure as its only child,
 * or point directly to the rendered element root.
 * 
 * @param parent element containing, or pointing to, a previously rendered DOM structure
 * @param attribute attribute name that identifies the root of the DOM structure
 * @return the root element of the previously rendered DOM structure or <code>null</code>
 *         if {@code parent} does not contain a previously rendered element
 * 
 * @throws NullPointerException if {@code parent} == null
 */
private static Element findRootElementOrNull(Element parent, String attribute) {
 if (parent == null) {
  throw new NullPointerException("parent argument is null");
 }
 Element rendered;
 if (parent.hasAttribute(attribute)) {
  // The parent is the root
  return parent;
 } else if ((rendered = parent.getFirstChildElement()) != null
   && rendered.hasAttribute(attribute)) {
  // The first child is the root
  return rendered;
 } else {
  return null;
 }
}

代码示例来源:origin: org.jboss.errai/errai-ui

@Override
public boolean hasAttribute(String name) {
 return element.hasAttribute(name);
}

代码示例来源:origin: errai/errai

@Override
public boolean hasAttribute(String name) {
 return element.hasAttribute(name);
}

代码示例来源:origin: org.vectomatic/lib-gwt-svg

/**
 * Determines whether an element has an attribute with a given name.
 * <p>
 * Note that IE, prior to version 8, will return false-positives for names
 * that collide with element properties (e.g., style, width, and so forth).
 * </p>
 * 
 * @param name
 * the name of the attribute
 * @return <code>true</code> if this element has the specified attribute
 */
public final boolean hasAttribute(String name) {
  return ((Element) ot).hasAttribute(name);
}

代码示例来源:origin: com.allen-sauer.gwt.voices/gwt-voices

public boolean getLooping(Element element) {
 return element.hasAttribute("loop");
}

代码示例来源:origin: laaglu/lib-gwt-svg

/**
 * Determines whether an element has an attribute with a given name.
 * <p>
 * Note that IE, prior to version 8, will return false-positives for names
 * that collide with element properties (e.g., style, width, and so forth).
 * </p>
 * 
 * @param name
 * the name of the attribute
 * @return <code>true</code> if this element has the specified attribute
 */
public final boolean hasAttribute(String name) {
  return ((Element) ot).hasAttribute(name);
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-vaadin-common-widgets

/**
 * Returns whether the currently focused element is one that accepts keyboard input.
 */
protected boolean isFocusedElementAnInputField() {
  final Element focused = WidgetUtil.getFocusedElement();
  String tagName = focused.getTagName();
  if ("input".equalsIgnoreCase(tagName) || "select".equalsIgnoreCase(tagName) || "textarea".equalsIgnoreCase(tagName)) {
    return true;
  }
  Element el = focused;
  boolean isContentEditable = false;
  final String contenteditableAttrName = "contenteditable";
  while (!isContentEditable && el != null) {
    // the element would be inline-editable if there is a "contenteditable" attr present and its value is not explicitly "false" (no value is equivalent to "true")
    isContentEditable = el.hasAttribute(contenteditableAttrName) && !el.getAttribute(contenteditableAttrName).equalsIgnoreCase("false");
    el = el.getParentElement();
  }
  return isContentEditable;
}

代码示例来源:origin: org.jboss.errai/errai-ui

@Override
 public boolean visit(final VisitContextMutable<TaggedElement> context, final Element element) {
  for (final AttributeType attrType : AttributeType.values()) {
   final String attrName = attrType.getAttributeName();
   final TaggedElement existingCandidate = context.getResult();
   if (element.hasAttribute(attrName) && element.getAttribute(attrName).equals(rootField)
     && (existingCandidate == null || existingCandidate.getAttributeType().ordinal() < attrType.ordinal())) {
    context.setResult(new TaggedElement(attrType, element));
   }
  }
  return true;
 }
});

代码示例来源:origin: errai/errai

@Override
 public boolean visit(final VisitContextMutable<TaggedElement> context, final Element element) {
  for (final AttributeType attrType : AttributeType.values()) {
   final String attrName = attrType.getAttributeName();
   final TaggedElement existingCandidate = context.getResult();
   if (element.hasAttribute(attrName) && element.getAttribute(attrName).equals(rootField)
     && (existingCandidate == null || existingCandidate.getAttributeType().ordinal() < attrType.ordinal())) {
    context.setResult(new TaggedElement(attrType, element));
   }
  }
  return true;
 }
});

代码示例来源:origin: GwtMaterialDesign/gwt-material

public void testEnabled() {
  // given
  MaterialListValueBox<T> listValueBox = getWidget();
  // when / then
  final Element element = listValueBox.getListBox().getElement();
  assertFalse(element.hasAttribute(CssName.DISABLED));
  listValueBox.setEnabled(true);
  assertFalse(element.hasAttribute(CssName.DISABLED));
  assertTrue(listValueBox.isEnabled());
  listValueBox.setEnabled(false);
  assertTrue(element.hasAttribute(CssName.DISABLED));
  assertFalse(listValueBox.getListBox().isEnabled());
}

代码示例来源:origin: com.github.gwtmaterialdesign/gwt-material

public void testEnabled() {
  // given
  MaterialListValueBox<T> listValueBox = getWidget();
  // when / then
  final Element element = listValueBox.getListBox().getElement();
  assertFalse(element.hasAttribute(CssName.DISABLED));
  listValueBox.setEnabled(true);
  assertFalse(element.hasAttribute(CssName.DISABLED));
  assertTrue(listValueBox.isEnabled());
  listValueBox.setEnabled(false);
  assertTrue(element.hasAttribute(CssName.DISABLED));
  assertFalse(listValueBox.getListBox().isEnabled());
}

代码示例来源:origin: GwtMaterialDesign/gwt-material

protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target, boolean checkElement) {
  final Element element = target.getElement();
  if(checkElement) {
    assertFalse(element.hasClassName(CssName.DISABLED));
    assertFalse(element.hasAttribute(CssName.DISABLED));
  }
  widget.setEnabled(true);
  if(checkElement) {
    assertFalse(element.hasClassName(CssName.DISABLED));
    assertFalse(element.hasAttribute(CssName.DISABLED));
  }
  assertEquals(widget.isEnabled(), true);
  widget.setEnabled(false);
  if(checkElement) {
    assertTrue(element.hasClassName(CssName.DISABLED));
    assertTrue(element.hasAttribute(CssName.DISABLED));
  }
  assertEquals(target.isEnabled(), false);
}

代码示例来源:origin: com.github.gwtmaterialdesign/gwt-material

protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target, boolean checkElement) {
  final Element element = target.getElement();
  if(checkElement) {
    assertFalse(element.hasClassName(CssName.DISABLED));
    assertFalse(element.hasAttribute(CssName.DISABLED));
  }
  widget.setEnabled(true);
  if(checkElement) {
    assertFalse(element.hasClassName(CssName.DISABLED));
    assertFalse(element.hasAttribute(CssName.DISABLED));
  }
  assertEquals(widget.isEnabled(), true);
  widget.setEnabled(false);
  if(checkElement) {
    assertTrue(element.hasClassName(CssName.DISABLED));
    assertTrue(element.hasAttribute(CssName.DISABLED));
  }
  assertEquals(target.isEnabled(), false);
}

代码示例来源:origin: GwtMaterialDesign/gwt-material

public void testActivates() {
  // UiBinder
  // given
  T widget = getWidget(false);
  // when / then
  widget.setActivates("test");
  assertEquals("test", widget.getActivates());
  // Standard
  // given
  attachWidget();
  // when / then
  final Element element = widget.getElement();
  widget.setActivates("test");
  assertTrue(element.hasAttribute("data-activates"));
  assertEquals("test", element.getAttribute("data-activates"));
}

代码示例来源:origin: SwellRT/swellrt

public void testAttributesReflectedOnlyInContent() {
 ContentDocument dom = TestEditors.createTestDocument();
 c = dom.debugGetRawDocument();
 ContentElement e = c.createElement("a", c.getDocumentElement(), null);
 assertEquals(0, c.getAttributes(e).size());
 c.setAttribute(e, "href", "blah");
 c.setAttribute(e, "x", "y");
 c.setAttribute(e, "aa", "bb");
 assertEquals("bb", c.getAttribute(e, "aa"));
 assertSame(null, c.getAttribute(e, "notthere"));
 assertEquals(3, c.getAttributes(e).size());
 for (String key : c.getAttributes(e).keySet()) {
  assertTrue(!e.getImplNodelet().hasAttribute(key));
 }
 c.setAttribute(e, "x", "abc");
 c.removeAttribute(e, "aa");
 assertEquals("abc", c.getAttribute(e, "x"));
 assertSame(null, c.getAttribute(e, "aa"));
 assertEquals(2, c.getAttributes(e).size());
}

代码示例来源:origin: com.github.gwtmaterialdesign/gwt-material

public void testActivates() {
  // UiBinder
  // given
  T widget = getWidget(false);
  // when / then
  widget.setActivates("test");
  assertEquals("test", widget.getActivates());
  // Standard
  // given
  attachWidget();
  // when / then
  final Element element = widget.getElement();
  widget.setActivates("test");
  assertTrue(element.hasAttribute("data-activates"));
  assertEquals("test", element.getAttribute("data-activates"));
}

代码示例来源:origin: com.github.gwtmaterialdesign/gwt-material

public void testId() {
  // UiBinder
  // given
  T widget = getWidget(false);
  // when / then
  widget.setId("test");
  assertNotNull(widget.getId());
  // Standard
  // given
  attachWidget();
  // when / then
  final Element element = widget.getElement();
  widget.setId("test");
  assertTrue(element.hasAttribute("id"));
  assertEquals(widget.getId(), element.getId());
}

代码示例来源:origin: GwtMaterialDesign/gwt-material

@Override
public void testId() {
  // UiBinder
  // given
  T widget = getWidget(false);
  // when / then
  widget.setId(ACTIVATES);
  assertNotNull(widget.getId());
  // Standard
  // given
  attachWidget();
  // when / then
  final Element element = widget.getElement();
  widget.setId(ACTIVATES);
  assertTrue(element.hasAttribute("id"));
  assertEquals(widget.getId(), element.getId());
}

代码示例来源:origin: GwtMaterialDesign/gwt-material

public void testId() {
  // UiBinder
  // given
  T widget = getWidget(false);
  // when / then
  widget.setId("test");
  assertNotNull(widget.getId());
  // Standard
  // given
  attachWidget();
  // when / then
  final Element element = widget.getElement();
  widget.setId("test");
  assertTrue(element.hasAttribute("id"));
  assertEquals(widget.getId(), element.getId());
}

代码示例来源:origin: com.github.gwtmaterialdesign/gwt-material

@Override
public void testId() {
  // UiBinder
  // given
  T widget = getWidget(false);
  // when / then
  widget.setId(ACTIVATES);
  assertNotNull(widget.getId());
  // Standard
  // given
  attachWidget();
  // when / then
  final Element element = widget.getElement();
  widget.setId(ACTIVATES);
  assertTrue(element.hasAttribute("id"));
  assertEquals(widget.getId(), element.getId());
}

相关文章

微信公众号

最新文章

更多

Element类方法