Skip to content

Commit 8a2d8f6

Browse files
authored
Merge pull request #599 from scala-js/topic/html-collection
Improve `HTMLCollection` and friends
2 parents ed19d07 + b4f15a6 commit 8a2d8f6

19 files changed

+1113
-1031
lines changed

api-reports/2_12.txt

+514-502
Large diffs are not rendered by default.

api-reports/2_13.txt

+514-502
Large diffs are not rendered by default.

src/main/scala/org/scalajs/dom/Document.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ abstract class Document extends Node with NodeSelector with DocumentEvent with P
5151
* root node. The returned HTMLCollection is live, meaning that it updates itself automatically to stay in sync with
5252
* the DOM tree without having to call document.getElementsByTagName again.
5353
*/
54-
def getElementsByTagName(name: String): HTMLCollection = js.native
54+
def getElementsByTagName(name: String): HTMLCollection[Element] = js.native
5555

5656
/** Returns a list of elements with the given tag name belonging to the given namespace. The complete document is
5757
* searched, including the root node.
5858
*/
59-
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection = js.native
59+
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection[Element] = js.native
6060

6161
/** Returns a set of elements which have all the given class names. When called on the document object, the complete
6262
* document is searched, including the root node. You may also call getElementsByClassName on any element; it will
6363
* return only elements which are descendants of the specified root element with the given class names.
6464
*/
65-
def getElementsByClassName(classNames: String): HTMLCollection = js.native
65+
def getElementsByClassName(classNames: String): HTMLCollection[Element] = js.native
6666

6767
/** Returns the element from the document whose elementFromPoint method is being called which is the topmost element
6868
* which lies under the given point.  To get an element, specify the point via coordinates, in CSS pixels, relative

src/main/scala/org/scalajs/dom/Element.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ abstract class Element extends Node with NodeSelector with ParentNode with NonDo
167167
* automatically. Consequently, there is no need to call several times element.getElementsByTagName with the same
168168
* element and arguments.
169169
*/
170-
def getElementsByTagName(name: String): HTMLCollection = js.native
170+
def getElementsByTagName(name: String): HTMLCollection[Element] = js.native
171171

172172
/** Returns a list of elements with the given tag name belonging to the given namespace. */
173-
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection = js.native
173+
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection[Element] = js.native
174174

175175
/** Returns an array-like object of all child elements which have all of the given class names. When called on the
176176
* document object, the complete document is searched, including the root node. You may also call
177177
* getElementsByClassName() on any element; it will return only elements which are descendants of the specified root
178178
* element with the given class names.
179179
*/
180-
def getElementsByClassName(classNames: String): HTMLCollection = js.native
180+
def getElementsByClassName(classNames: String): HTMLCollection[Element] = js.native
181181

182182
/** hasAttributeNS returns a boolean value indicating whether the current element has the specified attribute. */
183183
def hasAttributeNS(namespaceURI: String, localName: String): Boolean = js.native

