aboutsummaryrefslogtreecommitdiff
path: root/vfd-frontend/src/main/scala/vfd/frontend/Launcher.scala
blob: e1715d729286bc775933d7f54490e6c54a374be7 (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
package vfd.frontend

import scala.scalajs.js.annotation.JSExport

import org.scalajs.dom

import vfd.frontend.util.Environment

@JSExport
class Launcher(rootId: String, assetsBase: String) {

  lazy val env = new Environment {
    val root = dom.document.getElementById(rootId)
    def asset(file: String) = assetsBase + "/" + file
  }

  @JSExport
  def main() = {
    import env._

    val args: Seq[(String, String)] = for (
      i <- 0 until root.attributes.length;
      attr = root.attributes.item(i);
      if attr.name.startsWith("data-")
    ) yield {
      attr.name.drop(5) -> attr.value
    }

    while (env.root.hasChildNodes) {
      env.root.removeChild(env.root.firstChild)
    }
    
    Main.main(args.toMap)(env)
  }

}