Skip to content

Commit 1e70e9f

Browse files
committed
Merge branch 'develop'
* develop: Test fixes Continued work on Phaser.js # Conflicts: # browser/jquery/src/main/scala/io/scalajs/jquery/JQueryElement.scala # browser/jquery/src/test/scala/io/scalajs/jquery/JQueryTest.scala # browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ArcadePhysics.scala # browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/GameObjectCreator.scala # browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Phaser.scala # browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Physics.scala # browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PhysicsBody.scala # browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sprite.scala # browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/TextStyleOptions.scala # build.sbt # nodejs/src/test/scala/io/scalajs/nodejs/child_process/ChildProcessTest.scala # nodejs/src/test/scala/io/scalajs/nodejs/net/NetTest.scala
2 parents 3a4da03 + 4933e9b commit 1e70e9f

File tree

77 files changed

+4944
-803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4944
-803
lines changed

browser/dom/src/main/scala/io/scalajs/dom/html/URLSearchParams.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.scalajs.collection.Iterator
44
import io.scalajs.dom.USVString
55

66
import scala.scalajs.js
7+
import scala.scalajs.js.annotation.JSName
78
import scala.scalajs.js.|
89

910
/**
@@ -16,6 +17,7 @@ import scala.scalajs.js.|
1617
* @author lawrence.daniels@gmail.com
1718
*/
1819
@js.native
20+
@JSName("URLSearchParams")
1921
class URLSearchParams(init: USVString | URLSearchParams) extends js.Object {
2022

2123
/////////////////////////////////////////////////////////////////////////////////

browser/dom/src/test/scala/io/scalajs/dom/html/URLSearchParamsTest.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.scalajs.dom.html
22

33
import io.scalajs.dom.html.browser.console
4+
import io.scalajs.util.ScalaJsHelper._
45
import org.scalatest.FunSpec
56

7+
import scala.scalajs.js
8+
69
/**
710
* URL Search Params Test
811
* @author lawrence.daniels@gmail.com
@@ -12,11 +15,14 @@ class URLSearchParamsTest extends FunSpec {
1215
describe("URLSearchParams") {
1316

1417
it("should provide an iteration of values") {
15-
val searchParams = new URLSearchParams("key1=value1&key2=value2")
18+
// only if URLSearchParams is supported
19+
if (isDefined(js.Dynamic.global.URLSearchParams)) {
20+
val searchParams = new URLSearchParams("key1=value1&key2=value2")
1621

17-
// Display the key/value pairs
18-
for (value <- searchParams.values()) {
19-
console.log(value)
22+
// Display the key/value pairs
23+
for (value <- searchParams.values()) {
24+
console.log(value)
25+
}
2026
}
2127
}
2228

browser/jquery/src/main/scala/io/scalajs/jquery/JQueryElement.scala

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.scalajs.jquery
33
import io.scalajs.JsNumber
44
import io.scalajs.dom.html.HTMLElement
55
import io.scalajs.dom.html.css.CSSSelector
6-
import io.scalajs.dom.{Element, Event, Node}
6+
import io.scalajs.dom.{Element, Event, Node, Text}
77

88
import scala.scalajs.js
99
import scala.scalajs.js.annotation.JSBracketAccess
@@ -42,16 +42,27 @@ trait JQueryElement extends HTMLElement {
4242
// Methods
4343
///////////////////////////////////////////////////////////////
4444

45+
/**
46+
* Create a new jQuery object with elements added to the set of matched elements.
47+
* @param selector could be any of the following:
48+
* <ul>
49+
* <li>selector: A string representing a selector expression to find additional elements to add to the set of matched elements.</li>
50+
* <li>elements: One or more elements to add to the set of matched elements.</li>
51+
* <li>html: An HTML fragment to add to the set of matched elements.</li>
52+
* <li>selection: An existing jQuery object to add to the set of matched elements..</li>
53+
* </ul>
54+
*/
55+
def add(selector: Selector | CSSSelector | HTMLElement*): this.type = js.native
56+
4557
/**
4658
* The add() method adds elements to an existing group of elements.
47-
* @param element Required. Specifies a selector expression, a jQuery object, one or more elements
48-
* or an HTML snippet to be added to an existing group of elements
49-
* @param context Optional. Specifies the point in the document at which the selector expression
50-
* should begin matching
59+
* @param selector Required. Specifies a selector expression, a jQuery object, one or more elements
60+
* or an HTML snippet to be added to an existing group of elements
61+
* @param context Optional. Specifies the point in the document at which the selector expression
62+
* should begin matching
5163
* @return self reference
5264
*/
53-
def add(element: Element | Selector | CSSSelector | js.Any, context: Element | js.Any = js.native): this.type =
54-
js.native
65+
def add(selector: HTMLElement | Selector | CSSSelector, context: HTMLElement): this.type = js.native
5566

5667
/**
5768
* Add the previous set of elements on the stack to the current set, optionally filtered by a selector.
@@ -78,9 +89,7 @@ trait JQueryElement extends HTMLElement {
7889
* @param speed The optional speed parameter can take the following values: "slow", "fast", or milliseconds.
7990
* @param callback The optional callback parameter is a function to be executed after toggle() completes.
8091
*/
81-
def animate(params: AnimateOptions | js.Any,
82-
speed: String | JsNumber = js.native,
83-
callback: js.Function): this.type = js.native
92+
def animate(params: AnimateOptions | js.Any, speed: String | JsNumber = js.native, callback: js.Function): this.type = js.native
8493

8594
/**
8695
* Insert content, specified by the parameter, to the end of each element in the set of matched elements.
@@ -144,8 +153,7 @@ trait JQueryElement extends HTMLElement {
144153
* containing one or more events to attach to the elements, and
145154
* functions to run when the event occurs
146155
*/
147-
def bind(event: String, data: js.Any = js.native, function: js.Function, map: js.Any = js.native): this.type =
148-
js.native
156+
def bind(event: String, data: js.Any = js.native, function: js.Function, map: js.Any = js.native): this.type = js.native
149157

150158
/**
151159
* Attach a handler to an event for the elements.
@@ -194,7 +202,7 @@ trait JQueryElement extends HTMLElement {
194202
* Bind an event handler to the "change" JavaScript event, or trigger that event on an element.
195203
* @param callback A function to execute each time the event is triggered.
196204
*/
197-
def change(callback: js.Function1[Event, Any] = js.native): this.type = js.native
205+
def change[A](callback: js.Function1[Event, A] = js.native): this.type = js.native
198206

199207
/**
200208
* Get the children of each element in the set of matched elements, optionally filtered by a selector.
@@ -480,8 +488,7 @@ trait JQueryElement extends HTMLElement {
480488
* @param selector A selector which should match the one originally passed to [[JQueryElement.on .on()]] when attaching event handlers.
481489
* @param handler A handler function previously attached for the event(s), or the special value false.
482490
*/
483-
def off(events: String, selector: String = js.native, handler: js.Function1[Event, Unit] = js.native): this.type =
484-
js.native
491+
def off(events: String, selector: String = js.native, handler: js.Function1[Event, Unit] = js.native): this.type = js.native
485492

486493
/**
487494
* Get the current coordinates of the first element in the set of matched elements, relative to the document.
@@ -511,19 +518,15 @@ trait JQueryElement extends HTMLElement {
511518
* @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand
512519
* for a function that simply does return false.
513520
*/
514-
def on(events: String,
515-
selector: String = js.native,
516-
data: js.Any = js.native,
517-
handler: js.Function = js.native): this.type = js.native
521+
def on(events: String, selector: String = js.native, data: js.Any = js.native, handler: js.Function = js.native): this.type = js.native
518522

519523
/**
520524
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
521525
* @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".
522526
* @param data Data to be passed to the handler in event.data when an event is triggered.
523527
* @param handler A function to execute at the time the event is triggered.
524528
*/
525-
def one(events: String, data: js.Any = js.native, handler: js.Function1[Event, Unit] = js.native): this.type =
526-
js.native
529+
def one(events: String, data: js.Any = js.native, handler: js.Function1[Event, Unit] = js.native): this.type = js.native
527530

528531
def outerHeight(): Integer = js.native
529532

@@ -568,7 +571,7 @@ trait JQueryElement extends HTMLElement {
568571
* @param content One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to
569572
* insert at the beginning of each element in the set of matched elements.
570573
*/
571-
def prepend(content: js.Any, content1: js.Any*): this.type = js.native
574+
def prepend(content: (String | HTMLElement | Text | js.Array[String | HTMLElement | Text])*): this.type = js.native
572575

573576
/**
574577
* Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
@@ -579,12 +582,6 @@ trait JQueryElement extends HTMLElement {
579582
*/
580583
def prepend(fn: js.Function): this.type = js.native
581584

582-
/**
583-
* Inserts content at the beginning of the selected elements
584-
* @param content the specified content
585-
*/
586-
def prepend(content: js.Any): this.type = js.native
587-
588585
/**
589586
* Get the immediately preceding sibling of each element in the set of matched elements. If a selector is provided,
590587
* it retrieves the previous sibling only if it matches that selector.
@@ -614,13 +611,7 @@ trait JQueryElement extends HTMLElement {
614611
* @param propertyName The name of the property to get.
615612
* @return the property value
616613
*/
617-
def prop[T <: js.Any](propertyName: String): T = js.native
618-
619-
/**
620-
* Get the value of a property for the first element in the set of matched elements.
621-
* @param name The name of the property to get.
622-
*/
623-
def prop(name: String): Boolean = js.native
614+
def prop(propertyName: String): String = js.native
624615

625616
/**
626617
* Set one or more properties for the set of matched elements.
@@ -888,4 +879,4 @@ trait JQueryElement extends HTMLElement {
888879
*/
889880
def wrap(function: js.Function): this.type = js.native
890881

891-
}
882+
}

