From 95a5cbd720f6e8b640c8569758feb219ed8d483e Mon Sep 17 00:00:00 2001 From: starzu Date: Thu, 18 Feb 2016 13:05:25 +0100 Subject: [PATCH] * Application with examples * Improvements of the types in the wrapper --- .travis.yml | 5 +- build.sbt | 6 +- example/.gitignore | 132 ++++++++++++++++++ example/build.sbt | 54 +++++++ example/project/Dependencies.scala | 15 ++ example/project/UdashBuild.scala | 36 +++++ example/project/build.properties | 1 + example/project/plugins.sbt | 2 + example/src/main/assets/index.dev.html | 15 ++ example/src/main/assets/index.prod.html | 15 ++ .../demos/jquery/RoutingRegistryDef.scala | 30 ++++ .../jquery/StatesToViewPresenterDef.scala | 27 ++++ .../scala/io/udash/demos/jquery/init.scala | 33 +++++ .../scala/io/udash/demos/jquery/states.scala | 41 ++++++ .../udash/demos/jquery/views/ErrorView.scala | 19 +++ .../demos/jquery/views/FunctionView.scala | 25 ++++ .../udash/demos/jquery/views/IndexView.scala | 37 +++++ .../udash/demos/jquery/views/RootView.scala | 29 ++++ .../jquery/views/functions/AddBackView.scala | 62 ++++++++ .../jquery/views/functions/AddView.scala | 48 +++++++ .../jquery/views/functions/AfterView.scala | 29 ++++ .../jquery/views/functions/AnimateView.scala | 77 ++++++++++ .../views/functions/AppendPrependView.scala | 25 ++++ .../jquery/views/functions/AttrView.scala | 51 +++++++ .../views/functions/CallbacksView.scala | 50 +++++++ .../jquery/views/functions/ChildrenView.scala | 29 ++++ .../jquery/views/functions/DataView.scala | 30 ++++ .../jquery/views/functions/DeferredView.scala | 55 ++++++++ .../jquery/views/functions/EachView.scala | 27 ++++ .../jquery/views/functions/HideShowView.scala | 27 ++++ .../views/functions/OffsetPositionView.scala | 34 +++++ .../jquery/views/functions/OnOneOffView.scala | 44 ++++++ project/build.properties | 2 +- project/plugins.sbt | 2 +- .../io/udash/wrappers/jquery/JQuery.scala | 88 ++++++------ .../wrappers/jquery/JQueryCallbacks.scala | 4 + .../wrappers/jquery/JQueryDeferred.scala | 5 + .../udash/wrappers/jquery/JQueryStatic.scala | 7 +- .../io/udash/wrappers/jquery/utils.scala | 12 +- .../wrappers/jquery_test/SelectorsTest.scala | 12 +- .../wrappers/jquery_test/TraversingTest.scala | 10 +- 41 files changed, 1185 insertions(+), 67 deletions(-) create mode 100644 example/.gitignore create mode 100644 example/build.sbt create mode 100644 example/project/Dependencies.scala create mode 100644 example/project/UdashBuild.scala create mode 100644 example/project/build.properties create mode 100644 example/project/plugins.sbt create mode 100644 example/src/main/assets/index.dev.html create mode 100644 example/src/main/assets/index.prod.html create mode 100644 example/src/main/scala/io/udash/demos/jquery/RoutingRegistryDef.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/StatesToViewPresenterDef.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/init.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/states.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/ErrorView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/FunctionView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/IndexView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/RootView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/AddBackView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/AddView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/AfterView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/AnimateView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/AppendPrependView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/AttrView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/CallbacksView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/ChildrenView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/DataView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/DeferredView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/EachView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/HideShowView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/OffsetPositionView.scala create mode 100644 example/src/main/scala/io/udash/demos/jquery/views/functions/OnOneOffView.scala diff --git a/.travis.yml b/.travis.yml index d8e2485..610ec25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: scala scala: - - 2.11.7 + - 2.11.8 script: - - sbt ++$TRAVIS_SCALA_VERSION test \ No newline at end of file + - sbt ++$TRAVIS_SCALA_VERSION test + - cd example && sbt ++$TRAVIS_SCALA_VERSION compile \ No newline at end of file diff --git a/build.sbt b/build.sbt index 500b807..590adbc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,8 @@ name := "udash-jquery" -version := "1.0.0-SNAPSHOT" +version := "1.0.0-rc.2" organization := "io.udash" -scalaVersion := "2.11.7" +scalaVersion := "2.11.8" scalacOptions in ThisBuild ++= Seq( "-feature", "-deprecation", @@ -22,7 +22,7 @@ libraryDependencies ++= Seq( ) jsDependencies += - "org.webjars" % "jquery" % "2.2.0" / "2.2.0/jquery.js" minified "2.2.0/jquery.min.js" + "org.webjars" % "jquery" % "2.2.3" / "2.2.3/jquery.js" minified "2.2.3/jquery.min.js" requiresDOM in Test := true persistLauncher in Test := false diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..75bb5f2 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,132 @@ +# Created by .ignore support plugin (hsz.mobi) +### Eclipse template +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse +### Maven template +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +### Java template +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### Scala template +*.class +*.log + +# sbt specific +.cache +.history +.lib/ +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ + +# Scala-IDE specific +.scala_dependencies +.worksheet + + +generated/ \ No newline at end of file diff --git a/example/build.sbt b/example/build.sbt new file mode 100644 index 0000000..18ca035 --- /dev/null +++ b/example/build.sbt @@ -0,0 +1,54 @@ +name := "jquery-demo" + +version in ThisBuild := "1.0.0-SNAPSHOT" +scalaVersion in ThisBuild := "2.11.8" +organization in ThisBuild := "io.udash" +crossPaths in ThisBuild := false +scalacOptions in ThisBuild ++= Seq( + "-feature", + "-deprecation", + "-unchecked", + "-language:implicitConversions", + "-language:existentials", + "-language:dynamics", + "-Xfuture", + "-Xfatal-warnings", + "-Xlint:_,-missing-interpolator,-adapted-args" +) + +//TODO: remove it after scala-js-jquery 1.0 release +externalResolvers in ThisBuild := Seq( + DefaultMavenRepository, + Resolver.file("local", file(System.getProperty("user.home") + "/.ivy2/local"))(Resolver.ivyStylePatterns) +) + +val generatedDir = file("generated") +val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) + .settings( + libraryDependencies ++= deps.value, + persistLauncher in Compile := true, + + /* move these files out of target/. */ + crossTarget in (Compile, fullOptJS) := generatedDir, + crossTarget in (Compile, fastOptJS) := generatedDir, + crossTarget in (Compile, packageJSDependencies) := generatedDir, + crossTarget in (Compile, packageScalaJSLauncher) := generatedDir, + crossTarget in (Compile, packageMinifiedJSDependencies) := generatedDir, + + compile <<= (compile in Compile).dependsOn(compileStatics), + compileStatics := { + compileStaticsForRelease.value + (crossTarget.value / StaticFilesDir).***.get + }, + + artifactPath in(Compile, fastOptJS) := + (crossTarget in(Compile, fastOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl-fast.js", + artifactPath in(Compile, fullOptJS) := + (crossTarget in(Compile, fullOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl.js", + artifactPath in(Compile, packageJSDependencies) := + (crossTarget in(Compile, packageJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps-fast.js", + artifactPath in(Compile, packageMinifiedJSDependencies) := + (crossTarget in(Compile, packageMinifiedJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps.js", + artifactPath in(Compile, packageScalaJSLauncher) := + (crossTarget in(Compile, packageScalaJSLauncher)).value / StaticFilesDir / WebContent / "scripts" / "frontend-init.js" + ) \ No newline at end of file diff --git a/example/project/Dependencies.scala b/example/project/Dependencies.scala new file mode 100644 index 0000000..707fbc3 --- /dev/null +++ b/example/project/Dependencies.scala @@ -0,0 +1,15 @@ +import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ +import sbt._ + +object Dependencies extends Build { + val udashCoreVersion = "0.1.1" + val udashJQueryVersion = "1.0.0-rc.1" + + val deps = Def.setting(Seq[ModuleID]( + "io.udash" %%% "udash-core-frontend" % udashCoreVersion, + "io.udash" %%% "udash-jquery" % udashJQueryVersion + )) + + val depsJS = Def.setting(Seq[org.scalajs.sbtplugin.JSModuleID]( + )) +} \ No newline at end of file diff --git a/example/project/UdashBuild.scala b/example/project/UdashBuild.scala new file mode 100644 index 0000000..464b556 --- /dev/null +++ b/example/project/UdashBuild.scala @@ -0,0 +1,36 @@ +import org.scalajs.sbtplugin.ScalaJSPlugin.AutoImport._ +import sbt.Keys._ +import sbt._ + +object UdashBuild extends Build { + val StaticFilesDir = "UdashStatic" + val WebContent = "WebContent" + + def copyIndex(file: File, to: File) = { + val newFile = Path(to.toPath.toString + "/index.html") + IO.copyFile(file, newFile.asFile) + } + + val compileStatics = taskKey[Seq[File]]("Frontend static files manager.") + + val compileStaticsForRelease = Def.taskDyn { + def outDir(target: File) = target / StaticFilesDir / WebContent + if (!isSnapshot.value) { + Def.task { + val indexFile = sourceDirectory.value / "main/assets/index.prod.html" + copyIndex(indexFile, outDir((crossTarget in (Compile, fullOptJS)).value)) + (fullOptJS in Compile).value + (packageMinifiedJSDependencies in Compile).value + (packageScalaJSLauncher in Compile).value + } + } else { + Def.task { + val indexFile = sourceDirectory.value / "main/assets/index.dev.html" + copyIndex(indexFile, outDir((crossTarget in (Compile, fastOptJS)).value)) + (fastOptJS in Compile).value + (packageJSDependencies in Compile).value + (packageScalaJSLauncher in Compile).value + } + } + } +} \ No newline at end of file diff --git a/example/project/build.properties b/example/project/build.properties new file mode 100644 index 0000000..e6a3739 --- /dev/null +++ b/example/project/build.properties @@ -0,0 +1 @@ +sbt.version = 0.13.11 \ No newline at end of file diff --git a/example/project/plugins.sbt b/example/project/plugins.sbt new file mode 100644 index 0000000..2c9f86d --- /dev/null +++ b/example/project/plugins.sbt @@ -0,0 +1,2 @@ +logLevel := Level.Warn +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8") \ No newline at end of file diff --git a/example/src/main/assets/index.dev.html b/example/src/main/assets/index.dev.html new file mode 100644 index 0000000..72b62d5 --- /dev/null +++ b/example/src/main/assets/index.dev.html @@ -0,0 +1,15 @@ + + + + + jquery-demo - development + + + + + + + +
+ + \ No newline at end of file diff --git a/example/src/main/assets/index.prod.html b/example/src/main/assets/index.prod.html new file mode 100644 index 0000000..9c2609e --- /dev/null +++ b/example/src/main/assets/index.prod.html @@ -0,0 +1,15 @@ + + + + + jquery-demo + + + + + + + +
+ + \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/RoutingRegistryDef.scala b/example/src/main/scala/io/udash/demos/jquery/RoutingRegistryDef.scala new file mode 100644 index 0000000..118e345 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/RoutingRegistryDef.scala @@ -0,0 +1,30 @@ +package io.udash.demos.jquery + +import io.udash._ +import io.udash.utils.Bidirectional + +class RoutingRegistryDef extends RoutingRegistry[RoutingState] { + def matchUrl(url: Url): RoutingState = + url2State.applyOrElse(url.value.stripSuffix("/"), (x: String) => ErrorState) + + def matchState(state: RoutingState): Url = + Url(state2Url.apply(state)) + + private val (url2State, state2Url) = Bidirectional[String, RoutingState] { + case "" => IndexState + case "/add" => AddState + case "/addBack" => AddBackState + case "/after" => AfterBeforeState + case "/animate" => AnimateState + case "/append" => AppendPrependState + case "/attr" => AttrState + case "/callbacks" => CallbacksState + case "/children" => ChildrenState + case "/data" => DataState + case "/deferred" => DeferredState + case "/each" => EachState + case "/hide" => HideShowState + case "/offset" => OffsetPositionState + case "/on" => OnOneOffState + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/StatesToViewPresenterDef.scala b/example/src/main/scala/io/udash/demos/jquery/StatesToViewPresenterDef.scala new file mode 100644 index 0000000..0ff8f68 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/StatesToViewPresenterDef.scala @@ -0,0 +1,27 @@ +package io.udash.demos.jquery + +import io.udash._ +import io.udash.demos.jquery.views.functions._ +import io.udash.demos.jquery.views.{ErrorViewPresenter, IndexViewPresenter, RootViewPresenter} + +class StatesToViewPresenterDef extends ViewPresenterRegistry[RoutingState] { + def matchStateToResolver(state: RoutingState): ViewPresenter[_ <: RoutingState] = state match { + case RootState => RootViewPresenter + case IndexState => IndexViewPresenter + case AddState => AddViewPresenter + case AddBackState => AddBackViewPresenter + case AfterBeforeState => AfterBeforeViewPresenter + case AnimateState => AnimateViewPresenter + case AppendPrependState => AppendPrependViewPresenter + case AttrState => AttrViewPresenter + case CallbacksState => CallbacksViewPresenter + case ChildrenState => ChildrenViewPresenter + case DataState => DataViewPresenter + case DeferredState => DeferredViewPresenter + case EachState => EachViewPresenter + case HideShowState => HideShowViewPresenter + case OnOneOffState => OnOneOffViewPresenter + case OffsetPositionState => OffsetPositionViewPresenter + case _ => ErrorViewPresenter + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/init.scala b/example/src/main/scala/io/udash/demos/jquery/init.scala new file mode 100644 index 0000000..8bbe6ce --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/init.scala @@ -0,0 +1,33 @@ +package io.udash.demos.jquery + +import io.udash._ +import io.udash.wrappers.jquery._ +import org.scalajs.dom +import org.scalajs.dom.{Element, document} + +import scala.scalajs.js.JSApp +import scala.scalajs.js.annotation.JSExport + +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) +} + +object Init extends JSApp { + import Context._ + + @JSExport + override def main(): Unit = { + jQ(document).ready((_: Element) => { + val appRoot = jQ("#application").get(0) + if (appRoot.isEmpty) { + dom.console.error("Application root element not found! Check you index.html file!") + } else { + applicationInstance.run(appRoot.get) + } + }) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/states.scala b/example/src/main/scala/io/udash/demos/jquery/states.scala new file mode 100644 index 0000000..2ef0306 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/states.scala @@ -0,0 +1,41 @@ +package io.udash.demos.jquery + +import io.udash._ + +sealed abstract class RoutingState(val parentState: RoutingState) extends State { + def url(implicit application: Application[RoutingState]): String = s"#${application.matchState(this).value}" +} + +case object RootState extends RoutingState(null) + +case object ErrorState extends RoutingState(RootState) + +case object IndexState extends RoutingState(RootState) + +case object AddState extends RoutingState(RootState) + +case object AddBackState extends RoutingState(RootState) + +case object AfterBeforeState extends RoutingState(RootState) + +case object AnimateState extends RoutingState(RootState) + +case object AppendPrependState extends RoutingState(RootState) + +case object AttrState extends RoutingState(RootState) + +case object CallbacksState extends RoutingState(RootState) + +case object ChildrenState extends RoutingState(RootState) + +case object DataState extends RoutingState(RootState) + +case object DeferredState extends RoutingState(RootState) + +case object EachState extends RoutingState(RootState) + +case object HideShowState extends RoutingState(RootState) + +case object OffsetPositionState extends RoutingState(RootState) + +case object OnOneOffState extends RoutingState(RootState) \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/ErrorView.scala b/example/src/main/scala/io/udash/demos/jquery/views/ErrorView.scala new file mode 100644 index 0000000..98fc2d9 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/ErrorView.scala @@ -0,0 +1,19 @@ +package io.udash.demos.jquery.views + +import io.udash._ +import io.udash.demos.jquery.IndexState +import org.scalajs.dom.Element + +object ErrorViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new ErrorView) + +class ErrorView extends View { + import scalatags.JsDom.all._ + + private val content = h3( + "URL not found!" + ).render + + override def getTemplate: Element = content + + override def renderChild(view: View): Unit = {} +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/FunctionView.scala b/example/src/main/scala/io/udash/demos/jquery/views/FunctionView.scala new file mode 100644 index 0000000..c5c14b4 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/FunctionView.scala @@ -0,0 +1,25 @@ +package io.udash.demos.jquery.views + +import io.udash._ +import org.scalajs.dom.{Element, Event} + +abstract class FunctionView extends View { + import scalatags.JsDom.all._ + + protected val content: Element + protected val script: () => Any + + override def getTemplate: Element = { + div( + content, + button( + onclick :+= ((_: Event) => { + script() + false + }) + )("Run script") + ).render + } + + override def renderChild(view: View): Unit = {} +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/IndexView.scala b/example/src/main/scala/io/udash/demos/jquery/views/IndexView.scala new file mode 100644 index 0000000..946e02c --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/IndexView.scala @@ -0,0 +1,37 @@ +package io.udash.demos.jquery.views + +import io.udash._ +import io.udash.demos.jquery._ +import org.scalajs.dom.Element + +object IndexViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new IndexView) + +class IndexView extends View { + import Context._ + + import scalatags.JsDom.all._ + + private val content = div( + "Take a look at following demo pages:", + ul( + li(a(href := AddState.url)(".add() & .css()")), + li(a(href := AddBackState.url)(".addBack() & .addClass()")), + li(a(href := AfterBeforeState.url)(".after() & .before()")), + li(a(href := AnimateState.url)(".animate() & .click()")), + li(a(href := AppendPrependState.url)(".append() & .prepend()")), + li(a(href := AttrState.url)(".attr()")), + li(a(href := CallbacksState.url)("Callbacks")), + li(a(href := ChildrenState.url)(".children()")), + li(a(href := DataState.url)(".data()")), + li(a(href := DeferredState.url)("Deferred")), + li(a(href := EachState.url)(".each()")), + li(a(href := HideShowState.url)(".hide() & .show()")), + li(a(href := OnOneOffState.url)(".on() & .one() & .off()")), + li(a(href := OffsetPositionState.url)(".offset() & .position()")) + ) + ).render + + override def getTemplate: Element = content + + override def renderChild(view: View): Unit = {} +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/RootView.scala b/example/src/main/scala/io/udash/demos/jquery/views/RootView.scala new file mode 100644 index 0000000..64d870b --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/RootView.scala @@ -0,0 +1,29 @@ +package io.udash.demos.jquery.views + +import io.udash._ +import io.udash.demos.jquery.{Context, IndexState, RootState} +import org.scalajs.dom.Element + +object RootViewPresenter extends DefaultViewPresenterFactory[RootState.type](() => new RootView) + +class RootView extends View { + import Context._ + + import scalatags.JsDom.all._ + + private var child: Element = div().render + + private val content = div( + a(href := IndexState.url)(h1("jquery-demo")), + child + ).render + + override def getTemplate: Element = content + + override def renderChild(view: View): Unit = { + import io.udash.wrappers.jquery._ + val newChild = view.getTemplate + jQ(child).replaceWith(newChild) + child = newChild + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/AddBackView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/AddBackView.scala new file mode 100644 index 0000000..76037ce --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/AddBackView.scala @@ -0,0 +1,62 @@ +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 scalatags.JsDom.tags2 + +object AddBackViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AddBackView) + +/** Based on examples from: jQuery Docs. */ +class AddBackView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".addBack() & .addClass()"), + tags2.style( + """.demo p, .demo div { + | margin: 5px; + | padding: 5px; + |} + |.border { + | border: 2px solid red; + |} + |.background { + | background: yellow; + |} + |.left, .right { + | width: 45%; + | float: left; + |} + |.right { + | margin-left: 3%; + |}""".stripMargin + ), + div(cls := "left")( + p(strong("Before ", code("addBack()"))), + div(cls := "before-addback")( + p("First Paragraph"), + p("Second Paragraph") + ) + ), + div(cls := "right")( + p(strong("After ", code("addBack()"))), + div(cls := "after-addback")( + p("First Paragraph"), + p("Second Paragraph") + ) + ) + ).render + + override protected val script = () => { + jQ( ".demo div.left, .demo div.right" ).find( "div, div > p" ).addClass( "border" ) + + // First Example + jQ( ".demo div.before-addback" ).find( "p" ).addClass( "background" ) + + // Second Example + jQ( ".demo div.after-addback" ).find( "p" ).addBack().addClass( "background" ) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/AddView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/AddView.scala new file mode 100644 index 0000000..c77042d --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/AddView.scala @@ -0,0 +1,48 @@ +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 scalatags.JsDom.tags2 + +object AddViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AddView) + +/** Based on examples from: jQuery Docs. */ +class AddView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".add() & .css()"), + tags2.style( + """.demo div { + | width: 60px; + | height: 60px; + | margin: 10px; + | float: left; + |} + |.demo p { + | clear: left; + | font-weight: bold; + | font-size: 16px; + | color: blue; + | margin: 0 10px; + | padding: 2px; + |}""".stripMargin + ), + div(), + div(), + div(), + div(), + div(), + div(), + p("Added this... (notice no border)") + ).render + + override protected val script = () => { + jQ(".demo div").css("border", "2px solid red") + .add(".demo p") + .css("background", "yellow") + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/AfterView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/AfterView.scala new file mode 100644 index 0000000..15ffc96 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/AfterView.scala @@ -0,0 +1,29 @@ +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._ + +object AfterBeforeViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AfterBeforeView) + +/** Based on examples from: jQuery Docs. */ +class AfterBeforeView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".after()"), + div( + p(cls := "after")("I would like to say: ") + ), + h3(".before()"), + div( + p(cls := "before")("is what I said...") + ) + ).render + + override protected val script = () => { + jQ(".after").after("Hello") + jQ(".before").before("Hello") + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/AnimateView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/AnimateView.scala new file mode 100644 index 0000000..ad4c630 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/AnimateView.scala @@ -0,0 +1,77 @@ +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 + +import scalatags.JsDom.tags2 + +object AnimateViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AnimateView) + +/** Based on examples from: jQuery Docs. */ +class AnimateView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".animate() & .click()"), + tags2.style( + """.demo div { + | background-color: #bca; + | width: 200px; + | height: 1.1em; + | text-align: center; + | border: 2px solid green; + | margin: 3px; + | font-size: 14px; + |} + |.demo button { + | font-size: 14px; + |}""".stripMargin + ), + button(id := "go1", disabled := "disabled")("» Animate Block1"), + button(id := "go2", disabled := "disabled")("» Animate Block2"), + button(id := "go3", disabled := "disabled")("» Animate Both"), + button(id := "go4", disabled := "disabled")("» Reset"), + div(id := "block1")("Block1"), + div(id := "block2")("Block2") + ).render + + override protected val script = () => { + jQ("#go1").click((_: Element, _: JQueryEvent) => { + jQ( "#block1" ) + .animate(Map( + "width" -> "90%" + ), AnimationOptions( + queue = Some(false), + duration = Some(3000) + )) + .animate(Map("fontSize" -> "24px"), 1500) + .animate(Map("borderRightWidth" -> "15px"), 1500) + }) + + jQ("#go2").click((_: Element, _: JQueryEvent) => { + jQ("#block2") + .animate(Map("width" -> "90%"), 1000) + .animate(Map("fontSize" -> "24px"), 1000) + .animate(Map("borderLeftWidth" -> "15px"), 1000) + }) + + jQ("#go3").click((_: Element, _: JQueryEvent) => { + jQ("#go1").add("#go2").click() + }) + + jQ("#go4").click((_: Element, _: JQueryEvent) => { + // TODO: It does not work without explicit Map elements type + import scala.scalajs.js.`|` + jQ("div").css(Map[String, String | Int | Double | Boolean]( + "width" -> "", + "fontSize" -> "", + "borderWidth" -> "" + )) + }) + + jQ(".demo button").prop("disabled", "") + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/AppendPrependView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/AppendPrependView.scala new file mode 100644 index 0000000..6640498 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/AppendPrependView.scala @@ -0,0 +1,25 @@ +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._ + +object AppendPrependViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AppendPrependView) + +/** Based on examples from: jQuery Docs. */ +class AppendPrependView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".append()"), + p(id := "append")("I would like to say: "), + h3(".prepend()"), + p(id := "prepend")("amigo!") + ).render + + override protected val script = () => { + jQ("#append").append("hello") + jQ("#prepend").prepend("Hello ") + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/AttrView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/AttrView.scala new file mode 100644 index 0000000..433981f --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/AttrView.scala @@ -0,0 +1,51 @@ +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) + +/** Based on examples from: jQuery Docs. */ +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")}
+ |.prop('checked'): ${jQ(input).prop("checked")}
+ |.is(':checked'): ${jQ(input).is(":checked")}""".stripMargin + ) + }).change() + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/CallbacksView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/CallbacksView.scala new file mode 100644 index 0000000..aa297a2 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/CallbacksView.scala @@ -0,0 +1,50 @@ +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 scala.scalajs.js + +object CallbacksViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new CallbacksView) + +/** Based on examples from: jQuery Docs. */ +class CallbacksView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3("Callbacks"), + ul(id := "plus"), + ul(id := "minus"), + ul(id := "mul"), + ul(id := "div") + ).render + + override protected val script = () => { + 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) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/ChildrenView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/ChildrenView.scala new file mode 100644 index 0000000..845042f --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/ChildrenView.scala @@ -0,0 +1,29 @@ +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._ + +object ChildrenViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new ChildrenView) + +/** Based on examples from: jQuery Docs. */ +class ChildrenView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".children()"), + div( + span("Hello"), + p(cls := "selected")("Hello again"), + div(cls := "selected")("and again"), + p("and one last time.") + ) + ).render + + override protected val script = () => { + jQ(".demo div").children().css("color", "blue") + jQ(".demo div").children(".selected").css("border-bottom", "3px double red") + jQ(".demo div").children("div.selected").css("border-top", "1px dashed green") + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/DataView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/DataView.scala new file mode 100644 index 0000000..8d67ac0 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/DataView.scala @@ -0,0 +1,30 @@ +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._ + +object DataViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new DataView) + +/** Based on examples from: jQuery Docs. */ +class DataView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".data()"), + div( + "The values stored were ", + span("_"), + " and ", + span("_") + ) + ).render + + override protected val script = () => { + jQ(".demo div").data("test", Map("first" -> 16, "last" -> "pizza!")) + val data: Map[String, Any] = jQ(".demo div").data("test").get.asInstanceOf[Map[String, Any]] + jQ(".demo div span:first").text(data.get("first").get.toString) + jQ(".demo div span:last").text(data.get("last").get.toString) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/DeferredView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/DeferredView.scala new file mode 100644 index 0000000..edb6ced --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/DeferredView.scala @@ -0,0 +1,55 @@ +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) + +/** Based on examples from: jQuery Docs. */ +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")) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/EachView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/EachView.scala new file mode 100644 index 0000000..10e9395 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/EachView.scala @@ -0,0 +1,27 @@ +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) + +/** Based on examples from: jQuery Docs. */ +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) + }) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/HideShowView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/HideShowView.scala new file mode 100644 index 0000000..fcd8246 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/HideShowView.scala @@ -0,0 +1,27 @@ +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._ + +object HideShowViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new HideShowView) + +/** Based on examples from: jQuery Docs. */ +class HideShowView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".hide() & .show()"), + div("Click button to hide me") + ).render + + override protected val script = () => { + jQ(".demo div") + .hide(AnimationOptions( + duration = Some(3000), + easing = Some(EasingFunction.linear) + )) + .show(1500, EasingFunction.swing) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/OffsetPositionView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/OffsetPositionView.scala new file mode 100644 index 0000000..d2304d9 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/OffsetPositionView.scala @@ -0,0 +1,34 @@ +package io.udash.demos.jquery.views.functions + +import io.udash._ +import io.udash.demos.jquery.{IndexState, OffsetPositionState} +import io.udash.demos.jquery.views.FunctionView +import io.udash.wrappers.jquery._ +import org.scalajs.dom.{Element, Event} + +object OffsetPositionViewPresenter extends DefaultViewPresenterFactory[OffsetPositionState.type](() => new OffsetPositionView) + +/** Based on examples from: jQuery Docs. */ +class OffsetPositionView extends FunctionView { + import scalatags.JsDom.all._ + + override protected val content = div(cls := "demo")( + h3(".offset() & .position()"), + div(style := "padding: 12px; border: 1px red solid;")( + p(style := "margin-left: 10px; border: 1px blue solid;")("Hello world!") + ), + p(id := "results")("") + ).render + + override protected val script = () => { + val div = jQ(".demo div") + val p = jQ(".demo div p") + jQ("#results").html( + s"""Div offset: (${div.offset().top}, ${div.offset().left})
+ |Div position: (${div.position().top}, ${div.position().left})
+ |Paragraph offset: (${p.offset().top}, ${p.offset().left})
+ |Paragraph position: (${p.position().top}, ${p.position().left}) + """.stripMargin + ) + } +} \ No newline at end of file diff --git a/example/src/main/scala/io/udash/demos/jquery/views/functions/OnOneOffView.scala b/example/src/main/scala/io/udash/demos/jquery/views/functions/OnOneOffView.scala new file mode 100644 index 0000000..e237e37 --- /dev/null +++ b/example/src/main/scala/io/udash/demos/jquery/views/functions/OnOneOffView.scala @@ -0,0 +1,44 @@ +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) + +/** Based on examples from: jQuery Docs. */ +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", "") + } +} \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index da4bbed..e6a3739 100755 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 0.13.9 \ No newline at end of file +sbt.version = 0.13.11 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index feaeea7..6e58810 100755 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ logLevel := Level.Warn -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.7") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8") diff --git a/src/main/scala/io/udash/wrappers/jquery/JQuery.scala b/src/main/scala/io/udash/wrappers/jquery/JQuery.scala index 3e2b9c4..6e4b757 100644 --- a/src/main/scala/io/udash/wrappers/jquery/JQuery.scala +++ b/src/main/scala/io/udash/wrappers/jquery/JQuery.scala @@ -72,21 +72,21 @@ trait JQuery extends js.Object { * See: jQuery Docs */ def appendTo(target: (Selector | Element | JQuery)*): JQuery = js.native + /** Set one or more attributes for the set of matched elements.
+ * See: jQuery Docs */ + def attr(attributeName: String, attributeValue: String | Int | Double | Boolean): JQuery = js.native + /** Get the value of an attribute for the first element in the set of matched elements.
* See: jQuery Docs */ private[jquery] def attr(attributeName: String): UndefOr[String] = js.native /** Set one or more attributes for the set of matched elements.
* See: jQuery Docs */ - private[jquery] def attr(attributes: js.Dictionary[String | Double]): JQuery = js.native + private[jquery] def attr(attributes: js.Dictionary[String | Int | Double | Boolean]): JQuery = js.native /** Set one or more attributes for the set of matched elements.
* See: jQuery Docs */ - private[jquery] def attr(attributeName: String, attributeValue: String | Double): JQuery = js.native - - /** Set one or more attributes for the set of matched elements.
- * See: jQuery Docs */ - private[jquery] def attr(attributeName: String, function: js.Function2[Int, String, String | Double]): JQuery = js.native + private[jquery] def attr(attributeName: String, function: js.Function2[Int, String, String | Int | Double | Boolean]): JQuery = js.native /** Insert content, specified by the parameter, before each element in the set of matched elements.
* See: jQuery Docs */ @@ -147,19 +147,19 @@ trait JQuery extends js.Object { /** Get the computed style properties for the first element in the set of matched elements.
* See: jQuery Docs */ - def css(propertyNames: String*): JQuery = js.native + def css(propertyName: String): String = js.native /** Set one or more CSS properties for the set of matched elements.
* See: jQuery Docs */ - private[jquery] def css(attributeName: String, attributeValue: String | Int): JQuery = js.native + def css(attributeName: String, attributeValue: String | Int | Double | Boolean): JQuery = js.native /** Set one or more CSS properties for the set of matched elements.
* See: jQuery Docs */ - private[jquery] def css(attributeName: String, attributeFun: js.Function2[Int, String, String | Int]): JQuery = js.native + private[jquery] def css(attributeName: String, attributeFun: js.Function2[Int, String, String | Int | Double | Boolean]): JQuery = js.native /** Set one or more CSS properties for the set of matched elements.
* See: jQuery Docs */ - private[jquery] def css(properties: js.Dictionary[String | Int]): JQuery = js.native + private[jquery] def css(properties: js.Dictionary[String | Int | Double | Boolean]): JQuery = js.native /** Store arbitrary data associated with the matched elements.
* See: jQuery Docs */ @@ -196,7 +196,7 @@ trait JQuery extends js.Object { /** Iterate over a jQuery object, executing a function for each matched element.
* See: jQuery Docs */ - private[jquery] def each(function: js.ThisFunction2[Element, Int, Element, Any]): JQuery = js.native + private[jquery] def each(function: js.ThisFunction1[Element, Int, Any]): JQuery = js.native /** Remove all child nodes of the set of matched elements from the DOM.
* See: jQuery Docs */ @@ -328,11 +328,11 @@ trait JQuery extends js.Object { /** Set the CSS height of every matched element.
* See: jQuery Docs */ - def height(value: String | Double): JQuery = js.native + def height(value: String | Int | Double): JQuery = js.native /** Set the CSS height of every matched element.
* See: jQuery Docs */ - private[jquery] def height(function: js.ThisFunction2[Element, Int, Int, String | Double]): JQuery = js.native + private[jquery] def height(function: js.ThisFunction2[Element, Int, Int, String | Int | Double]): JQuery = js.native /** Hide the matched elements.
* See: jQuery Docs */ @@ -372,7 +372,7 @@ trait JQuery extends js.Object { /** Set the CSS inner height of each element in the set of matched elements.
* See: jQuery Docs */ - private[jquery] def innerHeight(function: js.ThisFunction2[Element, Int, Double, Double | String]): JQuery = js.native + private[jquery] def innerHeight(function: js.ThisFunction2[Element, Int, Double, Int | Double | String]): JQuery = js.native /** Get the current computed inner width for the first element in the set of matched elements, including padding but not border.
* See: jQuery Docs */ @@ -380,11 +380,11 @@ trait JQuery extends js.Object { /** Set the CSS inner width of each element in the set of matched elements.
* See: jQuery Docs */ - def innerWidth(value: Double | String): JQuery = js.native + def innerWidth(value: Int | Double | String): JQuery = js.native /** Set the CSS inner width of each element in the set of matched elements.
* See: jQuery Docs */ - private[jquery] def innerWidth(function: js.ThisFunction2[Element, Int, Double, Double | String]): JQuery = js.native + private[jquery] def innerWidth(function: js.ThisFunction2[Element, Int, Double, Int | Double | String]): JQuery = js.native /** Insert every element in the set of matched elements after the target.
* See: jQuery Docs */ @@ -521,7 +521,7 @@ trait JQuery extends js.Object { /** Get the current coordinates of the first element in the set of matched elements, relative to the document.
* See: jQuery Docs */ - private[jquery] def offset(coordinates: js.Dictionary[Double]): JQuery = js.native + private[jquery] def offset(coordinates: js.Dictionary[Int | Double]): JQuery = js.native /** Get the closest ancestor element that is positioned.
* See: jQuery Docs */ @@ -565,7 +565,7 @@ trait JQuery extends js.Object { /** Set the CSS outer Height of each element in the set of matched elements.
* See: jQuery Docs */ - def outerHeight(value: Double | String): JQuery = js.native + def outerHeight(value: Int | Double | String): JQuery = js.native /** Set the CSS outer Height of each element in the set of matched elements.
* See: jQuery Docs */ @@ -577,7 +577,7 @@ trait JQuery extends js.Object { /** Set the CSS outer width of each element in the set of matched elements.
* See: jQuery Docs */ - def outerWidth(value: Double | String): JQuery = js.native + def outerWidth(value: Int | Double | String): JQuery = js.native /** Set the CSS outer width of each element in the set of matched elements.
* See: jQuery Docs */ @@ -858,12 +858,12 @@ trait JQuery extends js.Object { /** Get the current value of the first element in the set of matched elements.
* See: jQuery Docs */ @JSName("val") - def value(): String | Number | js.Array[Any] = js.native + def value(): String | Int | Double | js.Array[Any] = js.native /** Set the value of each element in the set of matched elements.
* See: jQuery Docs */ @JSName("val") - def value(value: String | Number | js.Array[Any]): JQuery = js.native + def value(value: String | Int | Double | js.Array[Any]): JQuery = js.native /** Set the value of each element in the set of matched elements.
* See: jQuery Docs */ @@ -876,11 +876,11 @@ trait JQuery extends js.Object { /** Set the CSS width of each element in the set of matched elements.
* See: jQuery Docs */ - def width(value: String | Double): JQuery = js.native + def width(value: String | Int | Double): JQuery = js.native /** Set the CSS width of each element in the set of matched elements.
* See: jQuery Docs */ - private[jquery] def width(function: js.ThisFunction2[Element, Int, Int, String | Double]): JQuery = js.native + private[jquery] def width(function: js.ThisFunction2[Element, Int, Int, String | Int | Double]): JQuery = js.native /** Wrap an HTML structure around each element in the set of matched elements.
* See: jQuery Docs */ @@ -942,7 +942,8 @@ 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: EasingFunction = EasingFunction.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 */ @@ -958,15 +959,11 @@ object JQuery { /** Set one or more attributes for the set of matched elements.
* See: jQuery Docs */ - def attr(attributes: Map[String, String | Double]): JQuery = jquery.attr(attributes.toJSDictionary) + def attr(attributes: Map[String, String | Int | Double | Boolean]): JQuery = jquery.attr(attributes.toJSDictionary) /** Set one or more attributes for the set of matched elements.
* See: jQuery Docs */ - def attr(attributeName: String, attributeValue: String | Double): JQuery = jquery.attr(attributeName, attributeValue) - - /** Set one or more attributes for the set of matched elements.
- * See: jQuery Docs */ - def attr(attributeName: String, function: (Int, String) => String | Double): JQuery = jquery.attr(attributeName, function) + def attr(attributeName: String, function: (Int, String) => String | Int | Double | Boolean): JQuery = jquery.attr(attributeName, function) /** Insert content, specified by the parameter, before each element in the set of matched elements.
* See: jQuery Docs */ @@ -1006,15 +1003,11 @@ object JQuery { /** Set one or more CSS properties for the set of matched elements.
* See: jQuery Docs */ - def css(attributeName: String, attributeValue: String | Int): JQuery = jquery.css(attributeName, attributeValue) - - /** Set one or more CSS properties for the set of matched elements.
- * See: jQuery Docs */ - def css(attributeName: String, attributeFun: (Int, String) => String | Int): JQuery = jquery.css(attributeName, attributeFun) + def css(propertyNames: Map[String, String | Int | Double | Boolean]): JQuery = jquery.css(propertyNames.toJSDictionary) /** Set one or more CSS properties for the set of matched elements.
* See: jQuery Docs */ - def css(propertyNames: Map[String, String | Int]): JQuery = jquery.css(propertyNames.toJSDictionary) + def css(attributeName: String, attributeFun: (Int, String) => String | Int | Double | Boolean): JQuery = jquery.css(attributeName, attributeFun) /** Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute.
* See: jQuery Docs */ @@ -1034,7 +1027,7 @@ object JQuery { /** Iterate over a jQuery object, executing a function for each matched element.
* See: jQuery Docs */ - def each(callback: (Element, Int, Element) => Any): JQuery = jquery.each(callback) + def each(callback: (Element, Int) => Any): JQuery = jquery.each(callback) /** Bind an event handler to the "error" JavaScript event on an element.
* See: jQuery Docs */ @@ -1116,7 +1109,7 @@ object JQuery { /** Set the CSS height of every matched element.
* See: jQuery Docs */ - def height(function: (Element, Int, Int) => String | Double): JQuery = jquery.height(function) + def height(function: (Element, Int, Int) => String | Int | Double): JQuery = jquery.height(function) /** Hide the matched elements.
* See: jQuery Docs */ @@ -1140,11 +1133,11 @@ object JQuery { /** Set the CSS inner height of each element in the set of matched elements.
* See: jQuery Docs */ - def innerHeight(function: (Element, Int, Double) => Double | String): JQuery = jquery.innerHeight(function) + def innerHeight(function: (Element, Int, Double) => Int | Double | String): JQuery = jquery.innerHeight(function) /** Set the CSS inner width of each element in the set of matched elements.
* See: jQuery Docs */ - def innerWidth(function: (Element, Int, Double) => Double | String): JQuery = jquery.innerWidth(function) + def innerWidth(function: (Element, Int, Double) => Int | Double | String): JQuery = jquery.innerWidth(function) /** Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
* See: jQuery Docs */ @@ -1244,11 +1237,14 @@ object JQuery { /** Get the current coordinates of the first element in the set of matched elements, relative to the document.
* See: jQuery Docs */ - def offset(): Map[String, Double] = jquery.offset().toMap + def offset(): Offset = { + val o = jquery.offset() + Offset(o("top"), o("left")) + } /** Get the current coordinates of the first element in the set of matched elements, relative to the document.
* See: jQuery Docs */ - def offset(coordinates: Map[String, Double]): JQuery = jquery.offset(coordinates.toJSDictionary) + def offset(coordinates: Offset): JQuery = jquery.offset(coordinates.toJSDictionary) /** Attach an event handler function for one or more events to the selected elements.
* See: jQuery Docs */ @@ -1332,7 +1328,7 @@ object JQuery { type ThisFunctionCallback = ThisFunction1[Element, JQueryEvent, Any] - jquery.each((element: Element, idx: Int, _: Element) => { + jquery.each((element: Element, idx: Int) => { val cb = params match { case CallbackParameters(false, null, null) => c: ThisFunctionCallback => jQ(element).on(event, c) case CallbackParameters(false, null, data) => c: ThisFunctionCallback => jQ(element).on(event, data, c) @@ -1366,9 +1362,9 @@ object JQuery { /** Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.
* See: jQuery Docs */ - def position(): (Double, Double) = { + def position(): Position = { val p = jquery.position() - (p("top"), p("left")) + Position(p("top"), p("left")) } /** Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
@@ -1513,7 +1509,7 @@ object JQuery { /** Set the CSS width of each element in the set of matched elements.
* See: jQuery Docs */ - def width(function: (Element, Int, Int) => String | Double): JQuery = jquery.width(function) + def width(function: (Element, Int, Int) => String | Int | Double): JQuery = jquery.width(function) /** Wrap an HTML structure around each element in the set of matched elements.
* See: jQuery Docs */ diff --git a/src/main/scala/io/udash/wrappers/jquery/JQueryCallbacks.scala b/src/main/scala/io/udash/wrappers/jquery/JQueryCallbacks.scala index 2bf356b..7534bce 100644 --- a/src/main/scala/io/udash/wrappers/jquery/JQueryCallbacks.scala +++ b/src/main/scala/io/udash/wrappers/jquery/JQueryCallbacks.scala @@ -16,6 +16,10 @@ trait JQueryCallbacks[FunType <: js.Function1[ArgType, js.Any], ArgType] extends * See: jQuery Docs */ def disabled: Boolean = js.native + /** Remove all of the callbacks from a list.
+ * See: jQuery Docs */ + def empty(): JQueryCallbacks[FunType, ArgType] = js.native + /** Call all of the callbacks with the given arguments.
* See: jQuery Docs */ def fire(args: ArgType): JQueryCallbacks[FunType, ArgType] = js.native diff --git a/src/main/scala/io/udash/wrappers/jquery/JQueryDeferred.scala b/src/main/scala/io/udash/wrappers/jquery/JQueryDeferred.scala index cc9d913..da307ea 100644 --- a/src/main/scala/io/udash/wrappers/jquery/JQueryDeferred.scala +++ b/src/main/scala/io/udash/wrappers/jquery/JQueryDeferred.scala @@ -26,6 +26,11 @@ trait JQueryPromise[FunType <: js.Function1[ArgType, js.Any], ArgType] extends j * See: jQuery Docs */ def promise(target: js.Object = js.native): JQueryPromise[FunType, ArgType] = js.native + /** Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
+ * See: jQuery Docs */ + // Usage of then as identifier is deprecated. It can be used as a keyword in future versions of scala. + // def then(done: FunType, fail: FunType, progress: FunType): JQueryDeferred[FunType, ArgType] = js.native + /** Determine the current state of a Deferred object.
* See: jQuery Docs */ private[jquery] def state: String = js.native diff --git a/src/main/scala/io/udash/wrappers/jquery/JQueryStatic.scala b/src/main/scala/io/udash/wrappers/jquery/JQueryStatic.scala index be471d1..b659bea 100644 --- a/src/main/scala/io/udash/wrappers/jquery/JQueryStatic.scala +++ b/src/main/scala/io/udash/wrappers/jquery/JQueryStatic.scala @@ -3,6 +3,7 @@ package io.udash.wrappers.jquery import org.scalajs.dom._ import scala.scalajs.js +import scala.scalajs.js.annotation.JSName @js.native trait JQueryStatic extends js.Object { @@ -66,7 +67,8 @@ trait JQueryStatic extends js.Object { /** A multi-purpose callbacks list object that provides a powerful way to manage callback lists.
* See: jQuery Docs */ - def callbacks[FunType <: js.Function1[ArgType, js.Any], ArgType](flags: String): JQueryCallbacks[FunType, ArgType] = js.native + @JSName("Callbacks") + def callbacks[FunType <: js.Function1[ArgType, js.Any], ArgType](flags: String = js.native): JQueryCallbacks[FunType, ArgType] = js.native /** Check to see if a DOM element is a descendant of another DOM element.
* See: jQuery Docs */ @@ -79,7 +81,8 @@ trait JQueryStatic extends js.Object { /** A factory function that returns a chainable utility object with methods to register multiple callbacks into callback queues, * invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.
* See: jQuery Docs */ - def deferred[FunType <: js.Function1[ArgType, js.Any], ArgType](beforeStart: JQueryDeferred[_, _]): JQueryDeferred[FunType, ArgType] = js.native + @JSName("Deferred") + def deferred[FunType <: js.Function1[ArgType, js.Any], ArgType](beforeStart: JQueryDeferred[_, _] = js.native): JQueryDeferred[FunType, ArgType] = js.native /** Execute the next function on the queue for the matched element.
* See: jQuery Docs */ diff --git a/src/main/scala/io/udash/wrappers/jquery/utils.scala b/src/main/scala/io/udash/wrappers/jquery/utils.scala index 0b639e3..e584afc 100644 --- a/src/main/scala/io/udash/wrappers/jquery/utils.scala +++ b/src/main/scala/io/udash/wrappers/jquery/utils.scala @@ -1,8 +1,18 @@ package io.udash.wrappers.jquery import scala.scalajs.js +import scala.scalajs.js.| -case class AnimationOptions(duration: Option[Int] = None, easing: Option[EasingFunction], queue: Option[Boolean] = None, +sealed trait TopLeftCoords { + def top: Double + def left: Double + def toJSDictionary: js.Dictionary[Int | Double] = + js.Dictionary[Int | Double]("top" -> top, "left" -> left) +} +case class Position(override val top: Double, override val left: Double) extends TopLeftCoords +case class Offset(override val top: Double, override val left: Double) extends TopLeftCoords + +case class AnimationOptions(duration: Option[Int] = None, easing: Option[EasingFunction] = None, 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, diff --git a/src/test/scala/io/udash/wrappers/jquery_test/SelectorsTest.scala b/src/test/scala/io/udash/wrappers/jquery_test/SelectorsTest.scala index ede080c..6654210 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/SelectorsTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/SelectorsTest.scala @@ -13,9 +13,9 @@ class SelectorsTest extends WordSpec with Matchers { val el3 = h1(cls := "c3").render val dom = div(el1, el2, el3).render - jQ(dom).children(".c1").each((el, _, _) => jQ(el).attr("a1", 1)) - jQ(dom).children(".c2").each((el, _, _) => jQ(el).attr("a2", 1)) - jQ(dom).children(".c3").each((el, _, _) => jQ(el).attr("a3", 1)) + jQ(dom).children(".c1").each((el, _) => jQ(el).attr("a1", 1)) + jQ(dom).children(".c2").each((el, _) => jQ(el).attr("a2", 1)) + jQ(dom).children(".c3").each((el, _) => jQ(el).attr("a3", 1)) jQ(el1).attr("a1") should be(Some("1")) jQ(el1).attr("a2") should be(None) @@ -36,9 +36,9 @@ class SelectorsTest extends WordSpec with Matchers { val el3 = h1(id := "el3").render val dom = div(el1, el2, el3).render - jQ(dom).children("#el1").each((el, _, _) => jQ(el).attr("a1", 1)) - jQ(dom).children("#el2").each((el, _, _) => jQ(el).attr("a2", 1)) - jQ(dom).children("#el3").each((el, _, _) => jQ(el).attr("a3", 1)) + jQ(dom).children("#el1").each((el, _) => jQ(el).attr("a1", 1)) + jQ(dom).children("#el2").each((el, _) => jQ(el).attr("a2", 1)) + jQ(dom).children("#el3").each((el, _) => jQ(el).attr("a3", 1)) jQ(el1).attr("a1") should be(Some("1")) jQ(el1).attr("a2") should be(None) diff --git a/src/test/scala/io/udash/wrappers/jquery_test/TraversingTest.scala b/src/test/scala/io/udash/wrappers/jquery_test/TraversingTest.scala index c9b1860..d042acb 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/TraversingTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/TraversingTest.scala @@ -14,11 +14,11 @@ class TraversingTest extends WordSpec with Matchers { val el3 = h1.render val j1 = jQ(el1) - j1.each((el, _, _) => jQ(el).attr("a1", 1)) + j1.each((el, _) => jQ(el).attr("a1", 1)) val j2 = j1.add(el2) - j2.each((el, _, _) => jQ(el).attr("a2", 1)) + j2.each((el, _) => jQ(el).attr("a2", 1)) val j3 = j2.add(el3) - j3.each((el, _, _) => jQ(el).attr("a3", 1)) + j3.each((el, _) => jQ(el).attr("a3", 1)) jQ(el1).attr("a1") should be(Some("1")) jQ(el1).attr("a2") should be(Some("1")) @@ -39,7 +39,7 @@ class TraversingTest extends WordSpec with Matchers { val el3 = h1.render val selection = jQ(el1, el2, el3) - selection.each((el, _, _) => jQ(el).attr("a", 1)) + selection.each((el, _) => jQ(el).attr("a", 1)) jQ(el1).attr("a") should be(Some("1")) jQ(el2).attr("a") should be(Some("1")) @@ -52,7 +52,7 @@ class TraversingTest extends WordSpec with Matchers { val el3 = h1.render val selection = jQ(el1, el2, el3) - selection.filter("h1").each((el, _, _) => jQ(el).attr("a", 1)) + selection.filter("h1").each((el, _) => jQ(el).attr("a", 1)) jQ(el1).attr("a") should be(None) jQ(el2).attr("a") should be(None)