本文整理汇总了Scala中org.scalajs.dom.raw.Event类的典型用法代码示例。如果您正苦于以下问题:Scala Event类的具体用法?Scala Event怎么用?Scala Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ContextMenu
//设置package包名称以及导入依赖的类
package ch.epfl.callgraph.visualization.view
import org.scalajs.dom.raw.Event
import scalatags.JsDom.all._
object ContextMenu {
val newLayerLink = li(`class` := "context-menu__item")(
a(`class` := "context-menu__link")(
i(`class` := "fa fa-eye")("Expand node to new layer")
)
).render
val expandLink = li(`class` := "context-menu__item")(
a(`class` := "context-menu__link")(
i(`class` := "fa fa-eye")("Expand node forward")
)
).render
val hideLink = li(`class` := "context-menu__item")(
a(`class` := "context-menu__link")(
i(`class` := "fa fa-eye")("Hide node")
)
).render
val nav = div(`class` := "context-menu")(
ul(`class` := "context-menu__items")(
expandLink,
hideLink,
newLayerLink
)
).render
def show(x: Double, y: Double, unit: String = "px") = {
nav.setAttribute("class", "context-menu--active context-menu")
nav.setAttribute("style", "left:" + x + unit + " ;top:" + y + unit)
}
def hide(): Unit = nav.setAttribute("class", "context-menu")
def setNewLayerCallback(f: Event => Unit) = newLayerLink.onclick = f
def setExpandCallback(f: Event => Unit) = expandLink.onclick = f
def setHideCallback(f: Event => Unit) = hideLink.onclick = f
}
示例2: NodeListSeq
//设置package包名称以及导入依赖的类
package org.danielnixon.progressive.extensions
import org.danielnixon.progressive.facades.dom.ElementMatches
import org.danielnixon.progressive.shared.Wart
import org.scalajs.dom.{ DOMList, Element, EventTarget, Node }
import org.danielnixon.saferdom.implicits.saferDOMList
import org.scalajs.dom.raw.Event
package object dom {
implicit class NodeListSeq[T <: Node](nodes: DOMList[T]) extends IndexedSeq[T] {
@SuppressWarnings(Array(Wart.OptionPartial))
override def foreach[U](f: T => U): Unit = {
for (i <- 0 until nodes.length) {
f(nodes.item(i))
}
}
override def length: Int = nodes.length
@SuppressWarnings(Array(Wart.Throw))
override def apply(idx: Int): T = {
nodes.itemOpt(idx).getOrElse(throw new IndexOutOfBoundsException(idx.toString))
}
}
implicit class ElementWrapper(val element: Element) extends AnyVal {
def closest(selector: String): Option[Element] = {
Option(ElementMatches.element2ElementMatches(element).closest(selector))
}
}
implicit class EventTargetWrapper(val eventTarget: EventTarget) extends AnyVal {
@SuppressWarnings(Array(Wart.Nothing))
def on[T <: Event](events: String, selector: String)(handler: (T, Element) => Unit): Unit = {
val listener = (event: T) => {
event.target match {
case element: Element => element.closest(selector).foreach(closest => handler(event, closest))
case _ =>
}
}
eventTarget.addEventListener(events, listener)
}
}
}
示例3: Main
//设置package包名称以及导入依赖的类
package client
import comms.Client
import org.scalajs.dom.{KeyboardEvent, UIEvent}
import shared.autowire.SharedApi
import shared.models.Shuttle
import autowire._
import scala.scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
import org.scalajs.dom
import org.scalajs.dom.ext.KeyCode
import org.scalajs.dom.raw.Event
@JSExport
object Main {
@JSExport
def main(): Unit = {
val in = input(placeholder := "Ping String Here").render
val output = span().render
val btnGo = input(`type` := "submit", value := "Go").render
val btnClear = input(`type` := "button", value := "Clear").render
btnClear.onclick = (e: UIEvent) => {
in.value = ""
output.innerHTML = ""
}
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
btnGo.onclick = (e: Event) => {
Client[SharedApi].getShuttle(in.value).call().foreach { shuttle: Shuttle =>
output.appendChild(span(shuttle.ping).render)
output.appendChild(p().render)
output.appendChild(span(shuttle.pong).render)
output.appendChild(p().render)
}
}
in.onkeyup = (e: KeyboardEvent) => {
e.keyCode match {
case KeyCode.Enter => btnGo.click()
case KeyCode.Escape => btnClear.click()
case _ => None
}
}
dom.document.body.innerHTML = ""
dom.document.body.appendChild(div(
in,
btnGo,
btnClear,
p(),
output
).render)
in.focus()
}
}
示例4: Main
//设置package包名称以及导入依赖的类
package helloBinding
import com.thoughtworks.binding.Binding.{Var, Vars}
import com.thoughtworks.binding.dom
import org.scalajs.dom.raw.Event
import org.scalajs.dom.html.Input
import org.scalajs.dom.document
object Main extends scalajs.js.JSApp {
@dom
def render = {
val name = Var("Binding.scala")
val show = Var(false)
<div>
<p>
<input type="checkbox" id="showCheckbox" onchange={_: Event => show := showCheckbox.checked }/>
<label for="showCheckbox">
Say hello to <input id="nameInput" value={name.get} oninput={_: Event => name := nameInput.value}/>
</label>
</p>
{
if (show.bind) {
<p>
Hello, {name.bind}!
</p>
} else {
<!-- Don't show hello. -->
}
}
</div>
}
def main(): Unit = {
dom.render(document.body, render)
}
}
示例5: SocketJS
//设置package包名称以及导入依赖的类
package com.malliina.logstreams.js
import org.scalajs.dom
import org.scalajs.dom.CloseEvent
import org.scalajs.dom.raw.{ErrorEvent, Event, MessageEvent}
import org.scalajs.jquery.jQuery
import upickle.Invalid
import scala.scalajs.js
import scala.scalajs.js.JSON
abstract class SocketJS(wsPath: String) {
val statusElem = elem("status")
val socket: dom.WebSocket = openSocket(wsPath)
def handlePayload(payload: String)
def openSocket(pathAndQuery: String) = {
val wsUrl = s"$wsBaseUrl$pathAndQuery"
val socket = new dom.WebSocket(wsUrl)
socket.onopen = (_: Event) => setFeedback("Connected.")
socket.onmessage = (event: MessageEvent) => onMessage(event)
socket.onclose = (_: CloseEvent) => setFeedback("Connection closed.")
socket.onerror = (_: ErrorEvent) => setFeedback("Connection error.")
socket
}
def wsBaseUrl = {
val location = dom.window.location
val wsProto = if (location.protocol == "http:") "ws" else "wss"
s"$wsProto://${location.host}"
}
def onMessage(msg: MessageEvent): Unit = {
val event = JSON.parse(msg.data.toString)
if (event.event.toString == "ping") {
} else {
handlePayload(JSON.stringify(event))
}
}
def onInvalidData(message: String): PartialFunction[Invalid, Unit] = {
case Invalid.Data(jsValue, errorMessage) =>
println(s"JSON failed to parse: '$errorMessage' in value '$jsValue', message '$message'.")
case Invalid.Json(errorMessage, in) =>
println(s"Not JSON, '$errorMessage' in value '$in', message '$message'.")
}
def setFeedback(feedback: String) = statusElem html feedback
def elem(id: String) = jQuery(s"#$id")
def global = js.Dynamic.global
def validate[T: PimpJSON.Reader](in: String): Either[Invalid, T] =
PimpJSON.validate(in)
}
示例6: Welcome
//设置package包名称以及导入依赖的类
package renderer
import globalvariables.VariableStorage
import org.scalajs.dom
import org.scalajs.dom.html
import org.scalajs.dom.raw.Event
import sharednodejsapis.ElectronShell
/**
* Manages what happens in the main screen html file.
*/
object Welcome {
if (VariableStorage.retrieveValue("gameCanceled") != null) {
dom.window.alert(VariableStorage.retrieveValue("gameCanceled").asInstanceOf[String])
VariableStorage.unStoreValue("gameCanceled")
}
dom.document.getElementById("githubTextProjectLink").asInstanceOf[html.Anchor].onclick = (_: Event) => {
ElectronShell.openExternal("https://github.com/sherpal/oh-hell-card-game")
}
}
示例7: Common
//设置package包名称以及导入依赖的类
package renderer
import globalvariables.VariableStorage
import org.scalajs.dom
import org.scalajs.dom.html
import org.scalajs.dom.raw.Event
import sharednodejsapis.ElectronShell
/**
* Here we put all the codes that is common to all the menu pages.
*/
object Common {
if (VariableStorage.retrieveValue("isThereServer").asInstanceOf[String] != null) {
dom.document.getElementById("isThereServer").asInstanceOf[html.Paragraph].innerHTML =
"Server port is " + VariableStorage.retrieveValue("isThereServer").asInstanceOf[String]
}
dom.document.getElementById("githubProjectLink").asInstanceOf[html.Image].onclick = (_: Event) => {
ElectronShell.openExternal("https://github.com/sherpal/oh-hell-card-game")
}
}
示例8: CardViewer
//设置package包名称以及导入依赖的类
package renderer
import gamelogic.Card
import graphics.CardGraphics
import org.scalajs.dom
import org.scalajs.dom.html
import org.scalajs.dom.raw.Event
import sharednodejsapis.IPCRenderer
/**
* Display the last card under the mouse in big
*/
object CardViewer {
val img: html.Image = dom.document.getElementById("card").asInstanceOf[html.Image]
img.width = dom.window.innerWidth.toInt
img.height = dom.window.innerHeight.toInt
val allCards: List[CardGraphics] = Card.defaultDeck.map(new CardGraphics(_))
IPCRenderer.on("change-card", (_: Event, value: Int, color: String) => {
println(value, color)
allCards.find(card => card.card.value.value == value && card.card.color.color == color) match {
case Some(card) =>
img.src = card.image.src
img.width = dom.window.innerWidth.toInt
img.height = dom.window.innerHeight.toInt
case None =>
}
})
}
示例9: ScoreHistory
//设置package包名称以及导入依赖的类
package renderer
import org.scalajs.dom
import org.scalajs.dom.html
import org.scalajs.dom.raw.{Event, MouseEvent}
import sharednodejsapis.IPCRenderer
/**
* Manages what happens in the score history html file.
*/
object ScoreHistory {
val table: html.Table = dom.document.getElementById("scoreTable").asInstanceOf[html.Table]
IPCRenderer.on("send-info", (_: Event, tableContent: String) => {
if (scala.scalajs.LinkingInfo.developmentMode)
println(tableContent)
table.innerHTML = tableContent
})
val button: html.Anchor = dom.document.getElementById("printToPdf").asInstanceOf[html.Anchor]
val legend: html.Paragraph = dom.document.getElementById("legend").asInstanceOf[html.Paragraph]
button.onclick = (_: MouseEvent) => {
button.style.visibility = "hidden"
legend.style.visibility = "hidden"
IPCRenderer.send("print-to-pdf")
}
IPCRenderer.on("printed", (_: Event) => {
button.style.visibility = "visible"
legend.style.visibility = "visible"
})
}
示例10: ScalaJSExample
//设置package包名称以及导入依赖的类
package example
import com.thoughtworks.binding.Binding.Var
import com.thoughtworks.binding.dom
import org.scalajs.dom.document
import org.scalajs.dom.ext.Ajax
import org.scalajs.dom.raw.Event
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
import scala.scalajs.js
import scala.scalajs.js.JSON
object ScalaJSExample extends js.JSApp {
def countRequest(data: Var[String]) = {
val url = "http://localhost:9000/count"
Ajax.get(url).onSuccess { case xhr =>
data := JSON.parse(xhr.responseText).count.toString
}
}
@dom
def render = {
val data = Var("")
countRequest(data) // initial population
<div>
<button onclick={event: Event => countRequest(data) }>
Boop
</button>
From Play: The server has been booped { data.bind } times. Shared Message: {shared.SharedMessages.itWorks}.
</div>
}
def main(): Unit = {
dom.render(document.body, render)
}
}
示例11: handleSliderChange
//设置package包名称以及导入依赖的类
package akkaviz.frontend
import org.scalajs.dom.Element
import org.scalajs.dom.html.Input
import org.scalajs.dom.raw.Event
import rx.Var
import scala.scalajs.js.ThisFunction1
import scalatags.JsDom.all._
trait ManipulationsUI {
lazy val delaySlider = input(id := "delay-slider", tpe := "range", min := 0, max := 2000, step := 100, value := 0, onchange := handleSliderChange).render
lazy val delayDisplay = span("0 msec").render
val receiveDelayPanel: Seq[Frag] = {
Seq(
div(`class` := "panel-heading", "Receive delay"),
div(
`class` := "panel-body",
delaySlider, delayDisplay,
p("Warning: can cause TimeoutException! Use with care!")
)
)
}
val delayMillis: Var[Int] = Var(0)
def handleSliderChange: ThisFunction1[Element, Event, Unit] = { (self: Element, event: Event) =>
delayMillis() = self.asInstanceOf[Input].valueAsNumber
}
delayMillis.trigger {
val millis: Int = delayMillis.now
delaySlider.value = millis.toString
delayDisplay.innerHTML = s"$millis msec"
}
}
示例12: Main
//设置package包名称以及导入依赖的类
package helloBinding
import com.thoughtworks.binding.Binding.Var
import com.thoughtworks.binding.dom
import org.scalajs.dom.raw.Event
import org.scalajs.dom.document
object Main extends scalajs.js.JSApp {
@dom
def render = {
val name = Var("Binding.scala")
val show = Var(false)
<div>
<p>
<input type="checkbox" id="showCheckbox" onchange={_: Event => show := showCheckbox.checked }/>
<label for="showCheckbox">
Say hello to <input id="nameInput" value={name.get} oninput={_: Event => name := nameInput.value}/>
</label>
</p>
{
if (show.bind) {
<p>
Hello, {name.bind}!
</p>
} else {
<!-- Don't show hello. -->
}
}
</div>
}
def main(): Unit = {
dom.render(document.body, render)
}
}