aboutsummaryrefslogtreecommitdiff
path: root/common/shared/src/main/scala/TextTemplates.scala
diff options
context:
space:
mode:
Diffstat (limited to 'common/shared/src/main/scala/TextTemplates.scala')
-rw-r--r--common/shared/src/main/scala/TextTemplates.scala46
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)
+ )
+ )
+
+}