本文整理汇总了Java中com.google.gwt.dom.client.NodeList类的典型用法代码示例。如果您正苦于以下问题:Java NodeList类的具体用法?Java NodeList怎么用?Java NodeList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NodeList类属于com.google.gwt.dom.client包,在下文中一共展示了NodeList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementsByClassName
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
/**
* Gets a list of descendants of e that match the given class name.
*
* If the browser has the native method, that will be called. Otherwise, it
* traverses descendents of the given element and returns the list of elements
* with matching classname.
*
* @param e
* @param className
*/
public static NodeList<Element> getElementsByClassName(Element e, String className) {
if (QuirksConstants.SUPPORTS_GET_ELEMENTS_BY_CLASSNAME) {
return getElementsByClassNameNative(e, className);
} else {
NodeList<Element> all = e.getElementsByTagName("*");
if (all == null) {
return null;
}
JsArray<Element> ret = JavaScriptObject.createArray().cast();
for (int i = 0; i < all.getLength(); ++i) {
Element item = all.getItem(i);
if (className.equals(item.getClassName())) {
ret.push(item);
}
}
return ret.cast();
}
}
示例2: getInputElement
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private static Element getInputElement(NodeList<Node> nodes, int i, boolean shiftKeyDown) {
Node node = nodes.getItem(i);
if (((Element) node).getPropertyBoolean("disabled")) {
return null;
}
// Focus on <input> and <button> but only if they are visible.
if ((node.getNodeName().equals("INPUT")
|| node.getNodeName().equals("BUTTON")
|| node.getNodeName().equals("SELECT"))
&& !((Element) node).getStyle()
.getDisplay()
.equals("none")) {
return (Element) node;
} else if (node.getChildNodes()
.getLength() > 0) {
return getInputElement(node.getChildNodes(), shiftKeyDown);
}
return null;
}
示例3: onModuleLoad
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
public void onModuleLoad() {
// GWT.setUncaughtExceptionHandler(new ClientExceptionHandler());
NodeList nl = Document.get().getElementsByTagName("style");
final ArrayList<String> toLoad = new ArrayList<String>();
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.getItem(i);
if ("text/gss".equals(e.getAttribute("type"))) {
GWT.log("Style = " + e.getInnerText(), null);
}
}
Chronoscope.setMicroformatsEnabled(true);
ChronoscopeOptions.setErrorReporting(true);
Chronoscope.getInstance();
}
示例4: tuneSplitters
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
/** Makes splitter better. */
public void tuneSplitters() {
NodeList<Node> nodes = splitPanel.getElement().getChildNodes();
boolean firstFound = false;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.getItem(i);
if (node.hasChildNodes()) {
com.google.gwt.dom.client.Element el = node.getFirstChild().cast();
if ("gwt-SplitLayoutPanel-HDragger".equals(el.getClassName())) {
if (!firstFound) {
firstFound = true;
tuneLeftSplitter(el);
} else {
tuneRightSplitter(el);
}
} else if ("gwt-SplitLayoutPanel-VDragger".equals(el.getClassName())) {
tuneBottomSplitter(el);
}
}
}
}
示例5: tuneSplitter
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
/** Improves splitter visibility. */
private void tuneSplitter(SplitLayoutPanel splitLayoutPanel) {
NodeList<Node> nodes = splitLayoutPanel.getElement().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.getItem(i);
if (node.hasChildNodes()) {
Element el = node.getFirstChild().cast();
String className = el.getClassName();
if (HORIZONTAL_DRAGGER_CLASS.equals(className)) {
tuneVerticalSplitter(el);
} else if (VERTICAL_DRAGGER_CLASS.equals(className)) {
tuneHorizontalSplitter(el);
}
}
}
}
示例6: getArticleElement
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
/**
* Get the element of the main article, if any.
* @return An element of article (not necessarily the html5 article element).
*/
public static Element getArticleElement(Element root) {
NodeList<Element> allArticles = root.getElementsByTagName("ARTICLE");
List<Element> visibleElements = getVisibleElements(allArticles);
// Having multiple article elements usually indicates a bad case for this shortcut.
// TODO(wychen): some sites exclude things like title and author in article element.
if (visibleElements.size() == 1) {
return visibleElements.get(0);
}
// Note that the CSS property matching is case sensitive, and "Article" is the correct
// capitalization.
String query = "[itemscope][itemtype*=\"Article\"],[itemscope][itemtype*=\"Posting\"]";
allArticles = DomUtil.querySelectorAll(root, query);
visibleElements = getVisibleElements(allArticles);
// It is commonly seen that the article is wrapped separately or in multiple layers.
if (visibleElements.size() > 0) {
return Element.as(DomUtil.getNearestCommonAncestor(visibleElements));
}
return null;
}
示例7: getImageUrlList
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
/**
* Get the list of source URLs of this image.
* It's more efficient to call after generateOutput().
* @return Source URLs or an empty List.
*/
public List<String> getImageUrlList() {
if (cloned == null) {
cloneAndProcessNode();
}
List<String> imgUrls = new ArrayList<>();
NodeList<Element> imgs = DomUtil.querySelectorAll(cloned, "IMG, SOURCE");
for (int i = 0; i < imgs.getLength(); i++) {
ImageElement ie = (ImageElement) imgs.getItem(i);
if (!ie.getSrc().isEmpty()) {
imgUrls.add(ie.getSrc());
}
imgUrls.addAll(DomUtil.getAllSrcSetUrls(ie));
}
return imgUrls;
}
示例8: getDirectDescendants
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private static List<Element> getDirectDescendants(Element t) {
List<Element> directDescendants = new ArrayList<Element>();
NodeList<Element> allDescendants = t.getElementsByTagName("*");
if (!hasNestedTables(t)) {
for (int i = 0; i < allDescendants.getLength(); i++) {
directDescendants.add(allDescendants.getItem(i));
}
} else {
for (int i = 0; i < allDescendants.getLength(); i++) {
// Check if the current element is a direct descendant of the |t| table element in
// question, as opposed to being a descendant of a nested table in |t|.
Element e = allDescendants.getItem(i);
Element parent = e.getParentElement();
while (parent != null) {
if (parent.hasTagName("TABLE")) {
if (parent == t) directDescendants.add(e);
break;
}
parent = parent.getParentElement();
}
}
}
return directDescendants;
}
示例9: findTitle
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private void findTitle() {
init();
mTitle = "";
if (mAllMeta.getLength() == 0) return;
// Make sure there's a <title> element.
NodeList<Element> titles = mRoot.getElementsByTagName("TITLE");
if (titles.getLength() == 0) return;
// Extract title text from meta tag with "title" as name.
for (int i = 0; i < mAllMeta.getLength(); i++) {
MetaElement meta = MetaElement.as(mAllMeta.getItem(i));
if (meta.getName().equalsIgnoreCase("title")) {
mTitle = meta.getContent();
break;
}
}
}
示例10: findImages
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private void findImages() {
mImages = new ArrayList<MarkupParser.Image>();
NodeList<Element> allImages = mRoot.getElementsByTagName("IMG");
for (int i = 0; i < allImages.getLength(); i++) {
ImageElement imgElem = ImageElement.as(allImages.getItem(i));
// As long as the image has a caption, it's relevant regardless of size;
// otherwise, it's relevant if its size is good.
String caption = getCaption(imgElem);
if ((caption != null && !caption.isEmpty()) || isImageRelevantBySize(imgElem)) {
// Add relevant image to list.
MarkupParser.Image image = new MarkupParser.Image();
image.url = imgElem.getSrc();
image.caption = caption;
image.width = imgElem.getWidth();
image.height = imgElem.getHeight();
mImages.add(image);
}
}
}
示例11: getCaption
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private static String getCaption(ImageElement image) {
// If |image| is a child of <figure>, then get the <figcaption> elements.
Element parent = image.getParentElement();
if (!parent.hasTagName("FIGURE")) return "";
NodeList<Element> captions = parent.getElementsByTagName("FIGCAPTION");
int numCaptions = captions.getLength();
String caption = "";
if (numCaptions > 0 && numCaptions <= 2) {
// Use javascript innerText (instead of javascript textContent) to get only visible
// captions.
for (int i = 0; i < numCaptions && caption.isEmpty(); i++) {
caption = DomUtil.getInnerText(captions.getItem(i));
}
}
return caption;
}
示例12: testNearestCommonAncestor
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
/**
* The tree graph is:
* 1 - 2 - 3
* \ 4 - 5
*/
public void testNearestCommonAncestor() {
Element div = TestUtil.createDiv(1);
mBody.appendChild(div);
Element div2 = TestUtil.createDiv(2);
div.appendChild(div2);
Element currDiv = TestUtil.createDiv(3);
div2.appendChild(currDiv);
Element finalDiv1 = currDiv;
currDiv = TestUtil.createDiv(4);
div2.appendChild(currDiv);
currDiv.appendChild(TestUtil.createDiv(5));
assertEquals(div2, DomUtil.getNearestCommonAncestor(finalDiv1, currDiv.getChild(0)));
NodeList nodeList = DomUtil.querySelectorAll(mRoot, "[id=\"3\"],[id=\"5\"]");
assertEquals(div2, DomUtil.getNearestCommonAncestor(TestUtil.nodeListToList(nodeList)));
}
示例13: gwtSetUp
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
protected void gwtSetUp() throws Exception {
mRoot = Document.get().getDocumentElement();
JsArray<Node> attrs = DomUtil.getAttributes(mRoot);
String[] attrNames = new String[attrs.length()];
for (int i = 0; i < attrs.length(); i++) {
attrNames[i] = attrs.get(i).getNodeName();
}
for (int i = 0; i < attrNames.length; i++) {
mRoot.removeAttribute(attrNames[i]);
}
assertEquals(0, DomUtil.getAttributes(mRoot).length());
NodeList<Node> children = mRoot.getChildNodes();
for (int i = children.getLength() - 1; i >= 0; i--) {
children.getItem(i).removeFromParent();
}
assertEquals(0, mRoot.getChildNodes().getLength());
mHead = Document.get().createElement("head");
mRoot.appendChild(mHead);
mBody = Document.get().createElement("body");
mRoot.appendChild(mBody);
// With this, the width of chrome window won't affect the layout.
mRoot.getStyle().setProperty("width", "800px");
}
示例14: onOpenRow
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private void onOpenRow(Element row) {
// Find the first HREF of the anchor of the select row (if any)
if (row != null) {
NodeList<Element> nodes = row.getElementsByTagName(AnchorElement.TAG);
for (int i = 0; i < nodes.getLength(); i++) {
String url = nodes.getItem(i).getAttribute("href");
if (!url.isEmpty()) {
if (url.startsWith("#")) {
Gerrit.display(url.substring(1));
} else {
Window.Location.assign(url);
}
break;
}
}
}
saveSelectedTab();
}
示例15: menuVisible
import com.google.gwt.dom.client.NodeList; //导入依赖的package包/类
private static boolean menuVisible(Element searchFrom,
String label) {
System.out.println("Looking for an <li> with text " + label);
NodeList<com.google.gwt.dom.client.Element> liElems = searchFrom.getElementsByTagName("li");
for (int i = 0, n = liElems.getLength(); i < n; i++) {
com.google.gwt.dom.client.Element item = liElems.getItem(i);
if (item.getInnerText().contains(label)) {
System.out.println("Found: " + item);
return true;
} else {
System.out.println("Not this one!");
}
}
System.out.println("Not Found!");
return false;
}