• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Event类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.scalajs.dom.Event的典型用法代码示例。如果您正苦于以下问题:Scala Event类的具体用法?Scala Event怎么用?Scala Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Event类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: EventHandlerSetupService

//设置package包名称以及导入依赖的类
package org.danielnixon.progressive.services

import org.danielnixon.progressive.extensions.dom.{ EventTargetWrapper, NodeListSeq }
import org.danielnixon.progressive.shared.Wart
import org.danielnixon.progressive.shared.api.DataAttributes
import org.scalajs.dom.{ Element, Event, MouseEvent, html }

class EventHandlerSetupService(
    refreshService: => RefreshService,
    hijaxService: => HijaxService,
    additionalSetupInitial: html.Body => Unit,
    additionalSetup: Element => Unit
) {

  def setup(element: Element): Unit = {
    additionalSetup(element)

    element.querySelectorAll(s"[${DataAttributes.refresh}]").collect({ case e: Element => e }) foreach { node =>
      refreshService.setupRefresh(node)
    }
  }

  @SuppressWarnings(Array(Wart.AsInstanceOf, Wart.Nothing))
  def setupInitial(body: html.Body): Unit = {

    additionalSetupInitial(body)

    body.on("click", s"a[${DataAttributes.progressive}]") { (e: MouseEvent, element: Element) =>
      hijaxService.ajaxLinkClick(e, element.asInstanceOf[html.Anchor])
    }

    body.on("click", s"form[${DataAttributes.progressive}] button[${DataAttributes.progressive}]") { (e: Event, element: Element) =>
      hijaxService.ajaxSubmitButtonClick(element.asInstanceOf[html.Button])
    }

    body.on("submit", s"form[${DataAttributes.progressive}]") { (e: Event, element: Element) =>
      hijaxService.ajaxFormSubmit(e, element.asInstanceOf[html.Form])
    }

    setup(body)
  }
} 
开发者ID:danielnixon,项目名称:progressive,代码行数:43,代码来源:EventHandlerSetupService.scala


示例2: ScalaJSExamples

//设置package包名称以及导入依赖的类
package com.outr.nextui.examples.browser

import com.outr.nextui.browser.ScalaJS
import com.outr.nextui.examples.Examples
import org.scalajs.dom.{Event, document, html}

import scala.scalajs.js.JSApp

object ScalaJSExamples extends JSApp {
  override def main(): Unit = {
    val div = document.createElement("div").asInstanceOf[html.Div]
    Examples().foreach { ui =>
      val a = document.createElement("a").asInstanceOf[html.Anchor]
      a.href = "#"
      a.addEventListener("click", {(evt: Event) =>
        document.body.removeChild(div)
        ScalaJS(ui)
      }, true)
      a.textContent = ui.name
      val p = document.createElement("p").asInstanceOf[html.Paragraph]
      p.appendChild(a)
      div.appendChild(p)
    }
    document.body.appendChild(div)
  }
} 
开发者ID:outr,项目名称:nextui,代码行数:27,代码来源:ScalaJSExamples.scala


示例3: ScalaJSImageView

//设置package包名称以及导入依赖的类
package com.outr.nextui.browser

import com.outr.nextui.ImageView
import com.outr.nextui.model.Image
import org.scalajs.dom.Event
import org.scalajs.dom.raw.HTMLImageElement

class ScalaJSImageView(val component: ImageView) extends ScalaJSComponent {
  override val impl: HTMLImageElement = create[HTMLImageElement]("img")

  override def initialize(): Unit = {
    super.initialize()

    component.image.attach {
      case img if img != Image.Empty => impl.src = img.resource.url.toString
      case _ => impl.src = ""
    }

    impl.addEventListener("load", {(evt: Event) =>
      updateSize(delayed = false)
    }, true)
  }
} 
开发者ID:outr,项目名称:nextui,代码行数:24,代码来源:ScalaJSImageView.scala


示例4: FunctionView

//设置package包名称以及导入依赖的类
package io.udash.demos.jquery.views

import io.udash._
import org.scalajs.dom.{Element, Event}

abstract class FunctionView extends FinalView {
  import scalatags.JsDom.all._

  protected val content: Element
  protected val script: () => Any

