nondeterministic / scalajs-notifyjs   0.2.0

MIT License GitHub

A minimalistic Scala.js type facade for Notify.js

Scala versions: 2.13 2.12
Scala.js versions: 1.x 0.6

scalajs-notifyjs

A minimalistic Scala.js type facade for Notify.js supporting both ScalaJS 1.0 and 0.6

Installation

Add the following to your build.sbt:

libraryDependencies += "com.github.nondeterministic" %%% "scalajs-notifyjs" % "0.2.0"

(While the above should also work for Scala 0.6, I haven't tried it myself. You may want to fall back to version 0.1.1 in case of trouble.)

You also must make sure that the project, which you want to use scalajs-notifyjs in, has the corresponding JavaScript libraries available. To this end, you can either include them manually in your .html files, or add the following to your build.sbt:

jsDependencies += "org.webjars" % "jquery"   % "2.2.4" / "2.2.4/jquery.js"
jsDependencies += "org.webjars" % "notifyjs" % "0.4.2" / "0.4.2/notify.js"

Usage

Currently, there are basically three different use cases supported, all of which are demonstrated in the piece of code below.

import org.scalajs.jquery.jQuery
import scalatags.JsDom.all._
import com.github.nondeterministic.notifyjs._

object TutorialApp {
  def main(args: Array[String]): Unit = {
    val myHtml = div(id:="pos-demo", p("Message!"))
    jQuery("body").append(myHtml.render)

    // Some ordinary notifications:
    // Corresponds to the following JavaScript call:
    // $.notify("Warning!", "warn");
    Notify("Warning!", "warn")
    Notify("Error!", "error")
    Notify("Info!", "info")
	  
    // A bit of customisation:
    Notify("I'm a lefty!", new Options { override val globalPosition = "left" })

    // Positioning relative to an HTML-element:
    // Corresponds to the following JavaScript call:
    // $('#pos-demo').notify('Near Message!', { position:'bottom', className:'info', autoHide:false });
    Notify(jQuery("#pos-demo"), 
          "I'm a relativist!", 
          new Options { override val className = "info";
                        override val globalPosition = "bottom";
                        override val autoHide = false})
  }
}