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

Lines changed: 514 additions & 502 deletions
Large diffs are not rendered by default.

api-reports/2_13.txt

Lines changed: 514 additions & 502 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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
Lines changed: 22 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 18 additions & 0 deletions
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]

0 commit comments

Comments
 (0)