All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hyperscala.ui.PageChangeWarning.scala Maven / Gradle / Ivy

There is a newer version: 0.10.3
Show newest version
package org.hyperscala.ui

import org.hyperscala.module._
import org.hyperscala.web.{Website, Webpage}
import org.powerscala.Version
import org.hyperscala.html._
import org.hyperscala.javascript.JavaScriptString
import org.hyperscala.realtime.Realtime
import com.outr.net.http.session.Session

/**
 * @author Matt Hicks 
 */
object PageChangeWarning extends Module {
  def name = "pagechangewarning"

  def version = Version(1)

  override def dependencies = List(Realtime)

  override def init[S <: Session](website: Website[S]) = {
    website.register("/js/page_change_warning.js", "page_change_warning.js")
  }

  override def load[S <: Session](webpage: Webpage[S]) = {
    webpage.head.contents += new tag.Script(src = "/js/page_change_warning.js")
  }

  def warn[S <: Session](webpage: Webpage[S], message: String) = {
    val m = message match {
      case null => "null"
      case _ => "'%s'".format(message)
    }
    webpage.body.contents += new tag.Script {
      contents += new JavaScriptString("setPageChangeWarning(%s);".format(m))
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy