File tree Expand file tree Collapse file tree 3 files changed +12
-15
lines changed
src/main/scala/tutorial/webapp Expand file tree Collapse file tree 3 files changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,6 @@ name := "Scala.js Tutorial"
4
4
5
5
scalaVersion := " 2.11.2"
6
6
7
- libraryDependencies += " org.scala-lang.modules.scalajs" %%% " scalajs-dom" % " 0.6"
7
+ libraryDependencies += " org.scala-lang.modules.scalajs" %%% " scalajs-jquery" % " 0.6"
8
+
9
+ skip in ScalaJSKeys .packageJSDependencies := false
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 "
9
- onclick ="tutorial.webapp.TutorialApp().addClickedMessage() ">
10
- Click me!</ button >
8
+ < button id ="click-me-button " type ="button "> Click me!</ button >
11
9
10
+ <!-- Include JavaScript dependencies -->
11
+ < script type ="text/javascript " src ="./target/scala-2.11/scala-js-tutorial-jsdeps.js "> </ script >
12
12
<!-- Include Scala.js compiled code -->
13
13
< script type ="text/javascript " src ="./target/scala-2.11/scala-js-tutorial-fastopt.js "> </ script >
14
14
<!-- Run tutorial.webapp.TutorialApp -->
Original file line number Diff line number Diff line change 1
1
package tutorial .webapp
2
2
3
3
import scala .scalajs .js .JSApp
4
- import scala .scalajs .js .annotation .JSExport
5
4
6
- import org .scalajs .dom
7
- import dom .document
5
+ import org .scalajs .jquery .jQuery
8
6
9
7
object TutorialApp extends JSApp {
10
8
def main (): Unit = {
11
- appendPar(document.body, " Hello World " )
9
+ jQuery(setupUI _ )
12
10
}
13
11
14
- def appendPar (targetNode : dom.Node , text : String ): Unit = {
15
- val parNode = document.createElement(" p" )
16
- val textNode = document.createTextNode(text)
17
- parNode.appendChild(textNode)
18
- targetNode.appendChild(parNode)
12
+ def setupUI (): Unit = {
13
+ jQuery(" body" ).append(" <p>Hello World</p>" )
14
+ jQuery(" #click-me-button" ).click(addClickedMessage _)
19
15
}
20
16
21
- @ JSExport
22
17
def addClickedMessage (): Unit = {
23
- appendPar(document. body, " You clicked the button!" )
18
+ jQuery( " body" ).append( " <p> You clicked the button!</p> " )
24
19
}
25
20
}
You can’t perform that action at this time.
0 commit comments