src/main/scala/org/scalajs/dom/HTMLCollection.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import scala.scalajs.js.annotation._
1414
*/
1515
@js.native
1616
@JSGlobal
17-
class HTMLCollection private[this] () extends DOMList[Element] {
18-
def item(index: Int): Element = js.native
17+
abstract class HTMLCollection[+E] extends DOMList[E] {
18+
def item(index: Int): E = js.native
1919

2020
/** Returns the specific node whose ID or, as a fallback, name matches the string specified by name. Matching by name
2121
* is only done as a last resort, only in HTML, and only if the referenced element supports the name attribute.
2222
* Returns null if no node exists by the given name.
2323
*/
24-
def namedItem(name: String): Element = js.native
24+
def namedItem(name: String): E = js.native
2525
}

src/main/scala/org/scalajs/dom/HTMLDataListElement.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ import scala.scalajs.js.annotation._
1717
abstract class HTMLDataListElement extends HTMLElement {
1818

1919
/** A collection of the contained option elements. */
20-
def options: HTMLCollection = js.native
20+
def options: HTMLCollection[Element] = js.native
2121
}

src/main/scala/org/scalajs/dom/HTMLDocument.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ abstract class HTMLDocument extends Document {
6868
def activeElement: Element = js.native
6969

7070
/** Returns a list of the embedded <embed> elements within the current document. */
71-
def embeds: HTMLCollection = js.native
71+
def embeds: HTMLCollection[Element] = js.native
7272

7373
/** forms returns a collection (an HTMLCollection) of the form elements within the current document. */
74-
def forms: HTMLCollection = js.native
74+
def forms: HTMLCollection[Element] = js.native
7575

7676
/** The links property returns a collection of all AREA elements and anchor elements in a document with a value for
7777
* the href attribute.
7878
*/
79-
def links: HTMLCollection = js.native
79+
def links: HTMLCollection[Element] = js.native
8080

8181
/** anchors returns a list of all of the anchors in the document. */
82-
def anchors: HTMLCollection = js.native
82+
def anchors: HTMLCollection[Element] = js.native
8383

8484
/** Returns an HTMLCollection object containing one or more HTMLEmbedElements or null which represent the
8585
* <embed> elements in the current document.
8686
*/
87-
def plugins: HTMLCollection = js.native
87+
def plugins: HTMLCollection[Element] = js.native
8888

8989
/** document.images returns a collection of the images in the current HTML document. */
90-
def images: HTMLCollection = js.native
90+
def images: HTMLCollection[Element] = js.native
9191

9292
/** Returns the current value of the current range for a formatting command. */
9393
def queryCommandValue(commandId: String): String = js.native
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation._
11+
import scala.scalajs.js.|
12+
13+
/** The HTMLFormControlsCollection interface represents a collection of HTML form control elements.
14+
*
15+
* It represents the lists returned by the HTMLFormElement interface's elements property and the HTMLFieldSetElement
16+
* interface's elements property.
17+
*
18+
* This interface replaces one method from HTMLCollection, on which it is based.
19+
*/
20+
@js.native
21+
@JSGlobal
22+
class HTMLFormControlsCollection private[this] () extends HTMLCollection[RadioNodeList | Element]

src/main/scala/org/scalajs/dom/HTMLFormElement.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class HTMLFormElement extends HTMLElement {
3333
/** elements returns an HTMLFormControlsCollection (HTML 4 HTMLCollection) of all the form controls contained in the
3434
* FORM element, with the exception of input elements which have a type attribute of image.
3535
*/
36-
def elements: HTMLCollection = js.native
36+
def elements: HTMLCollection[Element] = js.native
3737

3838
/** action gets/sets the action of the <form> element. */
3939
var action: String = js.native
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation._
11+
12+
/** The HTMLOptionsCollection interface represents a collection of <option> HTML elements (in document order) and offers
13+
* methods and properties for selecting from the list as well as optionally altering its items. This object is returned
14+
* only by the options property of select.
15+
*/
16+
@js.native
17+
@JSGlobal
18+
class HTMLOptionsCollection private[this] () extends HTMLCollection[HTMLOptionElement]

src/main/scala/org/scalajs/dom/HTMLSelectElement.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.scalajs.js.annotation._
1717
abstract class HTMLSelectElement extends HTMLElement {
1818

1919
/** The set of &lt;option&gt; elements contained by this element. Read only. */
20-
val options: js.Array[HTMLOptionElement] = js.native
20+
val options: HTMLOptionsCollection = js.native
2121

2222
/** The value of this form control, that is, of the first selected option. */
2323
var value: String = js.native

src/main/scala/org/scalajs/dom/HTMLTableElement.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class HTMLTableElement extends HTMLElement {
3030
* a &lt;thead&gt; appear first, in tree order, and those members of a &lt;tbody&gt; last, also in tree order. The
3131
* HTMLCollection is live and is automatically updated when the HTMLTableElement changes.
3232
*/
33-
def rows: HTMLCollection = js.native
33+
def rows: HTMLCollection[Element] = js.native
3434

3535
/** Is an HTMLTableCaptionElement representing the first &lt;caption&gt; that is a child of the element, or null if
3636
* none is found. When set, if the object doesn't represent a &lt;caption&gt;, a DOMException with the
@@ -42,7 +42,7 @@ abstract class HTMLTableElement extends HTMLElement {
4242
/** Returns a live HTMLCollection containing all the &lt;tbody&gt; of the element. The HTMLCollection is live and is
4343
* automatically updated when the HTMLTableElement changes.
4444
*/
45-
def tBodies: HTMLCollection = js.native
45+
def tBodies: HTMLCollection[Element] = js.native
4646

4747
/** Is an HTMLTableSectionElement representing the first &lt;thead&gt; that is a child of the element, or null if none
4848
* is found. When set, if the object doesn't represent a &lt;thead&gt;, a DOMException with the HierarchyRequestError

src/main/scala/org/scalajs/dom/HTMLTableRowElement.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class HTMLTableRowElement extends HTMLElement with HTMLTableAlignment {
2424
/** Returns a live HTMLCollection containing the cells in the row. The HTMLCollection is live and is automatically
2525
* updated when cells are added or removed.
2626
*/
27-
def cells: HTMLCollection = js.native
27+
def cells: HTMLCollection[Element] = js.native
2828

2929
var borderColorLight: js.Any = js.native
3030

src/main/scala/org/scalajs/dom/HTMLTableSectionElement.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class HTMLTableSectionElement extends HTMLElement with HTMLTableAlignme
2020
/** Returns a live HTMLCollection containing the rows in the section. The HTMLCollection is live and is automatically
2121
* updated when rows are added or removed.
2222
*/
23-
def rows: HTMLCollection = js.native
23+
def rows: HTMLCollection[Element] = js.native
2424

2525
/** Removes the cell at the given position in the section. If the given position is greater (or equal as it starts at
2626
* zero) than the amount of rows in the section, or is smaller than 0, it raises a DOMException with the

src/main/scala/org/scalajs/dom/NodeList.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import scala.scalajs.js.annotation._
1313
*/
1414
@js.native
1515
@JSGlobal
16-
class NodeList[+T <: Node] private[this] () extends DOMList[T] {
16+
class NodeList[+T <: Node]() extends DOMList[T] {
1717
def item(index: Int): T = js.native
1818
}

src/main/scala/org/scalajs/dom/ParentNode.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import scala.scalajs.js.|
1818
trait ParentNode extends js.Object {
1919

2020
/** Returns a live HTMLCollection containing all objects of type Element that are children of the object. */
21-
def children: HTMLCollection = js.native
21+
def children: HTMLCollection[Element] = js.native
2222

2323
/** Returns the Element that is the first child of the object, or null if there is none. */
2424
def firstElementChild: Element = js.native
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/** The RadioNodeList interface represents a collection of radio elements in a <form> or a <fieldset> element. */
7+
@js.native
8+
@JSGlobal
9+
class RadioNodeList extends NodeList[Node] {
10+
11+
/** If the underlying element collection contains radio buttons, the value property represents the checked radio
12+
* button. On retrieving the value property, the value of the currently checked radio button is returned as a string.
13+
* If the collection does not contain any radio buttons or none of the radio buttons in the collection is in checked
14+
* state, the empty string is returned. On setting the value property, the first radio button input element whose
15+
* value property is equal to the new value will be set to checked.
16+
*/
17+
def value: String = js.native
18+
}

src/main/scala/org/scalajs/dom/html.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object html {
1010
type Button = HTMLButtonElement
1111
type BR = HTMLBRElement
1212
type Canvas = HTMLCanvasElement
13-
type Collection = HTMLCollection
13+
type Collection[+E] = HTMLCollection[E]
1414
type DataList = HTMLDataListElement
1515
type Div = HTMLDivElement
1616
type DList = HTMLDListElement

src/main/scala/org/scalajs/dom/raw.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ object raw {
320320
@deprecated("use dom.HTMLCanvasElement instead", "2.0.0")
321321
type HTMLCanvasElement = dom.HTMLCanvasElement
322322

323-
@deprecated("use dom.HTMLCollectionElement instead", "2.0.0")
324-
type HTMLCollectionElement = dom.HTMLCollection
323+
@deprecated("use dom.HTMLCollection instead", "2.0.0")
324+
type HTMLCollectionElement = dom.HTMLCollection[dom.Element]
325325

326326
@deprecated("use dom.HTMLDataListElement instead", "2.0.0")
327327
type HTMLDataListElement = dom.HTMLDataListElement

0 commit comments

Comments
 (0)