ShadowRoot class
@DomName('ShadowRoot')
@SupportedBrowser(SupportedBrowser.CHROME, '26')
@Experimental
// https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#api-shadow-root
class ShadowRoot extends DocumentFragment native "ShadowRoot" {
@DomName('ShadowRoot.activeElement')
@DocsEditable
final Element activeElement;
@DomName('ShadowRoot.applyAuthorStyles')
@DocsEditable
bool applyAuthorStyles;
@JSName('innerHTML')
@DomName('ShadowRoot.innerHTML')
@DocsEditable
String innerHtml;
@DomName('ShadowRoot.resetStyleInheritance')
@DocsEditable
bool resetStyleInheritance;
@JSName('cloneNode')
@DomName('ShadowRoot.cloneNode')
@DocsEditable
Node clone(bool deep) native;
@DomName('ShadowRoot.elementFromPoint')
@DocsEditable
Element elementFromPoint(int x, int y) native;
@DomName('ShadowRoot.getElementById')
@DocsEditable
Element getElementById(String elementId) native;
@DomName('ShadowRoot.getElementsByClassName')
@DocsEditable
@Returns('NodeList')
@Creates('NodeList')
List<Node> getElementsByClassName(String className) native;
@DomName('ShadowRoot.getElementsByTagName')
@DocsEditable
@Returns('NodeList')
@Creates('NodeList')
List<Node> getElementsByTagName(String tagName) native;
@DomName('ShadowRoot.getSelection')
@DocsEditable
Selection getSelection() native;
static bool get supported =>
JS('bool', '!!(Element.prototype.webkitCreateShadowRoot)');
}
Extends
Interceptor > EventTarget > Node > DocumentFragment > ShadowRoot
Static Properties
Properties
List<Element> children #
List<Element> get children {
if (_children == null) {
_children = new FilteredElementList(this);
}
return _children;
}
void set children(List<Element> value) {
// Copy list first since we don't want liveness during iteration.
List copy = new List.from(value);
var children = this.children;
children.clear();
children.addAll(copy);
}
final int hashCode #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode it should override the
equality operator as well to maintain consistency.
int get hashCode => Primitives.objectHashCode(this);
List<Node> nodes #
List<Node> get nodes {
return new _ChildNodeListLazy(this);
}
void set nodes(Iterable<Node> value) {
// Copy list first since we don't want liveness during iteration.
// TODO(jacobr): there is a better way to do this.
List copy = new List.from(value);
text = '';
for (Node node in copy) {
append(node);
}
}
final Events on #
This is an ease-of-use accessor for event streams which should only be used when an explicit accessor is not available.
Events get on => new Events(this);
final Type runtimeType #
A representation of the runtime type of the object.
Type get runtimeType => getRuntimeType(this);
final TemplateInstance templateInstance #
Gets the template instance that instantiated this node, if any.
@Experimental TemplateInstance get templateInstance => _templateInstance != null ? _templateInstance : (parent != null ? parent.templateInstance : null);
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Objects is to return true if and
only if this and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
Methods
Node append(Node newChild) #
Adds a node to the end of the child nodes list of this node.
If the node already exists in this document, it will be removed from its current parent node, then added to this node.
This method is more efficient than nodes.add, and is the preferred
way of appending a child node.
@JSName('appendChild')
/**
* Adds a node to the end of the child [nodes] list of this node.
*
* If the node already exists in this document, it will be removed from its
* current parent node, then added to this node.
*
* This method is more efficient than `nodes.add`, and is the preferred
* way of appending a child node.
*/
@DomName('Node.appendChild')
@DocsEditable
Node append(Node newChild) native;
void appendHtml(String text) #
Parses the specified text as HTML and adds the resulting node after the last child of this document fragment.
void appendHtml(String text) {
this.append(new DocumentFragment.html(text));
}
void appendText(String text) #
Adds the specified text as a text node after the last child of this document fragment.
void appendText(String text) {
this.append(new Text(text));
}
void bind(String name, model, String path) #
Binds the attribute
name to the
path of the
model.
Path is a String of accessors such as foo.bar.baz.
@Experimental
void bind(String name, model, String path) {
// TODO(jmesserly): should we throw instead?
window.console.error('Unhandled binding to Node: '
'$this $name $model $path');
}
Node clone(bool deep) #
@JSName('cloneNode')
@DomName('ShadowRoot.cloneNode')
@DocsEditable
Node clone(bool deep) native;
bool contains(Node other) #
@DomName('Node.contains')
@DocsEditable
bool contains(Node other) native;
bool dispatchEvent(Event event) #
@DomName('Node.dispatchEvent')
@DocsEditable
bool dispatchEvent(Event event) native;
Element elementFromPoint(int x, int y) #
@DomName('ShadowRoot.elementFromPoint')
@DocsEditable
Element elementFromPoint(int x, int y) native;
Element getElementById(String elementId) #
@DomName('ShadowRoot.getElementById')
@DocsEditable
Element getElementById(String elementId) native;
List<Node> getElementsByClassName(String className) #
@DomName('ShadowRoot.getElementsByClassName')
@DocsEditable
@Returns('NodeList')
@Creates('NodeList')
List<Node> getElementsByClassName(String className) native;
List<Node> getElementsByTagName(String tagName) #
@DomName('ShadowRoot.getElementsByTagName')
@DocsEditable
@Returns('NodeList')
@Creates('NodeList')
List<Node> getElementsByTagName(String tagName) native;
Selection getSelection() #
@DomName('ShadowRoot.getSelection')
@DocsEditable
Selection getSelection() native;
bool hasChildNodes() #
@DomName('Node.hasChildNodes')
@DocsEditable
bool hasChildNodes() native;
Node insertAllBefore(Iterable<Node> newNodes, Node refChild) #
Inserts all of the nodes into this node directly before refChild.
See also:
insertBefore
Node insertAllBefore(Iterable<Node> newNodes, Node refChild) {
if (newNodes is _ChildNodeListLazy) {
_ChildNodeListLazy otherList = newNodes;
if (identical(otherList._this, this)) {
throw new ArgumentError(newNodes);
}
// Optimized route for copying between nodes.
for (var i = 0, len = otherList.length; i < len; ++i) {
// Should use $dom_firstChild, Bug 8886.
this.insertBefore(otherList[0], refChild);
}
} else {
for (var node in newNodes) {
this.insertBefore(node, refChild);
}
}
}
Node insertBefore(Node newChild, Node refChild) #
@DomName('Node.insertBefore')
@DocsEditable
Node insertBefore(Node newChild, Node refChild) native;
dynamic noSuchMethod(Invocation invocation) #
noSuchMethod is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod in an Invocation.
If noSuchMethod returns a value, that value becomes the result of
the original invocation.
The default behavior of noSuchMethod is to throw a
noSuchMethodError.
dynamic noSuchMethod(Invocation invocation) {
throw new NoSuchMethodError(
this,
_symbolToString(invocation.memberName),
invocation.positionalArguments,
_symbolMapToStringMap(invocation.namedArguments));
}
Element query(String selectors) #
Element query(String selectors) => $dom_querySelector(selectors);
List<Element> queryAll(String selectors) #
List<Element> queryAll(String selectors) => new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
void remove() #
Removes this node from the DOM.
@DomName('Node.removeChild')
void remove() {
// TODO(jacobr): should we throw an exception if parent is already null?
// TODO(vsm): Use the native remove when available.
if (this.parentNode != null) {
final Node parent = this.parentNode;
parentNode.$dom_removeChild(this);
}
}
Node replaceWith(Node otherNode) #
Replaces this node with another node.
@DomName('Node.replaceChild')
Node replaceWith(Node otherNode) {
try {
final Node parent = this.parentNode;
parent.$dom_replaceChild(otherNode, this);
} catch (e) {
};
return this;
}
String toString() #
Print out a String representation of this Node.
String toString() => nodeValue == null ? super.toString() : nodeValue;
void unbind(String name) #
Unbinds the attribute name.
@Experimental
void unbind(String name) {}
void unbindAll() #
Unbinds all bound attributes.
@Experimental
void unbindAll() {}
void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) #
@JSName('addEventListener')
@DomName('Node.addEventListener')
@DocsEditable
void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) native;
Element $dom_querySelector(String selectors) #
@JSName('querySelector')
@DomName('DocumentFragment.querySelector')
@DocsEditable
Element $dom_querySelector(String selectors) native;
List<Node> $dom_querySelectorAll(String selectors) #
@JSName('querySelectorAll')
@DomName('DocumentFragment.querySelectorAll')
@DocsEditable
@Returns('NodeList')
@Creates('NodeList')
List<Node> $dom_querySelectorAll(String selectors) native;
Node $dom_removeChild(Node oldChild) #
@JSName('removeChild')
@DomName('Node.removeChild')
@DocsEditable
Node $dom_removeChild(Node oldChild) native;
void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #
@JSName('removeEventListener')
@DomName('Node.removeEventListener')
@DocsEditable
void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) native;