  override def getTemplate: Modifier =
    div(
      content,
      button(
        onclick :+= ((_: Event) => {
          script()
          false
        })
      )("Run script")
    )
} 
开发者ID:UdashFramework,项目名称:scala-js-jquery,代码行数:23,代码来源:FunctionView.scala


示例5: OnOneOffViewPresenter

//设置package包名称以及导入依赖的类
package io.udash.demos.jquery.views.functions

import io.udash._
import io.udash.demos.jquery.IndexState
import io.udash.demos.jquery.views.FunctionView
import io.udash.wrappers.jquery._
import org.scalajs.dom.{Element, Event}

object OnOneOffViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new OnOneOffView)


class OnOneOffView extends FunctionView {
  import scalatags.JsDom.all._

  val onCallback = (_: Element, _: JQueryEvent) =>
    jQ(".demo ul").append(li("This will be added on every click").render)
  val oneCallback = (_: Element, _: JQueryEvent) =>
    jQ(".demo ul").append(li("This will be added only once").render)

  override protected val content = div(cls := "demo")(
    h3(".on() & .one() & .off()"),
    button(id := "click", disabled := "disabled")("Click me"),
    ul(),
    button(
      id := "off",
      disabled := "disabled",
      onclick :+= ((_: Event) => {
        jQ(".demo #click")
          .off("click", onCallback)
          .off("click", oneCallback)
        false
      })
    )("Off")
  ).render

  override protected val script = () => {
    jQ(".demo #click")
      .on("click", onCallback)
      .one("click", oneCallback)

    jQ(".demo button")
      .prop("disabled", "")
  }
} 
开发者ID:UdashFramework,项目名称:scala-js-jquery,代码行数:45,代码来源:OnOneOffView.scala


示例6: AttrViewPresenter

//设置package包名称以及导入依赖的类
package io.udash.demos.jquery.views.functions

import io.udash._
import io.udash.demos.jquery.IndexState
import io.udash.demos.jquery.views.FunctionView
import io.udash.wrappers.jquery._
import org.scalajs.dom.{Element, Event}

object AttrViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AttrView)


class AttrView extends FunctionView {
  import scalatags.JsDom.all._

  override protected val content = div(cls := "demo")(
    h3(".attr() & .prop()"),
    input(id := "check1", tpe := "checkbox", checked := "checked"),
    label(`for` := "check1")("Check me"),
    p(),
    button(onclick :+= ((_: Event) => {
      jQ(".demo input").attr("data-checked", "checked").change()
      false
    }))(".attr(\"data-checked\", \"checked\")"),
    button(onclick :+= ((_: Event) => {
      jQ(".demo input").attr("data-checked", "").change()
      false
    }))(".attr(\"data-checked\", \"\")"),
    button(onclick :+= ((_: Event) => {
      jQ(".demo input").attr("data-checked", null).change()
      false
    }))(".attr(\"data-checked\", null)"), br(),
    button(onclick :+= ((_: Event) => {
      jQ(".demo input").prop("checked", true).change()
      false
    }))(".prop(\"checked\", true)"),
    button(onclick :+= ((_: Event) => {
      jQ(".demo input").prop("checked", false).change()
      false
    }))(".prop(\"checked\", false)")
  ).render

  override protected val script = () => {
    jQ(".demo input").change((input: Element, _: JQueryEvent) => {
      jQ(".demo p").html(
        s""".attr('data-checked'): ${jQ(input).attr("data-checked")}<br/>
           |.prop('checked'): ${jQ(input).prop("checked")}<br/>
           |.is(':checked'): ${jQ(input).is(":checked")}""".stripMargin
      )
    }).change()
  }
} 
开发者ID:UdashFramework,项目名称:scala-js-jquery,代码行数:52,代码来源:AttrView.scala


示例7: DeferredViewPresenter

//设置package包名称以及导入依赖的类
package io.udash.demos.jquery.views.functions

import io.udash._
import io.udash.demos.jquery.IndexState
import io.udash.demos.jquery.views.FunctionView
import io.udash.wrappers.jquery._
import org.scalajs.dom.Event

import scala.scalajs.js

object DeferredViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new DeferredView)


