Static types for the jQuery API for Scala.js programs.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
project
src
.gitignore
.travis.yml
LICENSE
README.md
build.sbt

README.md

scala-js-jquery Build Status Join the chat at https://gitter.im/UdashFramework/scala-js-jquery

Static types for the jQuery API for Scala.js programs.

Usage

Add the following dependency to your SBT build:

libraryDependencies += "io.udash" %%% "udash-jquery" % "2.0.0"

then import the jQuery package:

import io.udash.wrappers.jquery._

Since version 2.0.0 the wrapper does not force JS dependency on jQuery. You have to add it manually by:

  • explicit link in your index.html.
<script src="https://code.jquery.com/jquery-3.3.1.min.js" 
        integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" 
        crossorigin="anonymous"></script>
jsDependencies +=
  "org.webjars" % "jquery" % "3.3.1" / "3.3.1/jquery.js" minified "3.3.1/jquery.min.js"

Examples

import io.udash.wrappers.jquery._

jQ("#elementId")
  .hide(AnimationOptions(
    duration = Some(3000),
    easing = Some(EasingFunction.linear)
  ))
  .show(1500, EasingFunction.swing)
import io.udash.wrappers.jquery._

val element: JQuery = jQ("#id")
element.text("Text content")
element.attr("example-attr", "value")
element.attr("example-attr") match {
  case Some(value) => println(s"Attribute value: $value")
  case None => println("Attribute not found!")
}
import io.udash.wrappers.jquery._

val callbacks = jQ.callbacks[js.Function1[(Int, Int), js.Any], (Int, Int)]()
callbacks.add((t: (Int, Int)) => {
  val (a, b) = t
  jQ("#plus").append(li(s"$a + $b = ${a+b}").render)
})
callbacks.add((t: (Int, Int)) => {
  val (a, b) = t
  jQ("#minus").append(li(s"$a - $b = ${a-b}").render)
})
callbacks.add((t: (Int, Int)) => {
  val (a, b) = t
  jQ("#mul").append(li(s"$a * $b = ${a*b}").render)
})
callbacks.add((t: (Int, Int)) => {
  val (a, b) = t
  jQ("#div").append(li(s"$a / $b = ${a/b}").render)
})

callbacks.fire(1, 1)
callbacks.fire(3, 3)
callbacks.fire(7, 4)

callbacks.disable()
callbacks.fire(1, 2)