diff --git a/src/main/scala/io/udash/wrappers/jquery/JQuery.scala b/src/main/scala/io/udash/wrappers/jquery/JQuery.scala index fb1a94e..3e2b9c4 100644 --- a/src/main/scala/io/udash/wrappers/jquery/JQuery.scala +++ b/src/main/scala/io/udash/wrappers/jquery/JQuery.scala @@ -54,7 +54,7 @@ trait JQuery extends js.Object { /** Perform a custom animation of a set of CSS properties.
* See: jQuery Docs */ - private[jquery] def animate(properties: js.Dictionary[Any], duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def animate(properties: js.Dictionary[Any], duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Perform a custom animation of a set of CSS properties.
* See: jQuery Docs */ @@ -218,11 +218,11 @@ trait JQuery extends js.Object { /** Display the matched elements by fading them to opaque.
* See: jQuery Docs */ - def fadeIn(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def fadeIn(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Display the matched elements by fading them to opaque.
* See: jQuery Docs */ - private[jquery] def fadeIn(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def fadeIn(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Display the matched elements by fading them to opaque.
* See: jQuery Docs */ @@ -230,11 +230,11 @@ trait JQuery extends js.Object { /** Hide the matched elements by fading them to transparent.
* See: jQuery Docs */ - def fadeOut(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def fadeOut(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Hide the matched elements by fading them to transparent.
* See: jQuery Docs */ - private[jquery] def fadeOut(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def fadeOut(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Hide the matched elements by fading them to transparent.
* See: jQuery Docs */ @@ -250,7 +250,7 @@ trait JQuery extends js.Object { /** Adjust the opacity of the matched elements.
* See: jQuery Docs */ - def fadeTo(duration: Int, opacity: Double, easing: String): JQuery = js.native + def fadeTo(duration: Int, opacity: Double, easing: EasingFunction): JQuery = js.native /** Adjust the opacity of the matched elements.
* See: jQuery Docs */ @@ -258,11 +258,11 @@ trait JQuery extends js.Object { /** Display or hide the matched elements by animating their opacity.
* See: jQuery Docs */ - def fadeToggle(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def fadeToggle(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Display or hide the matched elements by animating their opacity.
* See: jQuery Docs */ - private[jquery] def fadeToggle(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def fadeToggle(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Display or hide the matched elements by animating their opacity.
* See: jQuery Docs */ @@ -336,11 +336,11 @@ trait JQuery extends js.Object { /** Hide the matched elements.
* See: jQuery Docs */ - def hide(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def hide(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Hide the matched elements.
* See: jQuery Docs */ - private[jquery] def hide(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def hide(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Hide the matched elements.
* See: jQuery Docs */ @@ -729,11 +729,11 @@ trait JQuery extends js.Object { /** Display the matched elements.
* See: jQuery Docs */ - def show(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def show(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Display the matched elements.
* See: jQuery Docs */ - private[jquery] def show(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def show(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Display the matched elements.
* See: jQuery Docs */ @@ -749,11 +749,11 @@ trait JQuery extends js.Object { /** Display the matched elements with a sliding motion.
* See: jQuery Docs */ - def slideDown(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def slideDown(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Display the matched elements with a sliding motion.
* See: jQuery Docs */ - private[jquery] def slideDown(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def slideDown(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Display the matched elements with a sliding motion.
* See: jQuery Docs */ @@ -761,11 +761,11 @@ trait JQuery extends js.Object { /** Display or hide the matched elements with a sliding motion.
* See: jQuery Docs */ - def slideToggle(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def slideToggle(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Display or hide the matched elements with a sliding motion.
* See: jQuery Docs */ - private[jquery] def slideToggle(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def slideToggle(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Display or hide the matched elements with a sliding motion.
* See: jQuery Docs */ @@ -773,11 +773,11 @@ trait JQuery extends js.Object { /** Hide the matched elements with a sliding motion.
* See: jQuery Docs */ - def slideUp(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def slideUp(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Hide the matched elements with a sliding motion.
* See: jQuery Docs */ - private[jquery] def slideUp(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def slideUp(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Hide the matched elements with a sliding motion.
* See: jQuery Docs */ @@ -813,11 +813,11 @@ trait JQuery extends js.Object { /** Display or hide the matched elements.
* See: jQuery Docs */ - def toggle(duration: Int = js.native, easing: String = js.native): JQuery = js.native + def toggle(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native /** Display or hide the matched elements.
* See: jQuery Docs */ - private[jquery] def toggle(duration: Int, easing: String, callback: js.ThisFunction0[Element, Any]): JQuery = js.native + private[jquery] def toggle(duration: Int, easing: EasingFunction, callback: js.ThisFunction0[Element, Any]): JQuery = js.native /** Display or hide the matched elements.
* See: jQuery Docs */ @@ -919,28 +919,6 @@ object JQuery { private val registrations: mutable.Map[Element, mutable.Buffer[CallbackRegistrationRef]] = mutable.Map[Element, mutable.Buffer[CallbackRegistrationRef]]() - case class AnimationOptions(duration: Option[Int] = None, easing: String = null, queue: Option[Boolean] = None, - step: (Int, js.Dynamic) => Any = null, progress: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Int, Int) => js.Any = null, - complete: () => js.Any = null, start: JQueryPromise[js.Function1[js.Any, js.Any], js.Any] => js.Any = null, - done: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => js.Any = null, - fail: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => js.Any = null, - always: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => js.Any = null) { - def toJSDictionary: js.Dictionary[Any] = { - val r = js.Dictionary[Any]() - if (duration.isDefined) r.update("duration", duration.get) - if (easing != null) r.update("easing", easing) - if (queue.isDefined) r.update("queue", queue.get) - if (step != null) r.update("step", step) - if (progress != null) r.update("progress", progress) - if (complete != null) r.update("complete", complete) - if (start != null) r.update("start", start) - if (done != null) r.update("done", done) - if (fail != null) r.update("fail", fail) - if (always != null) r.update("always", always) - r - } - } - implicit class JQueryWrapper(private val jquery: JQuery) { import js.JSConverters._ @@ -964,7 +942,7 @@ object JQuery { /** Perform a custom animation of a set of CSS properties.
* See: jQuery Docs */ - def animate(properties: Map[String, Any], duration: Int = 400, easing: String = "swing", callback: (Element) => Any = (_) => {}): JQuery = jquery.animate(properties.toJSDictionary, duration, easing, callback) + def animate(properties: Map[String, Any], duration: Int = 400, easing: EasingFunction = EasingFunction.swing, callback: (Element) => Any = (_) => {}): JQuery = jquery.animate(properties.toJSDictionary, duration, easing, callback) /** Perform a custom animation of a set of CSS properties.
* See: jQuery Docs */ @@ -1070,7 +1048,7 @@ object JQuery { /** Display the matched elements by fading them to opaque.
* See: jQuery Docs */ - def fadeIn(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.fadeIn(duration, easing, callback) + def fadeIn(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.fadeIn(duration, easing, callback) /** Display the matched elements by fading them to opaque.
* See: jQuery Docs */ @@ -1078,7 +1056,7 @@ object JQuery { /** Hide the matched elements by fading them to transparent.
* See: jQuery Docs */ - def fadeOut(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.fadeOut(duration, easing, callback) + def fadeOut(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.fadeOut(duration, easing, callback) /** Hide the matched elements by fading them to transparent.
* See: jQuery Docs */ @@ -1090,11 +1068,11 @@ object JQuery { /** Adjust the opacity of the matched elements.
* See: jQuery Docs */ - def fadeTo(duration: Int, opacity: Double, easing: String, callback: (Element) => Any): JQuery = jquery.fadeTo(duration, opacity, easing, callback) + def fadeTo(duration: Int, opacity: Double, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.fadeTo(duration, opacity, easing, callback) /** Display or hide the matched elements by animating their opacity.
* See: jQuery Docs */ - def fadeToggle(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.fadeToggle(duration, easing, callback) + def fadeToggle(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.fadeToggle(duration, easing, callback) /** Display or hide the matched elements by animating their opacity.
* See: jQuery Docs */ @@ -1142,7 +1120,7 @@ object JQuery { /** Hide the matched elements.
* See: jQuery Docs */ - def hide(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.hide(duration, easing, callback) + def hide(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.hide(duration, easing, callback) /** Hide the matched elements.
* See: jQuery Docs */ @@ -1451,7 +1429,7 @@ object JQuery { /** Display the matched elements.
* See: jQuery Docs */ - def show(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.show(duration, easing, callback) + def show(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.show(duration, easing, callback) /** Display the matched elements.
* See: jQuery Docs */ @@ -1459,7 +1437,7 @@ object JQuery { /** Display the matched elements with a sliding motion.
* See: jQuery Docs */ - def slideDown(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.slideDown(duration, easing, callback) + def slideDown(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.slideDown(duration, easing, callback) /** Display the matched elements with a sliding motion.
* See: jQuery Docs */ @@ -1467,7 +1445,7 @@ object JQuery { /** Display or hide the matched elements with a sliding motion.
* See: jQuery Docs */ - def slideToggle(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.slideToggle(duration, easing, callback) + def slideToggle(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.slideToggle(duration, easing, callback) /** Display or hide the matched elements with a sliding motion.
* See: jQuery Docs */ @@ -1475,7 +1453,7 @@ object JQuery { /** Hide the matched elements with a sliding motion.
* See: jQuery Docs */ - def slideUp(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.slideUp(duration, easing, callback) + def slideUp(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.slideUp(duration, easing, callback) /** Hide the matched elements with a sliding motion.
* See: jQuery Docs */ @@ -1499,7 +1477,7 @@ object JQuery { /** Display or hide the matched elements.
* See: jQuery Docs */ - def toggle(duration: Int, easing: String, callback: (Element) => Any): JQuery = jquery.toggle(duration, easing, callback) + def toggle(duration: Int, easing: EasingFunction, callback: (Element) => Any): JQuery = jquery.toggle(duration, easing, callback) /** Display or hide the matched elements.
* See: jQuery Docs */ diff --git a/src/main/scala/io/udash/wrappers/jquery/JQueryHelpers.scala b/src/main/scala/io/udash/wrappers/jquery/JQueryHelpers.scala deleted file mode 100644 index 1a17d73..0000000 --- a/src/main/scala/io/udash/wrappers/jquery/JQueryHelpers.scala +++ /dev/null @@ -1,20 +0,0 @@ -package io.udash.wrappers.jquery - -import org.scalajs.dom.Element - -import scala.scalajs.js -import scala.scalajs.js.Dictionary - -object JQueryHelpers { - - implicit class JQueryExt(element: JQuery) { - def animateThen(property: String, value: js.Any)(callback: => Unit) = - element.animate(Dictionary((property, value)), 300, "easeInOutQuint", (e: Element) => callback) - - def animate(property: String, value: Double) = animateThen(property, value)(()) - - def animate(property: String, value: String) = animateThen(property, value)(()) - } - - -} diff --git a/src/main/scala/io/udash/wrappers/jquery/package.scala b/src/main/scala/io/udash/wrappers/jquery/package.scala index 7f89fc7..51cc4dc 100644 --- a/src/main/scala/io/udash/wrappers/jquery/package.scala +++ b/src/main/scala/io/udash/wrappers/jquery/package.scala @@ -9,6 +9,7 @@ import scala.scalajs.js.annotation.JSName package object jquery { /** See: jQuery Docs */ type Selector = String + type EasingFunction = String type JQueryCallback = (Element, JQueryEvent) => Any def jQ: JQueryStatic = js.Dynamic.global.jQuery.asInstanceOf[JQueryStatic] diff --git a/src/main/scala/io/udash/wrappers/jquery/utils.scala b/src/main/scala/io/udash/wrappers/jquery/utils.scala new file mode 100644 index 0000000..0b639e3 --- /dev/null +++ b/src/main/scala/io/udash/wrappers/jquery/utils.scala @@ -0,0 +1,64 @@ +package io.udash.wrappers.jquery + +import scala.scalajs.js + +case class AnimationOptions(duration: Option[Int] = None, easing: Option[EasingFunction], queue: Option[Boolean] = None, + step: (Int, js.Dynamic) => Any = null, progress: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Int, Int) => Any = null, + complete: () => Any = null, start: JQueryPromise[js.Function1[js.Any, js.Any], js.Any] => Any = null, + done: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null, + fail: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null, + always: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null) { + def toJSDictionary: js.Dictionary[Any] = { + val r = js.Dictionary[Any]() + if (duration.isDefined) r.update("duration", duration.get) + if (easing.isDefined) r.update("easing", easing.get) + if (queue.isDefined) r.update("queue", queue.get) + if (step != null) r.update("step", step) + if (progress != null) r.update("progress", progress) + if (complete != null) r.update("complete", complete) + if (start != null) r.update("start", start) + if (done != null) r.update("done", done) + if (fail != null) r.update("fail", fail) + if (always != null) r.update("always", always) + r + } +} + +/** Easing functions specify the speed at which an animation progresses at different points within the animation.
+ * See: jQuery Docs */ +object EasingFunction { + val linear = "linear" + val swing = "swing" + + /* Require jQuery UI */ + val easeInQuad = "easeInQuad" + val easeOutQuad = "easeOutQuad" + val easeInOutQuad = "easeInOutQuad" + val easeInCubic = "easeInCubic" + val easeOutCubic = "easeOutCubic" + val easeInOutCubic = "easeInOutCubic" + val easeInQuart = "easeInQuart" + val easeOutQuart = "easeOutQuart" + val easeInOutQuart = "easeInOutQuart" + val easeInQuint = "easeInQuint" + val easeOutQuint = "easeOutQuint" + val easeInOutQuint = "easeInOutQuint" + val easeInExpo = "easeInExpo" + val easeOutExpo = "easeOutExpo" + val easeInOutExpo = "easeInOutExpo" + val easeInSine = "easeInSine" + val easeOutSine = "easeOutSine" + val easeInOutSine = "easeInOutSine" + val easeInCirc = "easeInCirc" + val easeOutCirc = "easeOutCirc" + val easeInOutCirc = "easeInOutCirc" + val easeInElastic = "easeInElastic" + val easeOutElastic = "easeOutElastic" + val easeInOutElastic = "easeInOutElastic" + val easeInBack = "easeInBack" + val easeOutBack = "easeOutBack" + val easeInOutBack = "easeInOutBack" + val easeInBounce = "easeInBounce" + val easeOutBounce = "easeOutBounce" + val easeInOutBounce = "easeInOutBounce" +}