class DeferredView extends FunctionView {
  import scalatags.JsDom.all._

  var deferred: JQueryDeferred[js.Function1[Int, js.Any], Int] = null

  override protected val content = div(cls := "demo")(
    h3("Deferred"),
    div(
      div(id := "deferred")("???"),
      button(
        id := "resolve",
        disabled := "disabled",
        onclick := ((ev: Event) => {
          deferred.resolve(5)
        })
      )("Resolve(5)"),
      button(
        id := "reject",
        disabled := "disabled",
        onclick := ((ev: Event) => {
          deferred.reject(-5)
        })
      )("Reject(-5)"),
      button(
        id := "notify",
        disabled := "disabled",
        onclick := ((ev: Event) => {
          deferred.notify(1)
        })
      )("Notify(1)")
    )
  ).render

  override protected val script = () => {
    jQ(".demo button").prop("disabled", "")
    deferred = jQ.deferred[js.Function1[Int, js.Any], Int]()
    jQ("#deferred").text(s"Waiting...")
    deferred.done((i: Int) => jQ("#deferred").text(s"Done: $i"))
    deferred.fail((i: Int) => jQ("#deferred").text(s"Fail: $i"))
    deferred.progress((i: Int) => jQ("#deferred").text(s"Progress: $i"))
  }
} 
开发者ID:UdashFramework,项目名称:scala-js-jquery,代码行数:56,代码来源:DeferredView.scala


示例8: Group

//设置package包名称以及导入依赖的类
package scalajs.antdesign

import japgolly.scalajs.react.{CallbackTo, React, ReactComponentU_, ReactNode}
import org.scalajs.dom.Event

import scala.scalajs.js
import scala.scalajs.js.{Dynamic, Object}


  case class Group(onChange: js.UndefOr[Event => CallbackTo[Unit]] = js.undefined,
                   value: js.UndefOr[String] = js.undefined,
                   defaultValue: js.UndefOr[String] = js.undefined,
                   size: js.UndefOr[Size] = js.undefined) {
    def toJS: Object with Dynamic = {
      val p = js.Dynamic.literal()
      onChange.foreach { x =>
        p.updateDynamic("onChange")(
          (v1: Event) => x(v1).runNow()
        )
      }
      value.foreach { x =>
        p.updateDynamic("value")(x)
      }
      defaultValue.foreach { x =>
        p.updateDynamic("defaultValue")(x)
      }
      size.foreach { x =>
        p.updateDynamic("size")(x.id)
      }
      p
    }

    def apply(children: ReactNode*): ReactComponentU_ = {
      val f =
        React.asInstanceOf[js.Dynamic].createFactory(js.Dynamic.global.antd.Radio.Group)
      f(toJS, children.toJsArray).asInstanceOf[ReactComponentU_]
    }
  }
} 
开发者ID:mdedetrich,项目名称:scalajs-antdesign,代码行数:40,代码来源:Radio.scala


示例9: Checkbox

//设置package包名称以及导入依赖的类
package scalajs.antdesign

import japgolly.scalajs.react.{CallbackTo, React, ReactComponentU_, ReactNode}
import org.scalajs.dom.Event

import scala.scalajs.js
import scala.scalajs.js.{Dynamic, Object}


case class Checkbox(checked: js.UndefOr[Boolean] = js.undefined,
                    defaultChecked: js.UndefOr[Boolean] = js.undefined,
                    onChange: js.UndefOr[(Event) => CallbackTo[Unit]] = js.undefined) {
  def toJS: Object with Dynamic = {
    val p = js.Dynamic.literal()
    checked.foreach { x =>
      p.updateDynamic("checked")(x)
    }
    defaultChecked.foreach { x =>
      p.updateDynamic("defaultChecked")(x)
    }
    onChange.foreach { x =>
      p.updateDynamic("onChange")(x)
    }
    p
  }

  def apply(children: ReactNode*): ReactComponentU_ = {
    val f =
      React.asInstanceOf[js.Dynamic].createFactory(js.Dynamic.global.antd.Checkbox)
    f(toJS, children.toJsArray).asInstanceOf[ReactComponentU_]
  }
} 
开发者ID:mdedetrich,项目名称:scalajs-antdesign,代码行数:33,代码来源:Checkbox.scala


