From 8ecae787ff7124b008229d958c579c73649dd9e4 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 6 May 2018 13:56:16 -0700 Subject: Initial commit --- common/shared/src/main/scala/TextTemplates.scala | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 common/shared/src/main/scala/TextTemplates.scala (limited to 'common/shared/src/main/scala/TextTemplates.scala') 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) + ) + ) + +} -- cgit v1.2.3