goog.dom.TagIterator
Classgoog.dom.TagIterator
> goog.iter.Iterator
goog.dom.TagIterator(opt_node, opt_reversed, opt_unconstrained, opt_tagType, opt_depth)
A DOM tree traversal iterator. Starting with the given node, the iterator walks the DOM in order, reporting events for the start and end of Elements, and the presence of text nodes. For example:
<div>1<span>2</span>3</div>Will return the following nodes:
[div, 1, span, 2, span, 3, div]
With the following states:
[START, OTHER, START, OTHER, END, OTHER, END]
And the following depths
[1, 1, 2, 2, 1, 1, 0]
Imagining |
represents iterator position, the traversal stops at
each of the following locations:
<div>|1|<span>|2|</span>|3|</div>|The iterator can also be used in reverse mode, which will return the nodes and states in the opposite order. The depths will be slightly different since, like in normal mode, the depth is computed *after* the given node. Lastly, it is possible to create an iterator that is unconstrained, meaning that it will continue iterating until the end of the document instead of until exiting the start node.
opt_node
{Node
=}
opt_reversed
{boolean
=}
opt_unconstrained
{boolean
=}
opt_tagType
{goog.dom.TagWalkType
?=}
opt_depth
{number
=}
.__iterator__(opt_keys)
Inherited from goog.iter.Iterator
.
Returns the {@code Iterator} object itself. This is used to implement the iterator protocol in JavaScript 1.7
opt_keys
{boolean
=}
goog.iter.Iterator
}
.clone()
goog.dom.TagIterator
}
.constrained
{boolean
}Whether the iterator is constrained to the starting node and its children.
.copyFrom(other)
[protected]Replace this iterator's values with values from another. The two iterators must be of the same type.
other
{goog.dom.TagIterator
}
.depth
{number
}The tree depth of this position relative to where the iterator started. The depth is considered to be the tree depth just past the current node, so if an iterator is at position
(i.e. the node is the div and the type is START_TAG) its depth will be 1.|
.equals(other)
Test if two iterators are at the same position - i.e. if the node and tagType is the same. This will still return true if the two iterators are moving in opposite directions or have different constraints.
other
{goog.dom.TagIterator
}
boolean
}
.isEndTag()
boolean
}
.isNonElement()
boolean
}
.isStartTag()
boolean
}
.isStarted()
[protected]boolean
}
.next()
Move to the next position in the DOM tree.
Node
}
.node
{Node
}The node this position is located on.
.restartTag()
Restart the current tag.
.reversed
{boolean
}Whether the node iterator is moving in reverse.
.setPosition(node, opt_tagType, opt_depth)
Set the position of the iterator. Overwrite the tree node and the position type which can be one of the {@link goog.dom.TagWalkType} token types. Only overwrites the tree depth when the parameter is specified.
node
{Node
}
opt_tagType
{goog.dom.TagWalkType
?=}
opt_depth
{number
=}
.skipTag()
Skip the current tag.
.splice(var_args)
Replace the current node with the list of nodes. Reset the iterator so that it visits the first of the nodes next.
var_args
{...Object
}
.tagType
{goog.dom.TagWalkType
}The type of this position.