示例10: DoiView

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.gui.views

import scalatags.JsDom.all._
import se.lu.nateko.cp.doi.Doi
import se.lu.nateko.cp.doi.gui.DoiInfo
import se.lu.nateko.cp.doi.gui.DoiAction
import org.scalajs.dom.Event
import org.scalajs.dom.console
import se.lu.nateko.cp.doi.gui.SelectDoi
import se.lu.nateko.cp.doi.gui.DoiRedux
import se.lu.nateko.cp.doi.gui.ThunkActions

class DoiView(doi: Doi, d: DoiRedux.Dispatcher) {

	private[this] var info: Option[DoiInfo] = None
	private[this] var isSelected = false

	private val doiListIcon = span(cls := doiListIconClass).render

	private def doiListIconClass = "glyphicon glyphicon-triangle-" +
		(if(isSelected) "bottom" else "right")

	private val selectDoi: Event => Unit = e => d.dispatch(ThunkActions.selectDoiFetchInfo(doi))

	private val panelBody = div(cls := "panel-body").render

	val element = div(cls := "panel panel-default")(
		div(cls := "panel-heading", onclick := selectDoi, cursor := "pointer")(
			doiListIcon,
			span(cls := "panel-title")(" " + doi.toString)
		),
		panelBody
	).render

	private def updateContentVisibility(): Unit = {
		val display = if(isSelected && info.isDefined) "block" else "none"
		panelBody.style.display = display
	}

	def setSelected(is: Boolean): Unit = {
		isSelected = is
		doiListIcon.className = doiListIconClass
		updateContentVisibility()
	}

	def supplyInfo(doiInfo: DoiInfo): Unit = if(!info.contains(doiInfo)){
		info = Some(doiInfo)
		updateContentVisibility()
		panelBody.innerHTML = ""
		val infoView = new DoiInfoView(doiInfo, d)
		panelBody.appendChild(infoView.element)
	}
	updateContentVisibility()
} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:55,代码来源:DoiView.scala


示例11: NameWidget

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.gui.widgets

import se.lu.nateko.cp.doi.meta.Name
import scalatags.JsDom.all._
import se.lu.nateko.cp.doi.meta.PersonalName
import se.lu.nateko.cp.doi.meta.GenericName
import org.scalajs.dom.Event
import org.scalajs.dom.Element
import se.lu.nateko.cp.doi.gui.widgets.generic.EntityWidget
import se.lu.nateko.cp.doi.gui.widgets.generic.TextInputWidget
import se.lu.nateko.cp.doi.gui.views.Bootstrap

class NameWidget(init: Name, protected val updateCb: Name => Unit) extends EntityWidget[Name]{

	private[this] var _name = init

	private def isPersonal: Boolean = _name match{
		case _: PersonalName => true
		case _: GenericName => false
	}

	private def getNameElem: Element = _name match{
		case pn: PersonalName => new PersonalNameWidget(pn, newPn => {
				_name = newPn
				updateCb(_name)
			}).element
		case gn: GenericName => new TextInputWidget(gn.name, newGn => {
				_name = GenericName(newGn)
				updateCb(_name)
			}).element
	}

	private var nameElem = getNameElem

	private def checkedModifier(personal: Boolean) = if(personal == isPersonal) Seq(checked := true) else Nil

	private def changeNameType(personal: Boolean): Event => Unit = e => if(isPersonal != personal){
		_name = if(personal) PersonalName("", "") else GenericName("")
		val newNameElem = getNameElem
		nameElem.parentNode.replaceChild(newNameElem, nameElem)
		nameElem = newNameElem
		updateCb(_name)
	}

	private def nameTypeOption(personal: Boolean) =
		input(tpe := "radio", name := "nameType", onchange := changeNameType(personal))(checkedModifier(personal))

	val element = Bootstrap.basicPanel(
		Bootstrap.propValueRow(strong("Name type"))(
			form(nameTypeOption(true), " Personal name", br, nameTypeOption(false), " Organizational name")
		)(paddingBottom := 15),
		Bootstrap.propValueRow(strong("Name"))(nameElem)
	).render
} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:55,代码来源:NameWidget.scala


