[html5] r3436 - [] (0) Change document.items to document.getItems() with built-in filtering.

whatwg at whatwg.org whatwg at whatwg.org
Thu Jul 16 18:30:43 PDT 2009


Author: ianh
Date: 2009-07-16 18:30:41 -0700 (Thu, 16 Jul 2009)
New Revision: 3436

Modified:
   index
   source
Log:
[] (0) Change document.items to document.getItems() with built-in filtering.

Modified: index
===================================================================
--- index	2009-07-17 01:11:53 UTC (rev 3435)
+++ index	2009-07-17 01:30:41 UTC (rev 3436)
@@ -6467,9 +6467,9 @@
   readonly attribute <a href=#htmlcollection-0>HTMLCollection</a> <a href=#dom-document-links title=dom-document-links>links</a>;
   readonly attribute <a href=#htmlcollection-0>HTMLCollection</a> <a href=#dom-document-forms title=dom-document-forms>forms</a>;
   readonly attribute <a href=#htmlcollection-0>HTMLCollection</a> <a href=#dom-document-scripts title=dom-document-scripts>scripts</a>;
-  readonly attribute <a href=#htmlcollection-0>HTMLCollection</a> <a href=#dom-document-items title=dom-document-items>items</a>;
   NodeList <a href=#dom-document-getelementsbyname title=dom-document-getElementsByName>getElementsByName</a>(in DOMString elementName);
   NodeList <a href=#dom-document-getelementsbyclassname title=dom-document-getElementsByClassName>getElementsByClassName</a>(in DOMString classNames);
+  NodeList <a href=#dom-document-getitems title=dom-document-getItems>getItems</a>([Optional] in DOMString typeNames);
 
   // <a href=#dynamic-markup-insertion>dynamic markup insertion</a>
            attribute DOMString <a href=#dom-innerhtml title=dom-innerHTML>innerHTML</a>;
@@ -41274,10 +41274,10 @@
   expose information to the user, for example offering it in a form
   that can be used by other applications.</p>
 
-  <p>The <code title=dom-document-items><a href=#dom-document-items>document.items</a></code> DOM
-  attribute provides access to all the <a href=#top-level-microdata-items>top-level microdata
-  items</a>. This attribute returns an <code><a href=#htmlcollection-0>HTMLCollection</a></code>,
-  which can be enumerated.</p>
+  <p>The <code title=dom-document-getItems><a href=#dom-document-getitems>document.getItems(<var title="">typeNames</var>)</a></code> method provides access to the
+  <a href=#top-level-microdata-items>top-level microdata items</a>. It returns a
+  <code>NodeList</code> containing the items with the specified types,
+  or all types if no argument is specified.</p>
 
   <p>Each <a href=#concept-item title=concept-item>item</a> is represented in the
   DOM by the element on which the relevant <code title=attr-item><a href=#items:-the-item-attribute>item</a></code> attribute is found. The various types
@@ -41286,23 +41286,12 @@
 
   <div class=example>
 
-   <p>This sample code shows a function that returns all the top-level
-   microdata items of the type that it is passed:</p>
+   <p>This sample how the <code title=dom-document-getItems><a href=#dom-document-getitems>getItems()</a></code> method can be used
+   to obtain a list of all the top-level microdata items of one type
+   given in the document:</p>
 
-   <pre>function getItems(type) {
-  var result = [];
-  for (var i = 0; i < document.items.length; i += 1) {
-    if (document.items[i].item.contains(type))
-      result.push(document.items[i]);
-  }
-  return result;
-}</pre>
+   <pre>var cats = document.getItems("com.example.feline");</pre>
 
-   <p>This function can be used to get all the "com.example.feline"
-   items as follows:</p>
-
-   <pre>var cats = getItems("com.example.feline");</pre>
-
   </div>
 
   <p>Once an element representing an <a href=#concept-item title=concept-item>item</a> has been obtained, its properties
@@ -41318,11 +41307,11 @@
 
   <div class=example>
 
-   <p>This sample uses the function above to get the first item of
-   type "net.example.user" and then pops up an alert using the
-   "net.example.name" property from that item.</p>
+   <p>This sample gets the first item of type "net.example.user" and
+   then pops up an alert using the "net.example.name" property from
+   that item.</p>
 
-   <pre>var user = getItems('net.example.user')[0];
+   <pre>var user = document.getItems('net.example.user')[0];
 alert('Hello ' + user.properties['net.example.name'][0].content + '!');</pre>
 
   </div>