browser/jquery/src/main/scala/io/scalajs/jquery/package.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.scalajs
22

3+
import scala.scalajs.js
4+
35
/**
46
* jquery package object
57
* @author lawrence.daniels@gmail.com
@@ -11,4 +13,18 @@ package object jquery {
1113
*/
1214
type Selector = String
1315

16+
17+
/**
18+
* JQuery Enrichment
19+
* @param element the given [[JQueryElement]]
20+
*/
21+
implicit class JQueryEnrichment(val element: JQueryElement) extends AnyVal {
22+
23+
@inline
24+
def attr(name: String, function: (Int, String) => String): element.type = {
25+
element.attr(name, function: js.Function2[Int, String, String])
26+
}
27+
28+
}
29+
1430
}

browser/jquery/src/test/scala/io/scalajs/jquery/JQueryTest.scala

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.scalajs.jquery
22

3+
import io.scalajs.dom.Event
4+
import io.scalajs.dom.html.browser.window
5+
import io.scalajs.dom.html.browser.window.document
36
import io.scalajs.jquery.JQuery.$
4-
import org.scalajs.dom.html.browser.window
57
import org.scalatest._
68

79
import scala.scalajs.js
@@ -12,10 +14,11 @@ import scala.scalajs.js
1214
*/
1315
class JQueryTest extends FunSpec {
1416

15-
import window.document
1617

1718
describe("JQuery") {
19+
// No JQuery on the server - See cheerio instead
1820

21+
/*
1922
it("should provide a add() method for adding elements to an existing group") {
2023
$("h1").add("p").add("span")
2124
}
@@ -30,29 +33,27 @@ class JQueryTest extends FunSpec {
3033
3134
// case #2
3235
$("#greatphoto").attr(new js.Object {
33-
val alt: String = "Beijing Brush Seller"
36+
val alt: String = "Beijing Brush Seller"
3437
val title: String = "photo by Kelly Clark"
3538
})
3639
3740
// case #3
3841
$("#w3s").attr("href", "http://www.w3schools.com/jquery")
3942
4043
// case #4
41-
$("#greatphoto").attr("title", (i, `val`) => `val` + " - photo by Kelly Clark")
44+
$("#greatphoto").attr("title", (i: Int, value: String) => value + " - photo by Kelly Clark")
4245
}
4346
4447
it("should provide a change() method") {
4548
val element = $("input")
46-
element
47-
.change(_ => {
48-
val $input = $(element)
49-
$("p").html(
50-
".attr( 'checked' ): <b>" + $input.attr("checked") + "</b><br>" +
51-
".prop( 'checked' ): <b>" + $input.prop("checked") + "</b><br>" +
52-
".is( ':checked' ): <b>" + $input.is(":checked") + "</b>"
53-
)
54-
})
55-
.change()
49+
element.change { _: Event =>
50+
val $input = $(element)
51+
$("p").html(
52+
".attr( 'checked' ): <b>" + $input.attr("checked") + "</b><br>" +
53+
".prop( 'checked' ): <b>" + $input.prop("checked") + "</b><br>" +
54+
".is( ':checked' ): <b>" + $input.is(":checked") + "</b>"
55+
)
56+
}.change()
5657
}
5758
5859
it("should provide a children() method") {
@@ -74,12 +75,12 @@ class JQueryTest extends FunSpec {
7475
$("p").click()
7576
7677
// case #2
77-
$("#btn1").click { _ =>
78+
$("#btn1").click { _: Event =>
7879
window.alert("Text: " + $("#test").text())
7980
}
8081
8182
// case #3
82-
$("ul").click { event =>
83+
$("ul").click { event: Event =>
8384
val target = $(event.target)
8485
if (target.is("li")) {
8586
target.css("background-color", "red")
@@ -149,7 +150,7 @@ class JQueryTest extends FunSpec {
149150
150151
it("should provide a text() method") {
151152
$("div").text($("img").attr("alt"))
152-
}
153+
}*/
153154

154155
}
155156

0 commit comments

Comments
 (0)