blob: de120c65545622b765314cef31e01d1a7c773fa3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package scrollmenu
import org.scalajs.dom
import org.scalajs.dom.extensions._
import scala.scalajs.js
import scala.scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
@JSExport
object Controller{
def munge(name: String) = {
name.replace(" ", "")
}
@JSExport
def main(data: scala.scalajs.js.Any) = {
val structure = upickle.readJs[Tree[String]](upickle.json.readJs(data))
val Seq(main, menu, layout, menuLink) = Seq(
"main", "menu", "layout", "menuLink"
).map(dom.document.getElementById)
val snippets = dom.document.getElementsByClassName("highlight-me")
snippets.foreach(js.Dynamic.global.hljs.highlightBlock(_))
val scrollSpy = new ScrollSpy(structure, main)
menu.appendChild(
div(cls:="pure-menu pure-menu-open")(
a(cls:="pure-menu-heading", href:="#")(
"Contents"
),
ul(cls:="menu-item-list")(
scrollSpy.domTrees.map(_.value.frag)
)
).render
)
menuLink.onclick = (e: dom.MouseEvent) => {
layout.classList.toggle("active")
menu.classList.toggle("active")
menuLink.classList.toggle("active")
}
main.onscroll = (e: dom.UIEvent) => {
scrollSpy(main.scrollTop + main.clientHeight)
}
}
}
|