@@ -41340,7 +41329,7 @@
    "com.example.color" values. This script looks up the first such
    item and then lists all its values.</p>
 
-   <pre>var cat = getItems('com.example.feline')[0];
+   <pre>var cat = document.getItems('com.example.feline')[0];
 var colors = cat.properties['com.example.color'].contents;
 var result;
 if (colors.length == 0) {
@@ -41642,12 +41631,14 @@
 
   <h3 id=microdata-dom-api><span class=secno>5.3 </span>Microdata DOM API</h3>
 
-  <dl class=domintro><dt><var title="">document</var> . <code title=dom-items>items</code></dt>
+  <dl class=domintro><dt><var title="">document</var> . <code title=dom-getItems()>getItems</code>( [ <var title="">types</var> ] )</dt>
 
    <dd>
 
-    <p>Returns an <code><a href=#htmlcollection-0>HTMLCollection</a></code> of the elements in the <code>Document</code> that create <a href=#concept-item title=concept-item>items</a> and that are not part of other <a href=#concept-item title=concept-item>items</a>.</p>
+    <p>Returns a <code>NodeList</code> of the elements in the <code>Document</code> that create <a href=#concept-item title=concept-item>items</a>, that are not part of other <a href=#concept-item title=concept-item>items</a>, and that have all the types given in the argument, if any.</p>
 
+    <p>The <var title="">types</var> argument is interpreted as a space-separated list of classes.</p>
+
    </dd>
 
    <dt><var title="">element</var> . <code title=dom-properties><a href=#dom-properties>properties</a></code></dt>
@@ -41673,10 +41664,17 @@
 
   </dl><div class=impl>
 
-  <p>The <dfn id=dom-document-items title=dom-document-items><code>document.items</code></dfn>
-  attribute must return an <code><a href=#htmlcollection-0>HTMLCollection</a></code> rooted at the
-  <code>Document</code> node, whose filter matches only elements in
-  the list of <a href=#top-level-microdata-items>top-level microdata items</a>.</p>
+  <p>The <dfn id=dom-document-getitems title=dom-document-getItems><code>document.getItems(<var title="">typeNames</var>)</code></dfn> method takes an optional
+  string that contains an <a href=#unordered-set-of-unique-space-separated-tokens>unordered set of unique
+  space-separated tokens</a> representing types. When called, the
+  method must return a live <code>NodeList</code> object containing
+  all the elements in the document, in <a href=#tree-order>tree order</a>, that
+  are <a href=#top-level-microdata-items>top-level microdata items</a> that have all the <a href=#item-types title="item types">types</a> specified in that argument, having
+  obtained the types by <a href=#split-a-string-on-spaces title="split a string on
+  spaces">splitting a string on spaces</a>. If there are no tokens
+  specified in the argument, or if the argument is missing, then the
+  method must return a <code>NodeList</code> containing all the
+  <a href=#top-level-microdata-items>top-level microdata items</a> in the document.</p>
 
   <p>The <dfn id=dom-item title=dom-item><code>item</code></dfn> DOM attribute
   on elements must <a href=#reflect>reflect</a> the element's <code title=attr-item><a href=#items:-the-item-attribute>item</a></code> content attribute.</p>

Modified: source
===================================================================
--- source	2009-07-17 01:11:53 UTC (rev 3435)
+++ source	2009-07-17 01:30:41 UTC (rev 3436)
@@ -6418,9 +6418,9 @@
   readonly attribute <span>HTMLCollection</span> <span title="dom-document-links">links</span>;
   readonly attribute <span>HTMLCollection</span> <span title="dom-document-forms">forms</span>;
   readonly attribute <span>HTMLCollection</span> <span title="dom-document-scripts">scripts</span>;
-  readonly attribute <span>HTMLCollection</span> <span title="dom-document-items">items</span>;
   NodeList <span title="dom-document-getElementsByName">getElementsByName</span>(in DOMString elementName);
   NodeList <span title="dom-document-getElementsByClassName">getElementsByClassName</span>(in DOMString classNames);
+  NodeList <span title="dom-document-getItems">getItems</span>([Optional] in DOMString typeNames);
 
   // <span>dynamic markup insertion</span>
            attribute DOMString <span title="dom-innerHTML">innerHTML</span>;
@@ -46460,10 +46460,11 @@
   expose information to the user, for example offering it in a form
   that can be used by other applications.</p>
 
-  <p>The <code title="dom-document-items">document.items</code> DOM
-  attribute provides access to all the <span>top-level microdata
-  items</span>. This attribute returns an <code>HTMLCollection</code>,
-  which can be enumerated.</p>
+  <p>The <code title="dom-document-getItems">document.getItems(<var
+  title="">typeNames</var>)</code> method provides access to the
+  <span>top-level microdata items</span>. It returns a
+  <code>NodeList</code> containing the items with the specified types,
+  or all types if no argument is specified.</p>
 
   <p>Each <span title="concept-item">item</span> is represented in the
   DOM by the element on which the relevant <code
@@ -46474,23 +46475,13 @@
 
   <div class="example">
 
-   <p>This sample code shows a function that returns all the top-level
-   microdata items of the type that it is passed:</p>
+   <p>This sample how the <code
+   title="dom-document-getItems">getItems()</code> method can be used
+   to obtain a list of all the top-level microdata items of one type
+   given in the document:</p>
 
-   <pre>function getItems(type) {
-  var result = [];
-  for (var i = 0; i < document.items.length; i += 1) {
-    if (document.items[i].item.contains(type))
-      result.push(document.items[i]);
-  }
-  return result;
-}</pre>
+   <pre>var cats = document.getItems("com.example.feline");</pre>
 
-   <p>This function can be used to get all the "com.example.feline"
-   items as follows:</p>
-
-   <pre>var cats = getItems("com.example.feline");</pre>
-
   </div>
 
   <p>Once an element representing an <span
@@ -46509,11 +46500,11 @@
 
   <div class="example">
 
-   <p>This sample uses the function above to get the first item of
-   type "net.example.user" and then pops up an alert using the
-   "net.example.name" property from that item.</p>
+   <p>This sample gets the first item of type "net.example.user" and
+   then pops up an alert using the "net.example.name" property from
+   that item.</p>
 
-   <pre>var user = getItems('net.example.user')[0];
+   <pre>var user = document.getItems('net.example.user')[0];
 alert('Hello ' + user.properties['net.example.name'][0].content + '!');</pre>
 
   </div>
@@ -46532,7 +46523,7 @@
    "com.example.color" values. This script looks up the first such
    item and then lists all its values.</p>
 
-   <pre>var cat = getItems('com.example.feline')[0];
+   <pre>var cat = document.getItems('com.example.feline')[0];
 var colors = cat.properties['com.example.color'].contents;
 var result;
 if (colors.length == 0) {
@@ -46880,12 +46871,14 @@
 
   <dl class="domintro">
 
-   <dt><var title="">document</var> . <code title="dom-items">items</code></dt>
+   <dt><var title="">document</var> . <code title="dom-getItems()">getItems</code>( [ <var title="">types</var> ] )</dt>
 
    <dd>
 
-    <p>Returns an <code>HTMLCollection</code> of the elements in the <code>Document</code> that create <span title="concept-item">items</span> and that are not part of other <span title="concept-item">items</span>.</p>
+    <p>Returns a <code>NodeList</code> of the elements in the <code>Document</code> that create <span title="concept-item">items</span>, that are not part of other <span title="concept-item">items</span>, and that have all the types given in the argument, if any.</p>
 
+    <p>The <var title="">types</var> argument is interpreted as a space-separated list of classes.</p>
+
    </dd>
 
    <dt><var title="">element</var> . <code title="dom-properties">properties</code></dt>
@@ -46916,10 +46909,19 @@
   <div class="impl">
 
   <p>The <dfn
-  title="dom-document-items"><code>document.items</code></dfn>
-  attribute must return an <code>HTMLCollection</code> rooted at the
-  <code>Document</code> node, whose filter matches only elements in
-  the list of <span>top-level microdata items</span>.</p>
+  title="dom-document-getItems"><code>document.getItems(<var
+  title="">typeNames</var>)</code></dfn> method takes an optional
+  string that contains an <span>unordered set of unique
+  space-separated tokens</span> representing types. When called, the
+  method must return a live <code>NodeList</code> object containing
+  all the elements in the document, in <span>tree order</span>, that
+  are <span>top-level microdata items</span> that have all the <span
+  title="item types">types</span> specified in that argument, having
+  obtained the types by <span title="split a string on
+  spaces">splitting a string on spaces</span>. If there are no tokens
+  specified in the argument, or if the argument is missing, then the
+  method must return a <code>NodeList</code> containing all the
+  <span>top-level microdata items</span> in the document.</p>
 
   <p>The <dfn title="dom-item"><code>item</code></dfn> DOM attribute
   on elements must <span>reflect</span> the element's <code




More information about the Commit-Watchers mailing list