File tree Expand file tree Collapse file tree 3 files changed +14
-13
lines changed
src/main/scala/tutorial/webapp Expand file tree Collapse file tree 3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,8 @@ scalaVersion := "2.13.1"
7
7
scalaJSUseMainModuleInitializer := true
8
8
9
9
libraryDependencies += " org.scala-js" %%% " scalajs-dom" % " 1.0.0"
10
+ libraryDependencies += " be.doeraene" %%% " scalajs-jquery" % " 1.0.0"
11
+
12
+ skip in packageJSDependencies := false
13
+ jsDependencies +=
14
+ " org.webjars" % " jquery" % " 2.2.1" / " jquery.js" minified " jquery.min.js"
Original file line number Diff line number Diff line change 5
5
< title > The Scala.js Tutorial</ title >
6
6
</ head >
7
7
< body >
8
- < button id ="click-me-button " type ="button " onclick =" addClickedMessage() " >
8
+ < button id ="click-me-button " type ="button ">
9
9
Click me!
10
10
</ button >
11
11
12
+ <!-- Include JavaScript dependencies -->
13
+ < script type ="text/javascript " src ="./target/scala-2.13/scala-js-tutorial-jsdeps.js "> </ script >
12
14
<!-- Include Scala.js compiled code -->
13
15
< script type ="text/javascript " src ="./target/scala-2.13/scala-js-tutorial-fastopt.js "> </ script >
14
16
</ body >
Original file line number Diff line number Diff line change 1
1
package tutorial .webapp
2
2
3
- import scala .scalajs .js .annotation .JSExportTopLevel
4
-
5
- import org .scalajs .dom
6
- import org .scalajs .dom .document
3
+ import org .scalajs .jquery ._
7
4
8
5
object TutorialApp {
9
6
def main (args : Array [String ]): Unit = {
10
- appendPar(document.body, " Hello World " )
7
+ jQuery(() => setupUI() )
11
8
}
12
9
13
- def appendPar (targetNode : dom.Node , text : String ): Unit = {
14
- val parNode = document.createElement(" p" )
15
- val textNode = document.createTextNode(text)
16
- parNode.appendChild(textNode)
17
- targetNode.appendChild(parNode)
10
+ def setupUI (): Unit = {
11
+ jQuery(" body" ).append(" <p>Hello World</p>" )
12
+ jQuery(" #click-me-button" ).click(() => addClickedMessage())
18
13
}
19
14
20
- @ JSExportTopLevel (" addClickedMessage" )
21
15
def addClickedMessage (): Unit = {
22
- appendPar(document. body, " You clicked the button!" )
16
+ jQuery( " body" ).append( " <p> You clicked the button!</p> " )
23
17
}
24
18
}
You can’t perform that action at this time.
0 commit comments