示例12: IntInputWidget

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.gui.widgets.generic

import org.scalajs.dom.Event
import scalatags.JsDom.all._


class IntInputWidget(init: Int, protected val updateCb: Int => Unit) extends EntityWidget[Int] {

	val element = input(tpe := "text", cls := "form-control", value := init.toString).render

	element.onkeyup = (_: Event) => {
		try{
			val newVal = element.value.toInt
			highlightError(element, None)
			updateCb(newVal)
		}catch{
			case _: Throwable =>
				highlightError(element, Some("Not a valid integer"))
				updateCb(init)
		}
	}

} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:24,代码来源:IntInputWidget.scala


示例13: MultiEntitiesEditWidget

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.gui.widgets.generic

import scalatags.JsDom.all._
import scala.collection.mutable.Buffer
import org.scalajs.dom.Event
import se.lu.nateko.cp.doi.gui.views.Bootstrap

abstract class MultiEntitiesEditWidget[E, W <: EntityWidget[E]](initValues: Seq[E], cb: Seq[E] => Unit){

	protected val title: String
	protected def makeWidget(value: E, updateCb: E => Unit): W
	protected def defaultValue: E
	protected val minAmount: Int

	private val widgets = Buffer.empty[RemovableEntityWidget[E]]

	private def setRemovability(): Unit = if(minAmount > 0) {
		widgets.foreach(_.setRemovability(widgets.length > minAmount))
	}

	private def notifyUpstream(): Unit = cb(widgets.map(_.entityValue))

	private val widgetsParent = div(cls := "col-md-11").render

	private def produceWidget(value: E): Unit = {
		val widgetFactory: (E => Unit) => W = makeWidget(value, _)

		val newWidget = new RemovableEntityWidget[E](widgetFactory, value, _ => notifyUpstream(), widget => {
			widgets -= widget
			widgetsParent.removeChild(widget.element)
			setRemovability()
			notifyUpstream()
		})
		widgetsParent.appendChild(newWidget.element)
		widgets += newWidget
	}
	initValues.foreach(produceWidget)
	setRemovability()

	private val addWidget: Event => Unit = (_: Event) => {
		produceWidget(defaultValue)
		setRemovability()
		notifyUpstream()
	}

	val element = Bootstrap.basicPanel(
		div(cls := "row")(
			div(cls := "col-md-1")(
				span(strong(title)),
				raw("&nbsp;"),
				button(tpe := "button", cls := "btn btn-success", onclick := addWidget, marginBottom := 5)(
					span(cls := "glyphicon glyphicon-plus")
				)
			),
			widgetsParent
		)
	)

} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:60,代码来源:MultiEntitiesEditWidget.scala


示例14: RemovableEntityWidget

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.gui.widgets.generic

import org.scalajs.dom.Event
import scalatags.JsDom.all._
import se.lu.nateko.cp.doi.gui.views.Bootstrap

class RemovableEntityWidget[E](
	widgetFactory: (E => Unit) => EntityWidget[E],
	init: E,
	updateCb: E => Unit,
	removeCb: RemovableEntityWidget[E] => Unit
){
	private[this] var _entityValue: E = init
	def entityValue = _entityValue

	private[this] val widget = widgetFactory((e: E) => {
		_entityValue = e
		updateCb(e)
	})

	private[this] val removeButton =
		button(tpe := "button", cls := "btn btn-warning")(
			span(cls := "glyphicon glyphicon-remove")
		).render

	removeButton.onclick = (_: Event) => removeCb(this)

	def setRemovability(removable: Boolean): Unit = {
		removeButton.disabled = !removable
	}

	val element = Bootstrap.basicPanel(
		div(cls := "row")(
			div(cls := "col-md-11")(widget.element),
			div(cls := "col-md-1 spacyrow")(removeButton)
		)
	).render
} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:39,代码来源:RemovableEntityWidget.scala


示例15: SelectOption

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.gui.widgets.generic

import org.scalajs.dom.Event
import scalatags.JsDom.all._
import SelectWidget._

case class SelectOption[T](value: Option[T], id: String, label: String)

