本文整理汇总了Scala中org.scalajs.dom.Element类的典型用法代码示例。如果您正苦于以下问题:Scala Element类的具体用法?Scala Element怎么用?Scala Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: 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)
}
}
}
示例2: 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)
}
}
示例3: ConfigurationBox
//设置package包名称以及导入依赖的类
package ui
import org.scalajs.dom.{Element, document}
object ConfigurationBox {
def create(triggerCallback: SimulationTrigger => Unit): Element = {
val configBox = document.createElement("form")
configBox.id = "params-box"
configBox.appendChild(WidthBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(DensityBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(ProbabilityBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(SpeedBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(SpeedStepBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(MinimumTimeoutBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(CountedIterationsBox.setupUI(SimulationTriggeringButtons))
configBox.appendChild(SimulationTriggeringButtons.setupUI(triggerCallback))
configBox
}
}
示例4: DungeonUI
//设置package包名称以及导入依赖的类
package mazes.webapp
import mazes.generators.DungeonGenerator.Map
import org.scalajs.dom.Element
abstract class DungeonUI(val base:Element,val speed:Int){
def setupUI()
def dungeonToText(d: Map): String = {
var r = " "
for (j <- 0 until d.columns) {
r+=(j % 10).toString()
}
r += "\n"
for (i <- 0 until d.rows) {
r+=(i % 10).toString()
for (j <- 0 until d.columns) {
r += d(i, j).asciiArt + ""
}
r += "\n"
}
return r
}
}
示例5: Context
//设置package包名称以及导入依赖的类
package org.codeape.sc.frontend
import io.udash._
import io.udash.wrappers.jquery._
import org.codeape.sc.shared.MainServerREST
import org.scalajs.dom
import org.scalajs.dom.{Element, document}
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scala.util.Try
object Context {
implicit val executionContext = scalajs.concurrent.JSExecutionContext.Implicits.queue
private val routingRegistry = new RoutingRegistryDef
private val viewPresenterRegistry = new StatesToViewPresenterDef
implicit val applicationInstance = new Application[RoutingState](routingRegistry, viewPresenterRegistry, RootState)
import io.udash.rest._
val port = Try(dom.window.location.port.toInt).getOrElse(80)
val host = dom.window.location.hostname
val restServer = DefaultServerREST[MainServerREST](host, port, "/api/")
}
object Init extends JSApp with StrictLogging {
import Context._
@JSExport
override def main(): Unit = {
logger.info("StampClock started")
jQ(document).ready((_: Element) => {
val appRoot = jQ("#application").get(0)
if (appRoot.isEmpty) {
logger.error("Application root element not found! Check your index.html file!")
} else {
applicationInstance.run(appRoot.get)
}
})
}
}
示例6: TabOverride
//设置package包名称以及导入依赖的类
package com.karasiq.taboverridejs
import org.scalajs.dom
import org.scalajs.dom.Element
import scala.scalajs.js
import scala.scalajs.js.annotation.JSName
@js.native
@JSName("tabOverride")
object TabOverride extends TabOverride
@js.native
trait TabOverride extends js.Object {
def set(textArea: dom.html.TextArea): Unit = js.native
def tabSize(size: Int = ???): Int = js.native
def autoIndent(value: Boolean = ???): Boolean = js.native
def tabKey(key: Int = ???, mod: js.Array[String] = ???): Int = js.native
def addExtension(hook: String, function: js.Function): Unit = js.native
def delay(delay: Int = ???): Int = js.native
def escape(escape: Boolean = ???): Boolean = js.native
def style: TabOverrideStyle = js.native
}
@js.native
trait TabOverrideStyle extends js.Object {
def apply(enabled: Boolean = ???): Boolean = js.native
def enabledClass(cls: String = ???): String = js.native
def activeClass(cls: String = ???): String = js.native
def hardTabSize(tab: Int = ???): Int = js.native
def utils: TabOverrideStyleUtils = js.native
}
@js.native
trait TabOverrideStyleUtils extends js.Object {
def hardTabSizeSupported: Boolean = js.native
def addEnabledClass(e: Element): Unit = js.native
def addActiveClass(e: Element): Unit = js.native
def removeEnabledClass(e: Element): Unit = js.native
def removeActiveClass(e: Element): Unit = js.native
def updateEnabledClass(cls: String = ???): Unit = js.native
def updateActiveClass(cls: String = ???): Unit = js.native
def addTabSizeCSSSelector(cls: String = ???): Unit = js.native
def removeTabSizeCSSSelector(cls: String = ???): Unit = js.native
}
示例7: Init
//设置package包名称以及导入依赖的类
package com.oni.udash
import acyclic.file
import io.udash._
import io.udash.wrappers.jquery._
import org.scalajs.dom.{ Element, document }
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scalacss.Defaults._
import scalacss.ScalatagsCss._
import scalatags.JsDom._
import com.oni.udash.styles._
import com.oni.udash.styles.OniStyles2
import com.oni.udash.styles.GlobalStyles
import com.oni.udash.styles.DemoStyles
import com.oni.udash.styles.partials.FooterStyles
import com.oni.udash.styles.partials.HeaderStyles
import org.scalajs.dom.raw.HTMLStyleElement
object Init extends JSApp with StrictLogging {
import Context._
@JSExport
override def main(): Unit = {
jQ(document).ready((_: Element) => {
val appRoot = jQ("#application").get(0)
if (appRoot.isEmpty) {
logger.error("Application root element not found! Check your index.html file!")
} else {
applicationInstance.run(appRoot.get)
jQ(GlobalStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(DemoStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(OniStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(OniStyles2.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(CsStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(CsStyles2.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(FooterStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(HeaderStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
}
})
}
}
示例8: RootViewPresenter
//设置package包名称以及导入依赖的类
package com.oni.udash.views
import org.scalajs.dom.Element
import com.oni.udash.styles.GlobalStyles
import com.oni.udash.views.components.Footer
import com.oni.udash.views.components.Header
import com.oni.udash.RootState
import io.udash.DefaultViewPresenterFactory
import io.udash.View
import scalacss.ScalatagsCss.styleaToJsDomTag
import scalatags.JsDom.all.div
import scalatags.JsDom.tags2.main
object RootViewPresenter extends DefaultViewPresenterFactory[RootState.type](() => new RootView)
class RootView extends View {
import scalatags.JsDom.all._
private val child: Element = div().render
private val content = div(
Header.getTemplate,
main(GlobalStyles.main)(
div(GlobalStyles.body)(
//h1("Programming Paradigms"),
child)),
Footer.getTemplate)
override def getTemplate: Modifier = content
override def renderChild(view: View): Unit = {
import io.udash.wrappers.jquery._
jQ(child).children().remove()
view.getTemplate.applyTo(child)
}
}
示例9: 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")
)
}
示例10: EachViewPresenter
//设置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
object EachViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new EachView)
class EachView extends FunctionView {
import scalatags.JsDom.all._
override protected val content = div(cls := "demo")(
h3(".each()"),
div("Click button"),
div("to iterate through"),
div("these divs.")
).render
override protected val script = () => {
jQ(".demo div").each((el: Element, idx: Int) => {
jQ(el).replaceWith(span(s"${el.textContent} ").render)
})
}
}
示例11: 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", "")
}
}
示例12: 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()
}
}
示例13: 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
}
示例14: rxToFrag
//设置package包名称以及导入依赖的类
package rip.hansolo.script.util
import org.scalajs.dom.Element
import rx.{Rx, Var}
import scala.scalajs.js
import scalatags.JsDom.all._
implicit def rxToFrag[T](r: Rx[T])(implicit converter: T => Frag): Frag = {
def rToFrag = span(r.now).render
var current = rToFrag
r triggerLater {
val newCurrent = rToFrag
js.Dynamic.global.last = current
current.parentNode.replaceChild(newCurrent, current)
current = newCurrent
}
current
}
}
object MdlConverter {
implicit def rxToFrag[T](r: Rx[T])(implicit converter: T => Frag): Frag = {
val upgrader = js.Dynamic.global.componentUpgrader
def rToFrag = span(r.now).render
if(!js.isUndefined(upgrader)) upgrader.upgradeElement(rToFrag)
var current = rToFrag
r triggerLater {
val newCurrent = rToFrag
js.Dynamic.global.last = current
current.parentNode.replaceChild(newCurrent, current)
current = newCurrent
}
current
}
}
implicit def VarAttrValue[T: AttrValue] = new AttrValue[Var[T]]{
def apply(t: Element, a: Attr, r: Var[T]): Unit = {
r.trigger{ implicitly[AttrValue[T]].apply(t, a, r.now) }
}
}
implicit def RxAttrValue[T: AttrValue] = new AttrValue[Rx[T]]{
def apply(t: Element, a: Attr, r: Rx[T]): Unit = {
r.trigger{ implicitly[AttrValue[T]].apply(t, a, r.now) }
}
}
implicit def RxDynamicAttrValue[T: AttrValue] = new AttrValue[Rx.Dynamic[T]]{
def apply(t: Element, a: Attr, r: Rx.Dynamic[T]): Unit = {
r.trigger{ implicitly[AttrValue[T]].apply(t, a, r.now) }
}
}
}
示例15: ErrorViewPresenter
//设置package包名称以及导入依赖的类
package io.udash.web.guide.views
import io.udash._
import io.udash.core.DomWindow
import io.udash.web.commons.styles.GlobalStyles
import io.udash.web.commons.styles.components.FooterStyles
import io.udash.web.commons.styles.utils.StyleConstants
import io.udash.web.guide.Context._
import io.udash.web.guide.styles.partials.{GuideStyles, HeaderStyles}
import io.udash.web.guide.{ErrorState, IntroState}
import io.udash.wrappers.jquery._
import org.scalajs.dom.Element
import scalacss.ScalatagsCss._
import scalatags.JsDom.tags2._
object ErrorViewPresenter extends DefaultViewPresenterFactory[ErrorState.type](() => new ErrorView)
class ErrorView extends FinalView {
import scalatags.JsDom.all._
private val content = section(GuideStyles.get.sectionError)(
div(GlobalStyles.body)(
div(GuideStyles.get.errorInner)(
p(GuideStyles.get.errorHead)(
span(GlobalStyles.red)("Oops! 404"), br(),
span("The link doesn't work. Or maybe it never has? You can still ", a(GlobalStyles.grey, href := "assets/pdf/origami_crane_printok.pdf", target := "_blank")("make origami")), br(),
span("... or go "), a(GlobalStyles.red, href := IntroState.url)("home"), span("")
)
)
)
).render
private lazy val jqTemplate = jQ(content)
val window = jQ(DomWindow)
window.resize((element: Element, _: JQueryEvent) => onResize())
onResize()
private def onResize(): Unit = {
if (window.width <= StyleConstants.MediaQueriesBounds.TabletLandscapeMax) {
val h = window.height - jQ(s".${FooterStyles.get.footer.htmlClass}").outerHeight() - jQ(s".${HeaderStyles.get.header.htmlClass}").outerHeight()
jqTemplate.css("min-height", s"${h}px")
}
}
override def getTemplate: Modifier = content
}