aboutsummaryrefslogtreecommitdiff
path: root/common/shared/src/main/scala/TextTemplates.scala
blob: 24a3b0e7ee93ee604e865fa382b11877c1653bb8 (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
package triad

object TextTemplates extends Templates(scalatags.Text) {
  import bundle.all._

  def scripts(js: Boolean = true) =
    if (js)
      Seq(
        script(`type` := "text/javascript",
               src := "/assets/ui/js/ui-fastopt.js"),
        script(`type` := "text/javascript")(
          raw(
            """|document.addEventListener("DOMContentLoaded", function(event) {
               |  try {
               |    // root element that will contain the ScalaJS application
               |    var root = document.getElementById("conversation");
               |
               |    // clear any existing content
               |    while (root.firstChild) {
               |      root.removeChild(root.firstChild);
               |    }
               |
               |    // run ScalaJS application
               |    console.info("Starting ScalaJS application...")
               |    triad.Main().main(root)
               |  } catch(ex) {
               |    // display warning message in case of exception
               |    //document.getElementById("scalajs-error").style.display = "block";
               |    throw ex;
               |  }
               |});
               |""".stripMargin
          )
        )
      )
    else Seq.empty

  def page(messages: Seq[Message], js: Boolean = true) = html(
    head(),
    body(
      conversation(messages),
      scripts(js)
    )
  )

}