class SelectWidget[T](
	options: IndexedSeq[SelectOption[T]],
	init: Option[T],
	protected val updateCb: Option[T] => Unit
) extends EntityWidget[Option[T]] {

	val element = select(cls := "form-control")(options.map(optionElem)).render

	element.onchange = (_: Event) => updateCb(options(element.selectedIndex).value)

	element.selectedIndex = options.indexWhere(_.value == init)
}

object SelectWidget{

	def optionElem[T](optInfo: SelectOption[T]) = {
		option(value := optInfo.id)(optInfo.label)
	}

	def selectOptions(enum: Enumeration, noValueLabelOpt: Option[String]): IndexedSeq[SelectOption[enum.Value]] = {
		noValueLabelOpt.map(SelectOption[enum.Value](None, "", _)).toIndexedSeq ++
		enum.values.toIndexedSeq.map(v =>
			SelectOption(Some(v), v.toString, v.toString)
		)
	}

	def selectOptions[T](noValueLabelOpt: Option[String])(selectVals: T*): IndexedSeq[SelectOption[T]] = {
		noValueLabelOpt.map(SelectOption[T](None, "", _)).toIndexedSeq ++
		selectVals.map(v =>
			SelectOption(Some(v), v.toString, v.toString)
		)
	}

} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:43,代码来源:SelectWidget.scala


示例16: JQueryEventsDemo

//设置package包名称以及导入依赖的类
package io.udash.web.guide.views.ext.demo

import io.udash._
import io.udash.bootstrap.UdashBootstrap.ComponentId
import io.udash.bootstrap.button.{UdashButton, UdashButtonGroup}
import io.udash.web.guide.Context
import io.udash.web.guide.styles.partials.GuideStyles
import io.udash.wrappers.jquery._
import org.scalajs.dom
import org.scalajs.dom.Event

import scala.language.postfixOps

object JQueryEventsDemo {
  import scalacss.ScalatagsCss._
  import scalatags.JsDom.all._
  import Context._

  val onCallback = (_: dom.Element, _: JQueryEvent) =>
    jQ("#jquery-events-demo ul").append(li("This will be added on every click").render)
  val oneCallback = (_: dom.Element, _: JQueryEvent) =>
    jQ("#jquery-events-demo ul").append(li("This will be added only once").render)

  def apply(): dom.Element = {
    val content = div(id := "jquery-events-demo", GuideStyles.get.frame, GuideStyles.get.useBootstrap)(
      ul(),
      br,
      UdashButtonGroup()(
        UdashButton(componentId = ComponentId("click"))("Click me").render,
        UdashButton(componentId = ComponentId("off"))(
          onclick :+= ((_: Event) =>
            jQ("#jquery-events-demo #click")
              .off("click", onCallback)
              .off("click", oneCallback)
          ), "Off"
        ).render
      ).render
    ).render

    jQ(content).find("#click")
      .on("click", onCallback)
      .one("click", oneCallback)

    content
  }
} 
开发者ID:UdashFramework,项目名称:udash-guide,代码行数:47,代码来源:JQueryEventsDemo.scala


示例17: Utils

//设置package包名称以及导入依赖的类
package todomvc

import org.scalajs.dom.Event
import org.scalajs.dom.raw.HTMLInputElement

object Utils {

  object KeyCodes {
    val Enter = 13
    val Escape = 27
  }

  def extractInputTarget(event: Event): HTMLInputElement = {
    event.currentTarget match {
      case x: HTMLInputElement => x
      case x => throw new IllegalArgumentException(s"Waiting for HTMLInputElement, but got $x")
    }
  }

  def pluralize(word: String, count: Int): String = {
    if (count == 1) word else word + "s"
  }
} 
开发者ID:LMnet,项目名称:scala-js-preact,代码行数:24,代码来源:Utils.scala


示例18: IndexViewPresenter

//设置package包名称以及导入依赖的类
package ch.wsl.box.client.views

import io.udash._
import ch.wsl.box.client._
import org.scalajs.dom.{Element, Event}
import ch.wsl.box.client.styles.GlobalStyles

import scalacss.ScalatagsCss._

object IndexViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new IndexView)

