summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2015-03-12 20:13:25 +0800
committerLi Haoyi <haoyi@dropbox.com>2015-03-28 22:11:38 +0800
commit7006cebd061784900233c405ce03665151b86010 (patch)
tree5809b127984508a436f6806d94132c29ea2b8fee
parentac86ffc25a169585fffffd2535e856b9826e78ad (diff)
downloadhands-on-scala-js-7006cebd061784900233c405ce03665151b86010.tar.gz
hands-on-scala-js-7006cebd061784900233c405ce03665151b86010.tar.bz2
hands-on-scala-js-7006cebd061784900233c405ce03665151b86010.zip
better scrolling
-rwxr-xr-xbook/src/main/resources/css/side-menu.css6
-rw-r--r--book/src/main/scalatex/Index.scalatex (renamed from book/src/main/scalatex/book/Index.scalatex)2
-rw-r--r--book/src/main/scalatex/Intro.scalatex (renamed from book/src/main/scalatex/book/Intro.scalatex)2
-rw-r--r--book/src/main/scalatex/handson/CanvasApp.scalatex (renamed from book/src/main/scalatex/book/handson/CanvasApp.scalatex)2
-rw-r--r--book/src/main/scalatex/handson/ClientServer.scalatex (renamed from book/src/main/scalatex/book/handson/ClientServer.scalatex)2
-rw-r--r--book/src/main/scalatex/handson/CommandLine.scalatex (renamed from book/src/main/scalatex/book/handson/CommandLine.scalatex)2
-rw-r--r--book/src/main/scalatex/handson/GettingStarted.scalatex (renamed from book/src/main/scalatex/book/handson/GettingStarted.scalatex)2
-rw-r--r--book/src/main/scalatex/handson/PublishingModules.scalatex (renamed from book/src/main/scalatex/book/handson/PublishingModules.scalatex)2
-rw-r--r--book/src/main/scalatex/handson/WebPage.scalatex (renamed from book/src/main/scalatex/book/handson/WebPage.scalatex)2
-rw-r--r--book/src/main/scalatex/indepth/AdvancedTechniques.scalatex (renamed from book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex)2
-rw-r--r--book/src/main/scalatex/indepth/CompilationPipeline.scalatex (renamed from book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex)2
-rw-r--r--book/src/main/scalatex/indepth/DesignSpace.scalatex (renamed from book/src/main/scalatex/book/indepth/DesignSpace.scalatex)2
-rw-r--r--book/src/main/scalatex/indepth/JavaAPIs.scalatex (renamed from book/src/main/scalatex/book/indepth/JavaAPIs.scalatex)2
-rw-r--r--book/src/main/scalatex/indepth/JavascriptInterop.scalatex (renamed from book/src/main/scalatex/book/indepth/JavascriptInterop.scalatex)0
-rw-r--r--book/src/main/scalatex/indepth/SemanticDifferences.scalatex (renamed from book/src/main/scalatex/book/indepth/SemanticDifferences.scalatex)2
-rw-r--r--build.sbt4
-rw-r--r--examples/crossBuilds/clientserver/build.sbt4
-rw-r--r--examples/crossBuilds/clientserver/project/build.sbt2
-rw-r--r--examples/crossBuilds/clientserver2/build.sbt6
-rw-r--r--examples/crossBuilds/clientserver2/project/build.sbt2
-rw-r--r--examples/demos/build.sbt6
-rw-r--r--examples/demos/src/main/scala/scrollmenu/Controller.scala2
-rw-r--r--examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala33
-rw-r--r--project/build.sbt2
24 files changed, 41 insertions, 52 deletions
diff --git a/book/src/main/resources/css/side-menu.css b/book/src/main/resources/css/side-menu.css
index ed06b5f..dafa1b5 100755
--- a/book/src/main/resources/css/side-menu.css
+++ b/book/src/main/resources/css/side-menu.css
@@ -1,10 +1,8 @@
#main{
- position: fixed;
max-width: 100%;
right: 0px;
left: 0px;
- height: 100%;
overflow-y: scroll
}
@@ -200,8 +198,8 @@ Hides the menu at `48em`, but modify this based on your app's needs.
padding-left: 250px; /* left col width "#menu" */
left: 0;
}
- #main{
- left: 250px;
+ #main-box{
+ padding-left: 250px;
}
#menu {
left: 250px;
diff --git a/book/src/main/scalatex/book/Index.scalatex b/book/src/main/scalatex/Index.scalatex
index e1a7f69..e9f65bb 100644
--- a/book/src/main/scalatex/book/Index.scalatex
+++ b/book/src/main/scalatex/Index.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@val firstHalfDescription = Seq[Frag]("""
is a set of tutorials that walks you through getting started with Scala.js. You'll build a range of small projects, from """, sect.ref("Making a Canvas App"), " to ", sect.ref("Interactive Web Pages"), " to ", sect.ref("Integrating Client-Server"), """, and in the process will get a good overview of both Scala.js's use cases as well as the development experience
diff --git a/book/src/main/scalatex/book/Intro.scalatex b/book/src/main/scalatex/Intro.scalatex
index c9248f8..b72b6e2 100644
--- a/book/src/main/scalatex/book/Intro.scalatex
+++ b/book/src/main/scalatex/Intro.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
Scala.js compiles Scala code to equivalent, executable Javascript. Here's the compilation of a trivial hello-world example:
diff --git a/book/src/main/scalatex/book/handson/CanvasApp.scalatex b/book/src/main/scalatex/handson/CanvasApp.scalatex
index e40b211..d008508 100644
--- a/book/src/main/scalatex/book/handson/CanvasApp.scalatex
+++ b/book/src/main/scalatex/handson/CanvasApp.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@val canvasapp = wd/'examples/'demos/'src/'main/'scala/'canvasapp
@p
By this point, you've already cloned and got your hands dirty fiddling around with the toy @lnk("workbench-example-app", "https://github.com/lihaoyi/workbench-example-app"). You have your editor set up, SBT installed, and have published the example application in a way you can host online for other people to see. Maybe you've even made some changes to the application to see what happens. Hopefully you're curious, and want to learn more.
diff --git a/book/src/main/scalatex/book/handson/ClientServer.scalatex b/book/src/main/scalatex/handson/ClientServer.scalatex
index 50f9850..4d15735 100644
--- a/book/src/main/scalatex/book/handson/ClientServer.scalatex
+++ b/book/src/main/scalatex/handson/ClientServer.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@def lazyload(id: String) = script(raw(s"""
window.addEventListener("load", function(){
diff --git a/book/src/main/scalatex/book/handson/CommandLine.scalatex b/book/src/main/scalatex/handson/CommandLine.scalatex
index b7a16cf..26e0811 100644
--- a/book/src/main/scalatex/book/handson/CommandLine.scalatex
+++ b/book/src/main/scalatex/handson/CommandLine.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
We've by this point done a bunch of work in the browser: we've made a small game that runs in the web browser on the HTML5 canvas, and we've made a number of small web-apps that interact with HTML and 3rd party web-services. However, there's a whole other side to the Scala.js ecosystem: the command line interace, or CLI.
diff --git a/book/src/main/scalatex/book/handson/GettingStarted.scalatex b/book/src/main/scalatex/handson/GettingStarted.scalatex
index 5d4d299..6243ace 100644
--- a/book/src/main/scalatex/book/handson/GettingStarted.scalatex
+++ b/book/src/main/scalatex/handson/GettingStarted.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
To get started with Scala.js, you will need to prepare a few things:
diff --git a/book/src/main/scalatex/book/handson/PublishingModules.scalatex b/book/src/main/scalatex/handson/PublishingModules.scalatex
index abe634a..61a21d5 100644
--- a/book/src/main/scalatex/book/handson/PublishingModules.scalatex
+++ b/book/src/main/scalatex/handson/PublishingModules.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
We've spent several chapters exploring the experience of making web apps using Scala.js, but any large application (web or not!) likely relies on a host of libraries in order to implement large chunks of its functionality. Ideally these libraries would be re-usable, and can be shared among different projects, teams or even companies.
diff --git a/book/src/main/scalatex/book/handson/WebPage.scalatex b/book/src/main/scalatex/handson/WebPage.scalatex
index a7f754d..13b5b20 100644
--- a/book/src/main/scalatex/book/handson/WebPage.scalatex
+++ b/book/src/main/scalatex/handson/WebPage.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
Most web applications aren't neat little games which live on a single canvas: they are large, structured HTML pages, which involve displaying data (whether from the user or from the web) in multiple ways, while allowing the user to make changes to the data that can be saved back to whatever remote web-service/database it came from.
diff --git a/book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex b/book/src/main/scalatex/indepth/AdvancedTechniques.scalatex
index 0b84cfe..66b8b10 100644
--- a/book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex
+++ b/book/src/main/scalatex/indepth/AdvancedTechniques.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
@sect.ref{Getting Started} walks you through how to set up some basic Scala.js applications, but that only scratches the surface of the things you can do with Scala.js. Apart from being able to use the same techniques you're used to in Scala-JVM in the browser, Scala.js opens up a whole range of possibilities and novel techniques that are not found in typical Scala-JVM applications.
diff --git a/book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex b/book/src/main/scalatex/indepth/CompilationPipeline.scalatex
index ece6215..fe2adb9 100644
--- a/book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex
+++ b/book/src/main/scalatex/indepth/CompilationPipeline.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
Scala.js is implemented as a compiler plugin in the Scala compiler. Despite this, the overall process looks very different from that of a normal Scala application. This is because Scala.js optimizes for the size of the compiled executable, which is something that Scala-JVM does not usually do.
diff --git a/book/src/main/scalatex/book/indepth/DesignSpace.scalatex b/book/src/main/scalatex/indepth/DesignSpace.scalatex
index 594d8c8..6eec6fd 100644
--- a/book/src/main/scalatex/book/indepth/DesignSpace.scalatex
+++ b/book/src/main/scalatex/indepth/DesignSpace.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
Scala.js is a relatively large project, and is the result of both an enormous amount of hard work as well as a number of decisions that craft what it's like to program in Scala.js today. Many of these decisions result in marked differences from the behavior of the same code running on the JVM. This chapter explores the reasoning and rationale behind these decisions.
diff --git a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex b/book/src/main/scalatex/indepth/JavaAPIs.scalatex
index 1a0afa5..51ac71f 100644
--- a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex
+++ b/book/src/main/scalatex/indepth/JavaAPIs.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
Below is a list of classes from the Java Standard Library that are available from Scala.js. In general, much of @hl.scala{java.lang}, and parts of @hl.scala{java.io}, @hl.scala{java.util} and @hl.scala{java.net} have been ported over. This means that all these classes are available for use in Scala.js applications despite being part of the Java standard library.
diff --git a/book/src/main/scalatex/book/indepth/JavascriptInterop.scalatex b/book/src/main/scalatex/indepth/JavascriptInterop.scalatex
index 30404ce..30404ce 100644
--- a/book/src/main/scalatex/book/indepth/JavascriptInterop.scalatex
+++ b/book/src/main/scalatex/indepth/JavascriptInterop.scalatex
diff --git a/book/src/main/scalatex/book/indepth/SemanticDifferences.scalatex b/book/src/main/scalatex/indepth/SemanticDifferences.scalatex
index c87c60f..bcc0f6b 100644
--- a/book/src/main/scalatex/book/indepth/SemanticDifferences.scalatex
+++ b/book/src/main/scalatex/indepth/SemanticDifferences.scalatex
@@ -1,4 +1,4 @@
-@import BookData._
+@import book.BookData._
@p
Although Scala.js tries very hard to maintain compatibility with Scala-JVM, there are some parts where the two platforms differs. This can be roughly grouped into two things: differences in the libraries available, and differences in the language itself. This chapter will cover both of these facets.
diff --git a/build.sbt b/build.sbt
index 58c61e8..c8de546 100644
--- a/build.sbt
+++ b/build.sbt
@@ -19,8 +19,8 @@ lazy val book = Project(
base = file("book")
).settings(sharedSettings ++ scalatex.SbtPlugin.projectSettings:_*).settings(
libraryDependencies ++= Seq(
- "com.lihaoyi" %% "scalatags" % "0.4.5",
- "com.lihaoyi" %%% "upickle" % "0.2.6",
+ "com.lihaoyi" %% "scalatags" % "0.4.6",
+ "com.lihaoyi" %%% "upickle" % "0.2.7",
"com.lihaoyi" %% "scalatex-site" % "0.1.1",
"com.lihaoyi" %% "ammonite" % "0.1.0"
),
diff --git a/examples/crossBuilds/clientserver/build.sbt b/examples/crossBuilds/clientserver/build.sbt
index 85c51fa..4ed5437 100644
--- a/examples/crossBuilds/clientserver/build.sbt
+++ b/examples/crossBuilds/clientserver/build.sbt
@@ -4,8 +4,8 @@ val app = crossProject.settings(
unmanagedSourceDirectories in Compile +=
baseDirectory.value / "shared" / "main" / "scala",
libraryDependencies ++= Seq(
- "com.lihaoyi" %%% "scalatags" % "0.4.5",
- "com.lihaoyi" %%% "upickle" % "0.2.6"
+ "com.lihaoyi" %%% "scalatags" % "0.4.6",
+ "com.lihaoyi" %%% "upickle" % "0.2.7"
),
scalaVersion := "2.11.5"
).jsSettings(
diff --git a/examples/crossBuilds/clientserver/project/build.sbt b/examples/crossBuilds/clientserver/project/build.sbt
index 2e982c3..64e56f2 100644
--- a/examples/crossBuilds/clientserver/project/build.sbt
+++ b/examples/crossBuilds/clientserver/project/build.sbt
@@ -1,4 +1,4 @@
/*project/build.sbt*/
-addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")
+addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")
diff --git a/examples/crossBuilds/clientserver2/build.sbt b/examples/crossBuilds/clientserver2/build.sbt
index c01f12b..6198623 100644
--- a/examples/crossBuilds/clientserver2/build.sbt
+++ b/examples/crossBuilds/clientserver2/build.sbt
@@ -2,9 +2,9 @@ val app = crossProject.settings(
unmanagedSourceDirectories in Compile +=
baseDirectory.value / "shared" / "main" / "scala",
libraryDependencies ++= Seq(
- "com.lihaoyi" %%% "scalatags" % "0.4.5",
- "com.lihaoyi" %%% "upickle" % "0.2.6",
- "com.lihaoyi" %%% "autowire" % "0.2.4"
+ "com.lihaoyi" %%% "scalatags" % "0.4.6",
+ "com.lihaoyi" %%% "upickle" % "0.2.7",
+ "com.lihaoyi" %%% "autowire" % "0.2.5"
),
scalaVersion := "2.11.5"
).jsSettings(
diff --git a/examples/crossBuilds/clientserver2/project/build.sbt b/examples/crossBuilds/clientserver2/project/build.sbt
index d523658..d3b6050 100644
--- a/examples/crossBuilds/clientserver2/project/build.sbt
+++ b/examples/crossBuilds/clientserver2/project/build.sbt
@@ -1,3 +1,3 @@
/*project/build.sbt*/
-addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")
+addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.1")
diff --git a/examples/demos/build.sbt b/examples/demos/build.sbt
index 6a7b10c..9190612 100644
--- a/examples/demos/build.sbt
+++ b/examples/demos/build.sbt
@@ -10,12 +10,12 @@ scalaVersion := "2.11.4"
libraryDependencies += "com.lihaoyi" %% "acyclic" % "0.1.2" % "provided"
-libraryDependencies += "com.lihaoyi" %%% "upickle" % "0.2.6"
+libraryDependencies += "com.lihaoyi" %%% "upickle" % "0.2.7"
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.8.0"
-libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.4.5"
+libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.4.6"
-libraryDependencies += "com.lihaoyi" %%% "scalarx" % "0.2.7"
+libraryDependencies += "com.lihaoyi" %%% "scalarx" % "0.2.8"
libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.2" \ No newline at end of file
diff --git a/examples/demos/src/main/scala/scrollmenu/Controller.scala b/examples/demos/src/main/scala/scrollmenu/Controller.scala
index 4627837..25af158 100644
--- a/examples/demos/src/main/scala/scrollmenu/Controller.scala
+++ b/examples/demos/src/main/scala/scrollmenu/Controller.scala
@@ -74,7 +74,7 @@ object Controller{
menuLink.classList.toggle("active")
}
- main.onscroll = (e: dom.UIEvent) => updateScroll()
+ dom.document.body.onscroll = (e: dom.UIEvent) => updateScroll()
updateScroll()
}
diff --git a/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala b/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala
index bd2f194..5c81ba2 100644
--- a/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala
+++ b/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala
@@ -57,10 +57,12 @@ class ScrollSpy(structure: Tree[String],
rec(structure).tail
}
- js.Array(
- menuItems.map(name => dom.document.getElementById(Controller.munge(name)).asInstanceOf[html.Element])
- .map((el) => () => offset(el, main)):_*
- )
+ val offsets = for(name <- menuItems) yield {
+ val el = dom.document.getElementById(Controller.munge(name)).asInstanceOf[html.Element]
+ () => offset(el, dom.document.body)
+
+ }
+ js.Array(offsets:_*)
}
var open = false
@@ -87,21 +89,11 @@ class ScrollSpy(structure: Tree[String],
private[this] var scrolling = false
private[this] var scrollTop = -1
def apply(): Unit = {
- if (!scrolling) {
- scrolling = true
- scrollTop = main.scrollTop.toInt
- dom.setTimeout({() =>
- scrolling = false
- if (scrollTop == main.scrollTop) start()
- else apply()
- },
- 75
- )
- }
+ start()
}
private[this] var previousWin: MenuNode = null
private[this] def start(force: Boolean = false) = {
- val scrollTop = main.scrollTop
+ val scrollTop = dom.document.body.scrollTop
def walkIndex(tree: Tree[MenuNode]): List[Tree[MenuNode]] = {
val t @ Tree(m, children) = tree
val win = if(m.start == -1) true
@@ -118,6 +110,7 @@ class ScrollSpy(structure: Tree[String],
}
val winPath = walkIndex(domTrees)
+
val winItem = winPath.last.value
def walkTree(indices: List[Tree[MenuNode]]): Int = indices match {
case Nil => 0
@@ -130,8 +123,9 @@ class ScrollSpy(structure: Tree[String],
for {
child <- children
if !indices.headOption.exists(_.value.frag == child.value.frag)
- } walkHide(child)
-
+ } {
+ walkHide(child)
+ }
val size = walkTree(rest) + children.length
mn.frag.children(1).asInstanceOf[html.Element].style.maxHeight =
if (!open) size * 44 + "px" else "none"
@@ -153,10 +147,7 @@ class ScrollSpy(structure: Tree[String],
}
if (winItem != previousWin || force){
-// scroll(winItem.frag.children(0))
-// dom.history.replaceState(null, null, "#" + winItem.id)
previousWin = winItem
-// println(winPath.map(_.value.id))
walkTree(winPath)
}
}
diff --git a/project/build.sbt b/project/build.sbt
index b1cfc53..a4c9041 100644
--- a/project/build.sbt
+++ b/project/build.sbt
@@ -1,4 +1,4 @@
-addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")
+addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")