aboutsummaryrefslogblamecommitdiff
path: root/vfd-dashboard/src/main/scala/vfd/dashboard/Launcher.scala
blob: d0919110f2a07fb55eff6b56581274be22cf56b9 (plain) (tree)
1
2
3
4
5
6
7
8
9
                     
 
                                           

                      
                           
 
                     
                                                    
 
                                  
                                                                             













                                                     
 

                                               
     

                              


   
package vfd.dashboard

import scala.scalajs.js.annotation.JSExport

import org.scalajs.dom
import org.scalajs.dom.html

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

  lazy val env = new Environment {
    val root = dom.document.getElementById(rootId).asInstanceOf[html.Element]
    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)
  }

}