Index: sdk/lib/html/dart2js/html_dart2js.dart |
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart |
index fb99370992317fb8e5a7caccdc4aa3514f28f4ff..b5ff67af6a685df1e207dbd39c441cb117289432 100644 |
--- a/sdk/lib/html/dart2js/html_dart2js.dart |
+++ b/sdk/lib/html/dart2js/html_dart2js.dart |
@@ -7351,17 +7351,54 @@ class _ElementCssClassSet extends CssClassSet { |
} |
} |
-/// @domName Element |
+/** |
+ * An abstract class which all HTML elements extend. |
+ */ |
abstract class Element extends Node implements ElementTraversal native "*Element" { |
+ /** |
+ * Creates an HTML element from a valid fragment of HTML. |
+ * |
+ * The [html] fragment must represent valid HTML with a single element root, |
+ * which will be parsed and returned. |
+ * |
+ * Important: the contents of [html] should not contain any user-supplied |
+ * data. Without strict data validation it is impossible to prevent script |
+ * injection exploits. |
+ * |
+ * It is instead recommended that elements be constructed via [Element.tag] |
+ * and text be added via [text]. |
+ * |
+ * var element = new Element.html('<div class="foo">content</div>'); |
+ */ |
factory Element.html(String html) => |
_ElementFactoryProvider.createElement_html(html); |
+ |
+ /** |
+ * Creates the HTML element specified by the tag name. |
+ * |
+ * This is similar to [Document.createElement]. |
+ * [tag] should be a valid HTML tag name. If [tag] is an unknown tag then |
+ * this will create an [UnknownElement]. |
+ * var divElement = new Element.tag('div'); |
+ * print(divElement is DivElement); // 'true' |
+ * var myElement = new Element.tag('unknownTag'); |
+ * print(myElement is UnknownElement); // 'true' |
+ * For standard elements it is more preferable to use the type constructors: |
+ * var element = new DivElement(); |
+ */ |
factory Element.tag(String tag) => |
_ElementFactoryProvider.createElement_tag(tag); |
/** |
- * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute, |
- * Element.removeAttribute |
+ * All attributes on this element. |
+ * |
+ * Any modifications to the attribute map will automatically be applied to |
+ * this element. |
+ * |
+ * This only includes attributes which are not in a namespace |
+ * (such as xlink:href), additional attributes can be accessed via |
+ * [getNamespacedAttributes]. |
*/ |
Map<String, String> get attributes => new _ElementAttributeMap(this); |
@@ -7395,8 +7432,15 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
List<Element> get elements => this.children; |
/** |
- * @domName childElementCount, firstElementChild, lastElementChild, |
- * children, Node.nodes.add |
+ * List of the direct children of this element. |
+ * |
+ * This collection can be used to add and remove elements from the document. |
+ * var item = new DivElement(); |
+ * item.text = 'Something'; |
+ * document.body.children.add(item) // Item is now displayed on the page. |
+ * for (var element in document.body.children) { |
+ * element.style.background = 'red'; // Turns every child of body red. |
+ * } |
*/ |
List<Element> get children => new _ChildrenElementList._wrap(this); |
@@ -7408,12 +7452,43 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
children.addAll(copy); |
} |
+ /** |
+ * Finds the first descendant element of this element that matches the |
+ * specified group of selectors. |
+ * |
+ * [selectors] should be a string using CSS selector syntax. |
+ * Get the first descendant with the class 'classname': |
+ * var element = element.query('.className'); |
+ * Get the element with id 'id': |
+ * var element = element.query('#id'); |
+ * Get the first descendant [ImageElement]: |
+ * var img = element.query('img'); |
+ * |
+ * See also: |
+ * |
+ * * [CSS Selectors](http://docs.webplatform.org/wiki/css/selectors) |
+ */ |
Element query(String selectors) => $dom_querySelector(selectors); |
+ /** |
+ * Finds all descendent elements of this element that match the specified |
+ * group of selectors. |
+ * |
+ * [selectors] should be a string using CSS selector syntax. |
+ * var items = element.query('.itemClassName'); |
+ */ |
List<Element> queryAll(String selectors) => |
new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); |
- /** @domName className, classList */ |
+ /** |
+ * The set of CSS classes applied to this element. |
+ * |
+ * This set makes it easy to add, remove or toggle the classes applied to |
+ * this element. |
+ * element.classes.add('selected'); |
+ * element.classes.toggle('isOnline'); |
+ * element.classes.remove('selected'); |
+ */ |
CssClassSet get classes => new _ElementCssClassSet(this); |
void set classes(Collection<String> value) { |
@@ -7422,6 +7497,25 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
classSet.addAll(value); |
} |
+ /** |
+ * Allows access to all custom data attributes (data-*) set on this element. |
+ * |
+ * The keys for the map must follow these rules: |
+ * |
+ * * The name must not begin with `xml`. |
+ * * The name cannot contain a semi-colon (`;`). |
+ * * The name cannot contain any capital letters. |
+ * |
+ * Any keys from markup will be converted to camel-cased keys in the map. |
+ * For example, HTML specified as: |
+ * <div data-my-random-value='value'></div>div |
Kathy Walrath
2012/12/12 19:16:06
</div>div -> </div>
?
blois
2012/12/12 19:46:29
Done.
|
+ * Would be accessed in Dart as: |
+ * var value = element.dataAttributes['myRandomValue']; |
+ * |
+ * See also: |
+ * |
+ * * [Custom data attributes](http://www.w3.org/TR/html5/global-attributes.html#custom-data-attribute) |
+ */ |
Map<String, String> get dataAttributes => |
new _DataAttributeMap(attributes); |
@@ -7435,19 +7529,39 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
/** |
* Gets a map for manipulating the attributes of a particular namespace. |
+ * |
* This is primarily useful for SVG attributes such as xref:link. |
*/ |
Map<String, String> getNamespacedAttributes(String namespace) { |
return new _NamespacedAttributeMap(this, namespace); |
} |
- /** @domName Window.getComputedStyle */ |
+ /** |
+ * The set of all CSS values applied to this element, including inherited |
+ * and default values. |
+ * |
+ * The computedStyle contains the values which are inherited from other |
Kathy Walrath
2012/12/12 19:16:06
which -> that
the values -> values?
blois
2012/12/12 19:46:29
Done.
|
+ * sources, such as parent elements or stylesheets. This differs from the |
+ * [style] property which contains the values specified directly on this |
Kathy Walrath
2012/12/12 19:16:06
which -> , which
(in general, you should either h
blois
2012/12/12 19:46:29
Done.
|
+ * element, |
Kathy Walrath
2012/12/12 19:16:06
element, -> element.
(period)
blois
2012/12/12 19:46:29
Done.
blois
2012/12/12 19:46:29
Done.
|
+ * |
+ * See also: |
+ * |
+ * * [CSS Inheritance and Cascade](http://docs.webplatform.org/wiki/tutorials/inheritance_and_cascade) |
+ */ |
Future<CssStyleDeclaration> get computedStyle { |
// TODO(jacobr): last param should be null, see b/5045788 |
return getComputedStyle(''); |
} |
- /** @domName Window.getComputedStyle */ |
+ /** |
+ * This returns the computed styles for pseudo-elements such as |
Kathy Walrath
2012/12/12 19:16:06
This returns -> Returns
blois
2012/12/12 19:46:29
Done.
|
+ * `::after, ::before, ::marker, ::line-marker`. |
+ * |
+ * See also: |
+ * |
+ * * [Pseudo-elements](http://docs.webplatform.org/wiki/css/selectors/pseudo-elements) |
+ */ |
Future<CssStyleDeclaration> getComputedStyle(String pseudoElement) { |
return _createMeasurementFuture( |
() => window.$dom_getComputedStyle(this, pseudoElement), |
@@ -7492,7 +7606,20 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
// TODO(vsm): Implement noSuchMethod or similar for dart2js. |
- /** @domName Element.insertAdjacentText */ |
+ /** |
+ * Creates a text node and inserts it into the DOM at the specified location. |
+ * |
+ * The [where] parameter indicates where to insert [text]: |
+ * |
+ * * `beforeBegin` Immediately before this element. |
Kathy Walrath
2012/12/12 19:16:06
These bullets seem like they wouldn't look right i
blois
2012/12/12 19:46:29
Done.
|
+ * * `afterBegin` As the first child of this element. |
+ * * `beforeEnd` As the last child of this element. |
+ * * `afterEnd` Immediately after this element. |
+ * |
+ * See also: |
+ * |
+ * * [insertAdjacentHtml] |
+ */ |
void insertAdjacentText(String where, String text) { |
if (JS('bool', '!!#.insertAdjacentText', this)) { |
_insertAdjacentText(where, text); |
@@ -7504,7 +7631,23 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
@JSName('insertAdjacentText') |
void _insertAdjacentText(String where, String text) native; |
- /** @domName Element.insertAdjacentHTML */ |
+ /** |
+ * Parses text as an HTML fragment and inserts it into the DOM at the |
+ * specified location. |
+ * |
+ * The [where] parameter indicates where to insert the HTML fragment: |
+ * |
+ * * `beforeBegin` Immediately before this element. |
+ * * `afterBegin` As the first child of this element. |
+ * * `beforeEnd` As the last child of this element. |
+ * * `afterEnd` Immediately after this element. |
+ * |
+ * var html = '<div class="something">content</div>'; |
+ * // Inserts as the first child |
+ * document.body.insertAdjacentHtml('afterBegin', html); |
+ * var createdElement = document.body.children[0]; |
+ * print(createdElement.classes[0]); // Prints 'something' |
Kathy Walrath
2012/12/12 19:16:06
Perhaps this method should be the one that the mai
blois
2012/12/12 19:46:29
Done.
|
+ */ |
void insertAdjacentHtml(String where, String text) { |
if (JS('bool', '!!#.insertAdjacentHtml', this)) { |
_insertAdjacentHtml(where, text); |
@@ -7516,7 +7659,20 @@ abstract class Element extends Node implements ElementTraversal native "*Element |
@JSName('insertAdjacentHTML') |
void _insertAdjacentHTML(String where, String text) native; |
- /** @domName Element.insertAdjacentHTML */ |
+ /** |
+ * Inserts [element] into the DOM at the specified location. |
+ * |
+ * The [where] parameter indicates where to insert [element]: |
+ * |
+ * * `beforeBegin` Immediately before this element. |
+ * * `afterBegin` As the first child of this element. |
+ * * `beforeEnd` As the last child of this element. |
+ * * `afterEnd` Immediately after this element. |
+ * |
+ * See also: |
+ * |
+ * * [insertAdjacentHtml] |
+ */ |
Element insertAdjacentElement(String where, Element element) { |
if (JS('bool', '!!#.insertAdjacentElement', this)) { |
_insertAdjacentElement(where, element); |