diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-05-06 13:56:16 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-05-08 23:02:39 -0700 |
commit | 8ecae787ff7124b008229d958c579c73649dd9e4 (patch) | |
tree | dad7bea34d9b7ea0f716a783f3b57de491ec959e /common/shared/src/main/scala/TextTemplates.scala | |
download | scala-triad-8ecae787ff7124b008229d958c579c73649dd9e4.tar.gz scala-triad-8ecae787ff7124b008229d958c579c73649dd9e4.tar.bz2 scala-triad-8ecae787ff7124b008229d958c579c73649dd9e4.zip |
Initial commit
Diffstat (limited to 'common/shared/src/main/scala/TextTemplates.scala')
-rw-r--r-- | common/shared/src/main/scala/TextTemplates.scala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/common/shared/src/main/scala/TextTemplates.scala b/common/shared/src/main/scala/TextTemplates.scala new file mode 100644 index 0000000..24a3b0e --- /dev/null +++ b/common/shared/src/main/scala/TextTemplates.scala @@ -0,0 +1,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) + ) + ) + +} |