Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: sdk/lib/html/templates/html/impl/impl_Element.darttemplate

Issue 11348255: Adding docs to Element. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/html/templates/html/impl/impl_Element.darttemplate
diff --git a/sdk/lib/html/templates/html/impl/impl_Element.darttemplate b/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
index b253d2d3602e40f86970000e34b563a88f3d1a5b..d236031a2122ba0117a833c60a99695eb6915100 100644
--- a/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
+++ b/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
@@ -348,17 +348,56 @@ class _ElementCssClassSet extends CssClassSet {
}
}
-/// @domName $DOMNAME
+/**
+ * An abstract class, which all HTML elements extend.
+ */
abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
+ /**
+ * 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 $CLASSNAME.html(String html) =>
_$(CLASSNAME)FactoryProvider.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 $CLASSNAME.tag(String tag) =>
_$(CLASSNAME)FactoryProvider.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);
@@ -392,8 +431,16 @@ abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
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);
@@ -405,12 +452,46 @@ abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
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.
+ *
+ * // Gets the first descendant with the class 'classname'
+ * var element = element.query('.className');
+ * // Gets the element with id 'id'
+ * var element = element.query('#id');
+ * // Gets 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) {
@@ -419,6 +500,29 @@ abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
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>
+ *
+ * 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);
@@ -432,19 +536,39 @@ abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
/**
* 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 values that are inherited from other
+ * sources, such as parent elements or stylesheets. This differs from the
+ * [style] property, which contains only the values specified directly on this
+ * element.
+ *
+ * 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 */
+ /**
+ * Returns the computed styles for pseudo-elements such as `::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),
@@ -452,14 +576,15 @@ abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
}
/**
- * Adds the specified element to after the last child of this.
+ * Adds the specified element to after the last child of this element.
*/
void append(Element e) {
this.children.add(e);
}
/**
- * Adds the specified text as a text node after the last child of this.
+ * Adds the specified text as a text node after the last child of this
+ * element.
*/
void appendText(String text) {
this.insertAdjacentText('beforeend', text);
@@ -467,7 +592,7 @@ abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
/**
* Parses the specified text as HTML and adds the resulting node after the
- * last child of this.
+ * last child of this element.
*/
void appendHtml(String text) {
this.insertAdjacentHtml('beforeend', text);
@@ -509,7 +634,16 @@ $else
$endif
$if DART2JS
- /** @domName Element.insertAdjacentText */
+ /**
+ * Creates a text node and inserts it into the DOM at the specified location.
+ *
+ * To see the possible values for [where], read the doc for
+ * [insertAdjacentHtml].
+ *
+ * See also:
+ *
+ * * [insertAdjacentHtml]
+ */
void insertAdjacentText(String where, String text) {
if (JS('bool', '!!#.insertAdjacentText', this)) {
_insertAdjacentText(where, text);
@@ -521,7 +655,28 @@ $if DART2JS
@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'
+ *
+ * See also:
+ *
+ * * [insertAdjacentText]
+ * * [insertAdjacentElement]
+ */
void insertAdjacentHtml(String where, String text) {
if (JS('bool', '!!#.insertAdjacentHtml', this)) {
_insertAdjacentHtml(where, text);
@@ -533,7 +688,16 @@ $if DART2JS
@JSName('insertAdjacentHTML')
void _insertAdjacentHTML(String where, String text) native;
- /** @domName Element.insertAdjacentHTML */
+ /**
+ * Inserts [element] into the DOM at the specified location.
+ *
+ * To see the possible values for [where], read the doc for
+ * [insertAdjacentHtml].
+ *
+ * See also:
+ *
+ * * [insertAdjacentHtml]
+ */
Element insertAdjacentElement(String where, Element element) {
if (JS('bool', '!!#.insertAdjacentElement', this)) {
_insertAdjacentElement(where, element);
« sdk/lib/html/dart2js/html_dart2js.dart ('K') | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698