class IndexView extends View {
  import ch.wsl.box.client.Context._
  import scalatags.JsDom.all._

  import org.scalajs.dom.File
  val acceptMultipleFiles: Property[Boolean] = Property(false)
  val selectedFiles: SeqProperty[File] = SeqProperty(Seq.empty)

  val fileUploader = new FileUploader(new Url("/test"))

  val input = FileInput("file", acceptMultipleFiles, selectedFiles)()


  private val content = div(
    h2("Postgres Box Client"),
    input,
    h4("Selected files"),
    ul(
      repeat(selectedFiles)(file => {
        li(file.get.name).render
      })
    ),
    button(onclick :+= ((e:Event) => fileUploader.upload(input)),"Send")
  )


  override def getTemplate: Modifier = content

  override def renderChild(view: View): Unit = {}
} 
开发者ID:Insubric,项目名称:box,代码行数:42,代码来源:IndexView.scala


示例19: MenuLink

//设置package包名称以及导入依赖的类
package ch.wsl.box.client.views.components

import ch.wsl.box.client.{IndexState, LoginState, RoutingState}
import ch.wsl.box.client.styles.GlobalStyles
import org.scalajs.dom.raw.Element

import scalatags.JsDom.all._
import scalacss.ScalatagsCss._
import ch.wsl.box.client.Context._
import ch.wsl.box.client.utils.Session
import io.udash.bootstrap.BootstrapStyles
import io.udash.bootstrap.dropdown.UdashDropdown
import io.udash.bootstrap.navs.{UdashNav, UdashNavbar}
import io.udash.properties.seq.SeqProperty
import io.udash._
import org.scalajs.dom.Event

case class MenuLink(name:String, state:RoutingState)

object Header {

  import ch.wsl.box.client.Context

  private def linkFactory(l: MenuLink) =
    a(href := l.state.url)(span(l.name)).render


  def langs = Seq("it","de","fr","en")


  def navbar(title:String, links:Seq[MenuLink]) = {
    header(
      div(BootstrapStyles.pullLeft)(b(title)),
      div(BootstrapStyles.pullRight) (
        links.map{link =>
          a(href := link.state.url)(
            link.name
          )
        },
        if(Session.isLogged()) {
          a(onclick :+= ((e:Event) => Session.logout() ),"Logout")
        } else frag(),
        langs.map{ l =>
          a(onclick :+= ((e:Event) => Session.setLang(l) ),l)
        }
      )
    ).render
  }
} 
开发者ID:Insubric,项目名称:box,代码行数:50,代码来源:Header.scala


示例20: Socket

//设置package包名称以及导入依赖的类
package sharednodejsapis

import org.scalajs.dom.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobal, JSImport, ScalaJSDefined}
import scala.scalajs.js.|

@ScalaJSDefined
trait ErrorEvent extends Event {
  val stack: String
}

@ScalaJSDefined
trait RInfo extends js.Object {
  val address: String
  val port: Int
  val family: String
}

@ScalaJSDefined
trait Address extends js.Object {
  val address: String
  val port: Int
}

@js.native
@JSGlobal("dgram.Socket")
abstract class Socket extends EventEmitter {
  def address(): Address = js.native

  def bind(port: Int, address: String = js.native): Unit = js.native

  def close(): Unit = js.native

  def send(msg: String | Buffer | js.Array[Buffer], port: Int, address: String): Unit = js.native
  def send(msg: String | Buffer | js.Array[Buffer], port: Int, address: String, callback: js.Function): Unit = js.native
  def send(msg: String | Buffer | js.Array[Buffer], offset: Int, length: Int, port: Int, address: String): Unit = js.native
  def send(msg: String | Buffer | js.Array[Buffer], offset: Int, length: Int,
           port: Int, address: String, callback: js.Function): Unit = js.native
}

@js.native
@JSImport("dgram", JSImport.Namespace)
object DgramModule extends js.Object {
  def createSocket(t: String): Socket = js.native
} 
开发者ID:sherpal,项目名称:oh-hell-card-game,代码行数:48,代码来源:Socket.scala



注:本文中的org.scalajs.dom.Event类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ConfigObject类代码示例发布时间:2022-05-23
下一篇:
Scala Identify类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap