aboutsummaryrefslogtreecommitdiff
path: root/shared/TextTemplates.scala
blob: 5674eacfe9b908e1774c5b97da39f7475c1b8171 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package triad

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

  def scripts(js: Boolean = true) =
    if (js)
      Seq(
        div(id := "scalajs-error", style := "display: none;")(
          "ScalaJS raised an exception. See the log for more information."
        ),
        script(`type` := "text/javascript", src := "/out.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(
      link(
        rel := "stylesheet",
        `type` := "text/css",
        href := "/assets/lib/bootstrap-4.1.0/css/bootstrap-reboot.min.css"
      ),
      link(
        rel := "stylesheet",
        `type` := "text/css",
        href := "/assets/lib/bootstrap-4.1.0/css/bootstrap-grid.min.css"
      ),
      link(
        rel := "stylesheet",
        `type` := "text/css",
        href := "/assets/lib/bootstrap-4.1.0/css/bootstrap.min.css"
      ),
      link(
        rel := "stylesheet",
        `type` := "text/css",
        href := "/assets/main.css"
      ),
      meta(
        name := "viewport",
        content := "width=device-width, initial-scale=1, shrink-to-fit=no"
      )
    ),
    body(
      conversation(messages),
      scripts(js)
    )
  )

}