summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlihaoyi <haoyi.sg@gmail.com>2014-11-23 22:21:44 -0800
committerlihaoyi <haoyi.sg@gmail.com>2014-11-23 22:21:44 -0800
commit85d381c1201ff8aa798321ea9237b57464b40de9 (patch)
tree26dac3719558b66a549a7236b4c46bb5119a3cf0
parent7924069976b15ee0c535221673d89200ce3d5570 (diff)
downloadhands-on-scala-js-85d381c1201ff8aa798321ea9237b57464b40de9.tar.gz
hands-on-scala-js-85d381c1201ff8aa798321ea9237b57464b40de9.tar.bz2
hands-on-scala-js-85d381c1201ff8aa798321ea9237b57464b40de9.zip
gh links work
-rwxr-xr-xbook/src/main/resources/css/side-menu.css2
-rw-r--r--book/src/main/scala/book/Utils.scala18
-rw-r--r--book/src/main/scalatex/book/Intro.scalatex2
-rw-r--r--examples/demos/src/main/scala/scrollmenu/Controller.scala2
-rw-r--r--examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala18
5 files changed, 29 insertions, 13 deletions
diff --git a/book/src/main/resources/css/side-menu.css b/book/src/main/resources/css/side-menu.css
index 81f1ee7..b8e36c6 100755
--- a/book/src/main/resources/css/side-menu.css
+++ b/book/src/main/resources/css/side-menu.css
@@ -333,6 +333,6 @@ code{
}
/*Workaround for bug in highlight.js IDEA theme*/
-.hljs-tag, .hljs-symbol{
+span.hljs-tag, span.hljs-symbol{
background: none;
}
diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala
index 91d76a7..8c5c920 100644
--- a/book/src/main/scala/book/Utils.scala
+++ b/book/src/main/scala/book/Utils.scala
@@ -147,6 +147,11 @@ object hl{
def diff(code: String*) = highlight(code, "diff")
def html(code: String*) = highlight(code, "xml")
+ val mappings = Seq(
+ "output/scala-js" -> "https://github.com/scala-js/scala-js",
+ "output/workbench-example-app" -> "https://github.com/lihaoyi/workbench-example-app",
+ "" -> "https://github.com/lihaoyi/hands-on-scala-js"
+ )
def ref(filepath: String, start: String = "", end: String = "\n") = {
val lang = filepath.split('.').last match {
@@ -179,7 +184,17 @@ object hl{
val blob = sliced.map(_.drop(whitespace)).mkString("\n")
+ val (prefix, url) =
+ mappings.iterator
+ .find{case (prefix, path) => filepath.startsWith(prefix)}
+ .get
+
+ val hash =
+ if (endLine == -1) ""
+ else s"#L$startLine-L$endLine"
+ val linkUrl =
+ s"$url/tree/master/${filepath.drop(prefix.length)}$hash"
pre(
code(cls:=lang + " highlight-me hljs", blob),
a(
@@ -190,7 +205,8 @@ object hl{
bottom:="0.5em",
display.block,
fontSize:="24px",
- href:="#"
+ href:=linkUrl,
+ target:="_blank"
)
)
}
diff --git a/book/src/main/scalatex/book/Intro.scalatex b/book/src/main/scalatex/book/Intro.scalatex
index 10a2638..87c8895 100644
--- a/book/src/main/scalatex/book/Intro.scalatex
+++ b/book/src/main/scalatex/book/Intro.scalatex
@@ -101,7 +101,7 @@
@p
Despite the problems with Javascript (and other tools like HTML an CSS, which have their own problems) the Web platform got a lot of things right, and the Desktop and Mobile platforms have a lot of catching up to do. If only we could improve upon the parts that aren't so great. This is where Scala.js comes in.
-@sect{The Promise}
+@sect{About Scala.js}
@p
With Scala.js, you can cross compile your Scala code to a Javascript executable that can run on all major web browsers. You get all the benefits of the web platform in terms of deployability, security, and hyperlinking, with none of the problems of writing your software in Javascript. Scala.js provides a @sect.ref("The Language", "better language") to do your work in, but also provides some other goodies that have in-so-far never been seen in mainstream web development: @sect.ref("Sharing Code", "shared-code") and @sect.ref("Client-Server Integration", "client-server integration").
diff --git a/examples/demos/src/main/scala/scrollmenu/Controller.scala b/examples/demos/src/main/scala/scrollmenu/Controller.scala
index d359138..4480445 100644
--- a/examples/demos/src/main/scala/scrollmenu/Controller.scala
+++ b/examples/demos/src/main/scala/scrollmenu/Controller.scala
@@ -34,7 +34,7 @@ object Controller{
scrollSpy.domTrees.map(_.value.frag)
).render
- def updateScroll() = scrollSpy(main.scrollTop)
+ def updateScroll() = scrollSpy()
val expandIcon = i(cls := "fa fa-caret-down").render
val expandLink =
a(
diff --git a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
index 29c44a6..9ce9a2b 100644
--- a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
+++ b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
@@ -61,13 +61,13 @@ class ScrollSpy(structure: Tree[String],
}
- private[this] var scrolling = false
- def apply(threshold: => Double) = if (!scrolling){
- scrolling = true
- dom.setTimeout(() => start(threshold), 200)
+ private[this] var scrolling = -1
+ def apply() = {
+ dom.clearTimeout(scrolling)
+ scrolling = dom.setTimeout(() => start(), 200)
}
- private[this] def start(threshold: Double) = {
- scrolling = false
+ private[this] def start() = {
+// scrolling = false
def scroll(el: dom.Element) = {
val rect = el.getBoundingClientRect()
if (rect.top <= 0)
@@ -77,8 +77,8 @@ class ScrollSpy(structure: Tree[String],
}
def walkTree(tree: Tree[MenuNode]): Boolean = {
val Tree(MenuNode(menuItem, itemId, start, end), children) = tree
- val before = headers(start) <= threshold
- val after = (end >= headers.length) || headers(end) > threshold
+ val before = headers(start) <= main.scrollTop
+ val after = (end >= headers.length) || headers(end) > main.scrollTop
val win = before && after
@@ -97,7 +97,7 @@ class ScrollSpy(structure: Tree[String],
// aren't any children which won, so it must be the actual leaf
tree.children.foreach(_.value.frag.classList.remove("selected"))
if (dom.location.hash != itemId)
- dom.location.hash = itemId
+ dom.history.pushState(null, null, "#"+itemId)
scroll(menuItem.children(0))
}