diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cf04a0d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,91 @@ +name: CI + +env: + JAVA_OPTS: "-Dfile.encoding=UTF-8 -Xms1024M -Xmx3072M -Xss4M -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler" + +on: + push: + branches: '*' + tags: [ "v[0-9]+*" ] + pull_request: + # avoid duplicate checks (push & PR) further in the review process + types: [opened] + +jobs: + test: + name: Run tests + runs-on: ubuntu-20.04 # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md + strategy: + fail-fast: false + matrix: + scala: [ 2.13.12 ] + command: [ test ] + steps: + - uses: actions/checkout@v2 + - name: Cache sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache + ~/.cache/coursier + key: ${{ runner.os }}-sbt-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}-${{ hashFiles('project/Dependencies.scala') }} + restore-keys: ${{ runner.os }}-sbt- + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache npm + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: ${{ runner.os }}-node- + - name: Set up node + uses: actions/setup-node@v2-beta + - name: Run tests + run: sbt "set concurrentRestrictions in Global += Tags.limit(ScalaJSTags.Link, 1)" ++${{ matrix.scala }} ${{ matrix.command }} + + publish: + name: Publish to Sonatype + # only run on tag push + if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v')) + needs: [ test ] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Cache sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache + ~/.cache/coursier + key: ${{ runner.os }}-sbt-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}-${{ hashFiles('project/Dependencies.scala') }} + restore-keys: ${{ runner.os }}-sbt- + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Get version + id: get_tag_name + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v} + - name: Import GPG key + env: + #exported via `gpg -a --export-secret-keys | cat -e | sed 's/\$/\\n/g' | xclip -selection clipboard` and added to org secrets + SONATYPE_GPG: ${{ secrets.SONATYPE_GPG }} + run: echo -e $SONATYPE_GPG | gpg --import - + - name: Publish artifacts + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + run: sbt 'set version in ThisBuild := "${{ steps.get_tag_name.outputs.VERSION }}"' +publishSigned + - name: Release Sonatype bundle + #https://github.com/xerial/sbt-sonatype#publishing-your-artifact + if: ${{ !endsWith(steps.get_tag_name.outputs.VERSION, 'SNAPSHOT') }} + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + run: sbt 'set version in ThisBuild := "${{ steps.get_tag_name.outputs.VERSION }}"' sonatypeBundleRelease diff --git a/.gitignore b/.gitignore index c67de7b..de4683c 100644 --- a/.gitignore +++ b/.gitignore @@ -84,7 +84,7 @@ buildNumber.properties ## Plugin-specific files: # IntelliJ -/out/ +out/ # mpeltonen/sbt-idea plugin .idea_modules/ @@ -117,6 +117,7 @@ hs_err_pid* .cache .history .lib/ +.bsp/ dist/* target/ lib_managed/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 56f862c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: scala -dist: trusty - -jdk: openjdk11 - -scala: - - 2.13.1 - -before_script: - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - - sleep 3 # give xvfb some time to start - # Instal google-chrome - - export CHROME_BIN=/usr/bin/google-chrome - - sudo apt-get update - - sudo apt-get install -y libappindicator1 fonts-liberation - - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb - - sudo dpkg -i google-chrome*.deb - # Install Selenium chromedriver - - wget http://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip - - unzip chromedriver_linux64.zip -d selenium-bin - - export PATH=$PWD/selenium-bin:$PATH - -script: - - sbt +test +publishLocal - - cd example && sbt compile jquery-global-demo/fullOptJS jquery-bundler-demo/compileStatics \ No newline at end of file diff --git a/README.md b/README.md index 77158a1..f5492de 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# scala-js-jquery [![Build Status](https://travis-ci.org/UdashFramework/scala-js-jquery.svg?branch=master)](https://travis-ci.org/UdashFramework/scala-js-jquery) [![Join the chat at https://gitter.im/UdashFramework/scala-js-jquery](https://badges.gitter.im/UdashFramework/scala-js-jquery.svg)](https://gitter.im/UdashFramework/scala-js-jquery?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](http://www.avsystem.com/) +# udash-jquery [](http://www.avsystem.com/) + +[![CI](https://github.com/UdashFramework/scala-js-jquery/actions/workflows/ci.yml/badge.svg)](https://github.com/UdashFramework/scala-js-jquery/actions/workflows/ci.yml)[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.udash/udash-jquery_sjs1_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.udash/udash-jquery_sjs1_2.13) +[![Join the chat at https://gitter.im/UdashFramework/scala-js-jquery](https://badges.gitter.im/UdashFramework/scala-js-jquery.svg)](https://gitter.im/UdashFramework/scala-js-jquery?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Static types for the jQuery API for [Scala.js](http://www.scala-js.org/) programs. @@ -7,7 +10,7 @@ Static types for the jQuery API for [Scala.js](http://www.scala-js.org/) program Add the following dependency to your SBT build: ```scala -libraryDependencies += "io.udash" %%% "udash-jquery" % "3.0.2" +libraryDependencies += "io.udash" %%% "udash-jquery" % "3.3.0" ``` then import the jQuery package: @@ -16,21 +19,9 @@ then import the jQuery package: import io.udash.wrappers.jquery._ ``` -Since version `3.0.0` the wrapper is published as a CommonJS module with JS dependencies managed -by [scalajs-bundler](https://github.com/scalacenter/scalajs-bundler). - -If you do not want to use the bundler, you have to include jQuery sources manually by: - * explicit link in your `index.html`. - ```html - - ``` - * or a [Scala.js dependency](http://www.scala-js.org/doc/project/dependencies.html). - ```scala - jsDependencies += - "org.webjars" % "jquery" % "3.3.1" / "3.3.1/jquery.js" minified "3.3.1/jquery.min.js" - ``` +Since version `3.0.4` the wrapper targets SJS 1.x series and supports JS dependencies managed by +by [scalajs-bundler](https://github.com/scalacenter/scalajs-bundler) or [sbt-jsdependencies +](https://github.com/scala-js/jsdependencies) ## Examples diff --git a/build.sbt b/build.sbt index 383767f..065d200 100644 --- a/build.sbt +++ b/build.sbt @@ -1,15 +1,12 @@ - - name := "udash-jquery" inThisBuild(Seq( - version := "3.0.2", + version := "3.3.0-SNAPSHOT", organization := "io.udash", )) val commonSettings = Seq( - scalaVersion := "2.13.1", - crossScalaVersions := Seq("2.12.10", "2.13.1"), + scalaVersion := "2.13.12", scalacOptions ++= Seq( "-feature", "-deprecation", @@ -17,44 +14,77 @@ val commonSettings = Seq( "-language:implicitConversions", "-language:existentials", "-language:dynamics", - "-language:postfixOps", "-language:experimental.macros", "-Xfatal-warnings", "-Xlint:_", - "-Ywarn-unused:_,-explicits,-implicits", - "-Ybackend-parallelism", "4", + "-Ybackend-parallelism", "8", "-Ycache-plugin-class-loader:last-modified", "-Ycache-macro-class-loader:last-modified", ), ) val commonJSSettings = Seq( - Compile / emitSourceMaps := true, - Test / parallelExecution := false, Test / scalaJSStage := FastOptStage, - // ScalaJSBundlerPlugin does not work with scalajs-env-selenium: - // https://github.com/scalacenter/scalajs-bundler/issues/89 - // Test / jsEnv := new SeleniumJSEnv(browserCapabilities), + Test / requireJsDomEnv := true, + npmExtraArgs += "--silent", scalacOptions += { val localDir = (ThisBuild / baseDirectory).value.toURI.toString val githubDir = "https://raw.githubusercontent.com/UdashFramework/scala-js-jquery" s"-P:scalajs:mapSourceURI:$localDir->$githubDir/v${version.value}/" }, - scalacOptions += "-P:scalajs:sjsDefinedByDefault", + webpack / version := "5.75.0", // TODO: can be removed when sbt-scalajs-bundler > 0.21.1 +) + +val deploymentConfiguration = Seq( + publishMavenStyle := true, + Test / publishArtifact := false, + pomIncludeRepository := { _ => false }, + + publishTo := sonatypePublishToBundle.value, + + credentials in Global += Credentials( + "Sonatype Nexus Repository Manager", + "oss.sonatype.org", + sys.env.getOrElse("SONATYPE_USERNAME", ""), + sys.env.getOrElse("SONATYPE_PASSWORD", "") + ), + + pomExtra := { + https://github.com/UdashFramework/scala-js-jquery + + + Apache v.2 License + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + git@github.com:UdashFramework/scala-js-jquery.git + scm:git@github.com:UdashFramework/scala-js-jquery.git + + + + avsystem + AVSystem + http://www.avsystem.com/ + + + } ) lazy val root = project.in(file(".")) - .enablePlugins(ScalaJSBundlerPlugin) + .enablePlugins(ScalaJSBundlerPlugin, JSDependenciesPlugin) .settings( commonSettings, commonJSSettings, + deploymentConfiguration, libraryDependencies ++= Seq( - "org.scala-js" %%% "scalajs-dom" % "0.9.7", - "org.scalatest" %%% "scalatest" % "3.0.8" % Test, - "com.lihaoyi" %%% "scalatags" % "0.7.0" % Test + "org.scala-js" %%% "scalajs-dom" % "2.7.0", + "org.scalatest" %%% "scalatest" % "3.2.9" % Test, + "com.lihaoyi" %%% "scalatags" % "0.10.0" % Test ), - Compile / npmDependencies += "jquery" -> "3.3.1", - Test / requireJsDomEnv := true + Compile / npmDependencies += "jquery" -> "3.6.4", + jsDependencies += "org.webjars" % "jquery" % "3.6.4" / "3.6.4/jquery.js" minified s"3.6.4/jquery.min.js", ) diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index 75bb5f2..0000000 --- a/example/.gitignore +++ /dev/null @@ -1,132 +0,0 @@ -# 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/README.md b/example/README.md deleted file mode 100644 index ea8efda..0000000 --- a/example/README.md +++ /dev/null @@ -1,13 +0,0 @@ -The `build.sbt` file contains two configurations: -* `jquery-global-demo` uses global jQuery dependency. -* `jquery-bundler-demo` uses `ScalaJSBundlerPlugin` in order to manage module dependencies. - -### How to use? - -Run `sbt jquery-global-demo/fastOptJS` or `sbt jquery-global-demo/fullOptJS` to compile this demo. You can find all generated files -in the `generated/global` directory. Open `index.html` in your browser. - -### How to use? (ScalaJSBundlerPlugin) - -Run `sbt jquery-bundler-demo/compileStatics` to compile this demo. You can find all generated files -in the `generated/bundler` directory. Open `index.html` in your browser. \ No newline at end of file diff --git a/example/build.sbt b/example/build.sbt deleted file mode 100644 index 04eeabb..0000000 --- a/example/build.sbt +++ /dev/null @@ -1,124 +0,0 @@ -name := "jquery-demo" - -inThisBuild(Seq( - version := "3.0.1", - organization := "io.udash", -)) - -val commonSettings = Seq( - scalaVersion := "2.12.10", - crossScalaVersions := Seq("2.12.10"), //todo 2.13 - scalacOptions ++= Seq( - "-feature", - "-deprecation", - "-unchecked", - "-language:implicitConversions", - "-language:existentials", - "-language:dynamics", - "-language:postfixOps", - "-Xfatal-warnings", - "-Xlint:_", - "-Ywarn-unused:_,-explicits,-implicits", - "-Ybackend-parallelism", "4", - "-Ycache-plugin-class-loader:last-modified", - "-Ycache-macro-class-loader:last-modified" - ), - - libraryDependencies ++= Dependencies.deps.value -) - -val generatedGlobalDir = file("generated/global") -val copyAssets = taskKey[Unit]("Copies all assets to the target directory.") -val root = project.in(file(".")) - .enablePlugins(ScalaJSPlugin) - .settings(commonSettings) - -val `jquery-global-demo` = project.in(file("global-demo")) - .enablePlugins(ScalaJSPlugin) - .settings( - commonSettings, - - jsDependencies ++= Dependencies.jsDeps.value, - - sourceDirsSettings(_.getParentFile), - - /* move these files out of target/. */ - Compile / fullOptJS / crossTarget := generatedGlobalDir, - Compile / fastOptJS / crossTarget := generatedGlobalDir, - Compile / packageJSDependencies / crossTarget := generatedGlobalDir, - Compile / packageMinifiedJSDependencies / crossTarget := generatedGlobalDir, - - Compile / fastOptJS := (Compile / fastOptJS).dependsOn(copyAssets).value, - Compile / fullOptJS := (Compile / fullOptJS).dependsOn(copyAssets).value, - - scalaJSUseMainModuleInitializer := true, - - copyAssets := { - IO.copyFile( - sourceDirectory.value / "main/assets/index.html", - generatedGlobalDir / "index.html" - ) - }, - - Compile / fastOptJS / artifactPath := - (Compile / fastOptJS / crossTarget).value / "scripts" / "frontend-impl.js", - Compile / fullOptJS / artifactPath := - (Compile / fullOptJS / crossTarget).value / "scripts" / "frontend-impl.js", - Compile / packageJSDependencies / artifactPath := - (Compile / packageJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js", - Compile / packageMinifiedJSDependencies / artifactPath := - (Compile / packageMinifiedJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js" - ) - -val generatedBundlerDir = file("generated/bundler") -val compileStatics = taskKey[Unit]("Compiles all static files.") -val `jquery-bundler-demo` = project.in(file("bundler-demo")) - .enablePlugins(ScalaJSBundlerPlugin) - .settings( - commonSettings, - - sourceDirsSettings(_.getParentFile), - - Compile / scalaJSUseMainModuleInitializer := true, - - copyAssets := { - IO.copyFile( - sourceDirectory.value / "main/assets/index.html", - generatedBundlerDir / "index.html" - ) - }, - - compileStatics := { - val sjsFileName = (Compile / fastOptJS).value.data.name.stripSuffix(".js") - IO.copyFile( - (Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js", - generatedBundlerDir / "scripts/frontend.js" - ) - IO.copyFile( - (Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js.map", - generatedBundlerDir / "scripts/frontend.js.map" - ) - }, - compileStatics := compileStatics.dependsOn(Compile / fastOptJS / webpack, copyAssets).value, - ) - -def mkSourceDirs(base: File, scalaBinary: String, conf: String): Seq[File] = Seq( - base / "src" / conf / "scala", - base / "src" / conf / s"scala-$scalaBinary", - base / "src" / conf / "java" -) - -def mkResourceDirs(base: File, conf: String): Seq[File] = Seq( - base / "src" / conf / "resources" -) - -def sourceDirsSettings(baseMapper: File => File) = Seq( - Compile / unmanagedSourceDirectories ++= - mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "main"), - Compile / unmanagedResourceDirectories ++= - mkResourceDirs(baseMapper(baseDirectory.value), "main"), - Test / unmanagedSourceDirectories ++= - mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "test"), - Test / unmanagedResourceDirectories ++= - mkResourceDirs(baseMapper(baseDirectory.value), "test"), -) \ No newline at end of file diff --git a/example/bundler-demo/src/main/assets/index.html b/example/bundler-demo/src/main/assets/index.html deleted file mode 100644 index 45d07e6..0000000 --- a/example/bundler-demo/src/main/assets/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - jquery-demo - ScalaJSBundlerPlugin demo - - -
- - - - \ No newline at end of file diff --git a/example/global-demo/src/main/assets/index.html b/example/global-demo/src/main/assets/index.html deleted file mode 100644 index b746eab..0000000 --- a/example/global-demo/src/main/assets/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - jquery-demo - global scope - - -
- - - - - \ No newline at end of file diff --git a/example/project/Dependencies.scala b/example/project/Dependencies.scala deleted file mode 100644 index caa9172..0000000 --- a/example/project/Dependencies.scala +++ /dev/null @@ -1,17 +0,0 @@ -import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ -import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._ -import sbt._ - -object Dependencies { - val udashCoreVersion = "0.8.1" - val udashJQueryVersion = "3.0.2" - - val deps = Def.setting(Seq[ModuleID]( - "io.udash" %%% "udash-core" % udashCoreVersion, - "io.udash" %%% "udash-jquery" % udashJQueryVersion - )) - - val jsDeps = Def.setting(Seq[org.scalajs.sbtplugin.JSModuleID]( - "org.webjars" % "jquery" % "3.3.1" / "3.3.1/jquery.js" minified "3.3.1/jquery.min.js" - )) -} \ No newline at end of file diff --git a/example/project/build.properties b/example/project/build.properties deleted file mode 100644 index ebcc8ac..0000000 --- a/example/project/build.properties +++ /dev/null @@ -1,2 +0,0 @@ -# suppress inspection "UnusedProperty" -sbt.version=1.3.2 \ No newline at end of file diff --git a/example/project/plugins.sbt b/example/project/plugins.sbt deleted file mode 100644 index cafe39a..0000000 --- a/example/project/plugins.sbt +++ /dev/null @@ -1,4 +0,0 @@ -logLevel := Level.Warn - -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.29") -addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.15.0-0.6") \ 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 deleted file mode 100644 index f43d899..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/RoutingRegistryDef.scala +++ /dev/null @@ -1,29 +0,0 @@ -package io.udash.demos.jquery - -import io.udash._ - -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 { - 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 deleted file mode 100644 index dee3a6e..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/StatesToViewPresenterDef.scala +++ /dev/null @@ -1,27 +0,0 @@ -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 ViewFactoryRegistry[RoutingState] { - def matchStateToResolver(state: RoutingState): ViewFactory[_ <: 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 deleted file mode 100644 index 549798b..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/init.scala +++ /dev/null @@ -1,32 +0,0 @@ -package io.udash.demos.jquery - -import io.udash._ -import io.udash.wrappers.jquery._ -import org.scalajs.dom -import org.scalajs.dom.Element - -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) -} - -object Init { - import Context._ - - @JSExport - def main(args: Array[String]): Unit = { - jQ((_: 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 deleted file mode 100644 index f4e7452..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/states.scala +++ /dev/null @@ -1,32 +0,0 @@ -package io.udash.demos.jquery - -import io.udash._ - -sealed abstract class RoutingState(val parentState: Option[ContainerRoutingState]) extends State { - type HierarchyRoot = RoutingState - - def url(implicit application: Application[RoutingState]): String = - s"#${application.matchState(this).value}" -} - -sealed abstract class ContainerRoutingState(parentState: Option[ContainerRoutingState]) extends RoutingState(parentState) with ContainerState -sealed abstract class FinalRoutingState(parentState: ContainerRoutingState) extends RoutingState(Option(parentState)) with FinalState - - -case object RootState extends ContainerRoutingState(None) -case object ErrorState extends FinalRoutingState(RootState) -case object IndexState extends FinalRoutingState(RootState) -case object AddState extends FinalRoutingState(RootState) -case object AddBackState extends FinalRoutingState(RootState) -case object AfterBeforeState extends FinalRoutingState(RootState) -case object AnimateState extends FinalRoutingState(RootState) -case object AppendPrependState extends FinalRoutingState(RootState) -case object AttrState extends FinalRoutingState(RootState) -case object CallbacksState extends FinalRoutingState(RootState) -case object ChildrenState extends FinalRoutingState(RootState) -case object DataState extends FinalRoutingState(RootState) -case object DeferredState extends FinalRoutingState(RootState) -case object EachState extends FinalRoutingState(RootState) -case object HideShowState extends FinalRoutingState(RootState) -case object OffsetPositionState extends FinalRoutingState(RootState) -case object OnOneOffState extends FinalRoutingState(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 deleted file mode 100644 index a2b8fa7..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/ErrorView.scala +++ /dev/null @@ -1,13 +0,0 @@ -package io.udash.demos.jquery.views - -import io.udash._ -import io.udash.demos.jquery.IndexState - -object ErrorViewPresenter extends StaticViewFactory[IndexState.type](() => new ErrorView) - -class ErrorView extends FinalView { - import scalatags.JsDom.all._ - - override def getTemplate: Modifier = - h3("URL not found!") -} \ 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 deleted file mode 100644 index 5874d47..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/FunctionView.scala +++ /dev/null @@ -1,22 +0,0 @@ -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") - ) -} \ 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 deleted file mode 100644 index cad18f0..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/IndexView.scala +++ /dev/null @@ -1,33 +0,0 @@ -package io.udash.demos.jquery.views - -import io.udash._ -import io.udash.demos.jquery._ - -object IndexViewPresenter extends StaticViewFactory[IndexState.type](() => new IndexView) - -class IndexView extends FinalView { - 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()")) - ) - ) - - override def getTemplate: Modifier = content -} \ 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 deleted file mode 100644 index 3906559..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/RootView.scala +++ /dev/null @@ -1,16 +0,0 @@ -package io.udash.demos.jquery.views - -import io.udash._ -import io.udash.demos.jquery.{Context, IndexState, RootState} - -object RootViewPresenter extends StaticViewFactory[RootState.type](() => new RootView) - -class RootView extends ContainerView { - import Context._ - import scalatags.JsDom.all._ - - override def getTemplate: Modifier = div( - a(href := IndexState.url)(h1("jquery-demo")), - childViewContainer - ) -} \ 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 deleted file mode 100644 index cdc25ba..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/AddBackView.scala +++ /dev/null @@ -1,62 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 9c0b0d8..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/AddView.scala +++ /dev/null @@ -1,48 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 7e61e09..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/AfterView.scala +++ /dev/null @@ -1,29 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index c1c8693..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/AnimateView.scala +++ /dev/null @@ -1,77 +0,0 @@ -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 StaticViewFactory[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").on(EventName.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").on(EventName.click, (_: Element, _: JQueryEvent) => { - jQ("#block2") - .animate(Map("width" -> "90%"), 1000) - .animate(Map("fontSize" -> "24px"), 1000) - .animate(Map("borderLeftWidth" -> "15px"), 1000) - }) - - jQ("#go3").on(EventName.click, (_: Element, _: JQueryEvent) => { - jQ("#go1").add("#go2").trigger("click") - }) - - jQ("#go4").on(EventName.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 deleted file mode 100644 index 2908b43..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/AppendPrependView.scala +++ /dev/null @@ -1,25 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 7ae29d0..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/AttrView.scala +++ /dev/null @@ -1,51 +0,0 @@ -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 StaticViewFactory[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").trigger("change") - false - }))(".attr(\"data-checked\", \"checked\")"), - button(onclick :+= ((_: Event) => { - jQ(".demo input").attr("data-checked", "").trigger("change") - false - }))(".attr(\"data-checked\", \"\")"), - button(onclick :+= ((_: Event) => { - jQ(".demo input").attr("data-checked", null).trigger("change") - false - }))(".attr(\"data-checked\", null)"), br(), - button(onclick :+= ((_: Event) => { - jQ(".demo input").prop("checked", true).trigger("change") - false - }))(".prop(\"checked\", true)"), - button(onclick :+= ((_: Event) => { - jQ(".demo input").prop("checked", false).trigger("change") - false - }))(".prop(\"checked\", false)") - ).render - - override protected val script = () => { - jQ(".demo input").on(EventName.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 - ) - }).trigger("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 deleted file mode 100644 index e3824bb..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/CallbacksView.scala +++ /dev/null @@ -1,50 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index ea4d0f6..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/ChildrenView.scala +++ /dev/null @@ -1,29 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index f905ec5..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/DataView.scala +++ /dev/null @@ -1,30 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 82ee717..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/DeferredView.scala +++ /dev/null @@ -1,55 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 447267b..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/EachView.scala +++ /dev/null @@ -1,27 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 9ed0a46..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/HideShowView.scala +++ /dev/null @@ -1,27 +0,0 @@ -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 StaticViewFactory[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 deleted file mode 100644 index 9ec5d02..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/OffsetPositionView.scala +++ /dev/null @@ -1,33 +0,0 @@ -package io.udash.demos.jquery.views.functions - -import io.udash._ -import io.udash.demos.jquery.OffsetPositionState -import io.udash.demos.jquery.views.FunctionView -import io.udash.wrappers.jquery._ - -object OffsetPositionViewPresenter extends StaticViewFactory[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 deleted file mode 100644 index 08035d0..0000000 --- a/example/src/main/scala/io/udash/demos/jquery/views/functions/OnOneOffView.scala +++ /dev/null @@ -1,44 +0,0 @@ -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 StaticViewFactory[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(EventName.click, onCallback) - .off(EventName.click, oneCallback) - false - }) - )("Off") - ).render - - override protected val script = () => { - jQ(".demo #click") - .on(EventName.click, onCallback) - .one(EventName.click, oneCallback) - - jQ(".demo button") - .prop("disabled", "") - } -} \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index ebcc8ac..ff95dc2 100755 --- a/project/build.properties +++ b/project/build.properties @@ -1,2 +1,2 @@ # suppress inspection "UnusedProperty" -sbt.version=1.3.2 \ No newline at end of file +sbt.version=1.9.6 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 6b9840d..fa4a47a 100755 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,9 @@ logLevel := Level.Warn -libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "0.3.0" +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.1") +addSbtPlugin("org.scala-js" % "sbt-jsdependencies" % "1.0.2") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.29") -addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.15.0-0.6") +// Deployment configuration +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10") \ No newline at end of file diff --git a/src/main/scala/io/udash/wrappers/jquery/JQuery.scala b/src/main/scala/io/udash/wrappers/jquery/JQuery.scala index 8218c5a..89f1be9 100644 --- a/src/main/scala/io/udash/wrappers/jquery/JQuery.scala +++ b/src/main/scala/io/udash/wrappers/jquery/JQuery.scala @@ -164,6 +164,10 @@ trait JQuery extends js.Object { @JSName("eq") def at(index: Int): JQuery = js.native + /** Reduce the set of matched elements to the even ones in the set, numbered from zero.
+ * See: jQuery Docs */ + def even(): JQuery = js.native + /** Display the matched elements by fading them to opaque.
* See: jQuery Docs */ def fadeIn(duration: Int = js.native, easing: EasingFunction = js.native): JQuery = js.native @@ -381,6 +385,10 @@ trait JQuery extends js.Object { * See: jQuery Docs */ def not(el: Element*): JQuery = js.native + /** Reduce the set of matched elements to the odd ones in the set, numbered from zero.
+ * See: jQuery Docs */ + def odd(): JQuery = js.native + /** Remove an event handler.
* See: jQuery Docs */ def off(): JQuery = js.native diff --git a/src/test/scala/io/udash/wrappers/jquery_test/DomManipulationTest.scala b/src/test/scala/io/udash/wrappers/jquery_test/DomManipulationTest.scala index ede038d..d16b4cc 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/DomManipulationTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/DomManipulationTest.scala @@ -1,8 +1,10 @@ package io.udash.wrappers.jquery_test -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec + +class DomManipulationTest extends AnyWordSpec with Matchers { -class DomManipulationTest extends WordSpec with Matchers { import io.udash.wrappers.jquery._ import scalatags.JsDom.all._ diff --git a/src/test/scala/io/udash/wrappers/jquery_test/EventsHandlingTest.scala b/src/test/scala/io/udash/wrappers/jquery_test/EventsHandlingTest.scala index 42fea1c..710fa0a 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/EventsHandlingTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/EventsHandlingTest.scala @@ -1,10 +1,13 @@ +package io.udash.wrappers.jquery_test + import org.scalajs.dom.Element import org.scalajs.dom.html.Input -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec -class EventsHandlingTest extends WordSpec with Matchers { - import io.udash.wrappers.jquery._ +class EventsHandlingTest extends AnyWordSpec with Matchers { + import io.udash.wrappers.jquery._ import scalatags.JsDom.all._ class C(i: Int) diff --git a/src/test/scala/io/udash/wrappers/jquery_test/MiscellaneousTest.scala b/src/test/scala/io/udash/wrappers/jquery_test/MiscellaneousTest.scala index 95b3953..4d32382 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/MiscellaneousTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/MiscellaneousTest.scala @@ -1,10 +1,11 @@ package io.udash.wrappers.jquery_test -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec -class MiscellaneousTest extends WordSpec with Matchers { - import io.udash.wrappers.jquery._ +class MiscellaneousTest extends AnyWordSpec with Matchers { + import io.udash.wrappers.jquery._ import scalatags.JsDom.all._ class C(i: Int) @@ -45,7 +46,8 @@ class MiscellaneousTest extends WordSpec with Matchers { } "serialize objects to URL query string" in { - import scala.scalajs.js, js.JSConverters._ + import scala.scalajs.js + import js.JSConverters._ jQ.param(js.Dynamic.literal("a" -> Seq(1, 2, 3).toJSArray, "b" -> "c")) should be("a%5B%5D=1&a%5B%5D=2&a%5B%5D=3&b=c") } } 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 6654210..61ea636 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/SelectorsTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/SelectorsTest.scala @@ -1,8 +1,10 @@ package io.udash.wrappers.jquery_test -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec + +class SelectorsTest extends AnyWordSpec with Matchers { -class SelectorsTest extends WordSpec with Matchers { import io.udash.wrappers.jquery._ import scalatags.JsDom.all._ 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 1400684..2ff1b89 100644 --- a/src/test/scala/io/udash/wrappers/jquery_test/TraversingTest.scala +++ b/src/test/scala/io/udash/wrappers/jquery_test/TraversingTest.scala @@ -1,10 +1,11 @@ package io.udash.wrappers.jquery_test -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec -class TraversingTest extends WordSpec with Matchers { - import io.udash.wrappers.jquery._ +class TraversingTest extends AnyWordSpec with Matchers { + import io.udash.wrappers.jquery._ import scalatags.JsDom.all._ "jQuery" should { @@ -165,5 +166,21 @@ class TraversingTest extends WordSpec with Matchers { root.children("a").first().length should be(0) root.children("a").last().length should be(0) } + + "even/odd matching element" in { + val dom = div( + span("0"), + span("1"), + span("2"), + span("3"), + span("4"), + span("5"), + ).render + + val root = jQ(dom) + root.children("span").even().text() shouldBe "024" + root.children("span").odd().text() shouldBe "135" + } + } }