From ac779d14fc1451255127fc7b4a5c07e9eb4b4402 Mon Sep 17 00:00:00 2001 From: coreyauger Date: Tue, 1 Sep 2015 10:52:32 -0700 Subject: [PATCH 1/6] Add the Notification API --- example/src/main/scala/example/Example.scala | 33 ++ .../dom/experimental/Notification.scala | 389 ++++++++++++++++++ 2 files changed, 422 insertions(+) create mode 100644 src/main/scala/org/scalajs/dom/experimental/Notification.scala diff --git a/example/src/main/scala/example/Example.scala b/example/src/main/scala/example/Example.scala index fa0517b2e..6307cd61b 100644 --- a/example/src/main/scala/example/Example.scala +++ b/example/src/main/scala/example/Example.scala @@ -173,3 +173,36 @@ object AjaxExtension { } } } + + +@JSExport +object Notification { + @JSExport + def main(in: html.Button) = { + import org.scalajs.dom.experimental.Notification._ + + def notifyMe() { + // Let's check whether notification permissions have already been granted + if (dom.window.Notification.permission == "granted") { + // If it's okay let's create a notification + var notification = new Notification("Hi there!") + } + + // Otherwise, we need to ask the user for permission + else if (dom.window.Notification.permission != "denied") { + dom.window.Notification.requestPermission( (permission:String) => { + // If the user accepts, let's create a notification + if (permission == "granted") { + var notification = new Notification("Hi there!") + } + }) + } + // At last, if the user has denied notifications, and you + // want to be respectful there is no need to bother them any more. + } + + in.onclick = (e: dom.Event) => { + notifyMe + } + } +} diff --git a/src/main/scala/org/scalajs/dom/experimental/Notification.scala b/src/main/scala/org/scalajs/dom/experimental/Notification.scala new file mode 100644 index 000000000..b33205528 --- /dev/null +++ b/src/main/scala/org/scalajs/dom/experimental/Notification.scala @@ -0,0 +1,389 @@ +package org.scalajs.dom.experimental + +import org.scalajs.dom.raw.EventTarget +import scala.language.implicitConversions +import scala.scalajs.js + + +trait NotificationOptions extends js.Object { + /** + * The body property of the Notification interface indicates the + * body string of the notification. + * + * MDN + */ + val body: String = js.native + + /** + * The dir property of the Notification interface indicates the + * text direction of the notification. + * + * MDN + */ + var dir: String = js.native + + /** + * The icon property of the Notification interface contains the + * URL of an icon to be displayed as part of the notification. + * + * MDN + */ + var icon: String = js.native + + /** + * The lang property of the Notification interface indicates the + * text direction of the notification. + * + * MDN + */ + var lang: String = js.native + + /** + * The noscreen property of the Notification interface specifies + * whether the notification firing should enable the device's screen or not. + * + * MDN + */ + var noscreen: Boolean = js.native + + /** + * The renotify property of the Notification interface specifies + * whether the user should be notified after a new notification replaces an + * old one. + * + * MDN + */ + var renotify: Boolean = js.native + + /** + * The silent property of the Notification interface specifies + * whether the notification should be silent, i.e. no sounds or vibrations + * should be issued, regardless of the device settings. + * + * MDN + */ + var silent: Boolean = js.native + + /** + * The sound property of the Notification interface specifies the + * URL of an audio file to be played when the notification fires. + * + * MDN + */ + var sound: String = js.native + + /** + * The sticky property of the Notification interface specifies + * whether the notification should be 'sticky', i.e. not easily clearable + * by the user. + * + * MDN + */ + var sticky: Boolean = js.native + + /** + * The tag property of the Notification interface signifies an + * identifying tag for the notification. + * + * The idea of notification tags is that more than one notification can + * share the same tag, linking them together. One notification can then + * be programmatically replaced with another to avoid the users' screen + * being filled up with a huge number of similar notifications. + * + * MDN + */ + var tag: String = js.native + + /** + * The title property of the Notification interface indicates + * the title of the notification. + * + * MDN + */ + var title: String = js.native + + var vibrate: js.Object = js.native +} + +object NotificationOptions { + /** + * Construct a new NotificationOptions + * + * @param body The body text of the notification. + * @param dir The text direction of the notification. + * @param icon The icon URL of the notification. + * @param lang The text direction of the notification. + * @param noscreen Boolean indicating if notification firing should enable + * the device's screen or not + * @param renotify Boolean indicating whether the user should be notified + * after a new notification replaces an old one. + * @param silent Boolean indicating specifies whether the notification + * should be silent, i.e. no sounds or vibrations should + * be issued, regardless of the device settings + * @param sound The URL of an audio file to be played when the + * notification fires. + * @param sticky Boolean indicating whether the notification should be + * 'sticky', i.e. not easily clearable by the user. + * @param tag A text identifying tag for the notification. + * @param title The text title of the notification + * @param vibrate The vibration pattern for hardware to emit + * @return a new NotificationOptions + */ + @inline + def apply(body: js.UndefOr[String] = js.undefined, + dir: js.UndefOr[String] = js.undefined, + icon: js.UndefOr[String] = js.undefined, + lang: js.UndefOr[String] = js.undefined, + noscreen: js.UndefOr[Boolean] = js.undefined, + renotify: js.UndefOr[Boolean] = js.undefined, + silent: js.UndefOr[Boolean] = js.undefined, + sound: js.UndefOr[String] = js.undefined, + sticky: js.UndefOr[Boolean] = js.undefined, + tag: js.UndefOr[String] = js.undefined, + title: js.UndefOr[String] = js.undefined, + vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { + val result = js.Dynamic.literal() + body.foreach(result.body = _) + dir.foreach(result.dir = _) + icon.foreach(result.icon = _) + lang.foreach(result.lang = _) + noscreen.foreach(result.noscreen = _) + renotify.foreach(result.renotify = _) + silent.foreach(result.silent = _) + sound.foreach(result.sound = _) + sticky.foreach(result.sticky = _) + tag.foreach(result.tag = _) + title.foreach(result.title = _) + vibrate.foreach(result.vibrate = _) + result.asInstanceOf[NotificationOptions] + } +} + +/** + * Implicit imports for the notification api. + * + * https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API + */ +object Notification { + implicit def toNotification(w: org.scalajs.dom.Window): NotificationWindow = + w.asInstanceOf[NotificationWindow] + + class NotificationWindow extends js.Any { + /** Return an interface to the Notification API */ + def Notification: Notification = js.native + + } + + /** + * The Notification interface allows to notify users of an incoming message + * or event + * NOTE: requires permission + * Note: This feature is available in Web Workers. + * + * MDN + */ + class Notification extends EventTarget { + /** + * Construct a new Notification + * + * @param title The text title of the notification + * @param options The options to configure this notification + * @return a new Notification + */ + def this(title:js.UndefOr[String] = js.undefined, + options:js.UndefOr[NotificationOptions] = js.undefined) = this() + + /** + * The body read-only property of the Notification interface indicates the + * body string of the notification, as specified in the body option of the + * Notification() constructor. + * + * MDN + */ + val body: String = js.native + + /** + * The data read-only property of the Notification interface returns a + * structured clone of the notification's data, as specified in the + * data option of the Notification() constructor. + * + * The notification's data can be any arbitrary data that you want + * associated with the notification. + * + * MDN + */ + var data: js.Object = js.native + + /** + * The dir read-only property of the Notification interface indicates the + * text direction of the notification, asspecified in the dir option of + * the Notification() constructor. + * + * MDN + */ + var dir: String = js.native + + /** + * The icon read-only property of the Notification interface contains the + * URL of an icon to be displayed as part of the notification, as specified + * in the icon option of the Notification() constructor. + * + * MDN + */ + var icon: String = js.native + + /** + * The lang read-only property of the Notification interface indicates the + * text direction of the notification, as specified in the lang option of + * the Notification() constructor. + * + * MDN + */ + var lang: String = js.native + + /** + * The noscreen read-only property of the Notification interface specifies + * whether the notification firing should enable the device's screen or not, + * as specified in the noscreen option of the Notification() constructor. + * + * MDN + */ + var noscreen: Boolean = js.native + + /** + * The onclick property of the Notification interface specifies an event + * listener to receive click events. These events occur when the user + * clicks on a displayed Notification. + * + * MDN + */ + var onclick: js.Function0[Unit] = js.native + + /** + * The onclose property of the Notification interface specifies an event + * listener to receive close events. These events occur when a Notification + * is closed. + * + * MDN + */ + @deprecated("This event handler is no longer listed in the Notifications API spec.", "forever") + var onclose: js.Function0[Unit] = js.native + + /** + * The onerror property of the Notification interface specifies an event + * listener to receive error events. These events occur when something goes + * wrong with a Notification (in many cases an error preventing the + * notification from being displayed.) + * + * MDN + */ + var onerror: js.Function0[Unit] = js.native + + /** + * The onshow property of the Notification interface specifies an event + * listener to receive show events. These events occur when a Notification + * is displayed. + * + * MDN + */ + @deprecated("This event handler is no longer listed in the Notifications API spec.", "forever") + var onshow: js.Function0[Unit] = js.native + + /** + * The permission read-only property of the Notification interface + * indicates the current permission granted by the user for the current + * origin to display web notifications. + * + * MDN + */ + var permission: String = js.native + + /** + * The renotify read-only property of the Notification interface specifies + * whether the user should be notified after a new notification replaces an + * old one, as specified in the renotify option of the Notification() + * constructor. + * + * MDN + */ + var renotify: Boolean = js.native + + /** + * The silent read-only property of the Notification interface specifies + * whether the notification should be silent, i.e. no sounds or vibrations + * should be issued, regardless of the device settings. This is specified + * in the renotify option of the Notification() constructor. + * + * MDN + */ + var silent: Boolean = js.native + + /** + * The sound read-only property of the Notification interface specifies the + * URL of an audio file to be played when the notification fires. This is + * specified in the sound option of the Notification() constructor. + * + * MDN + */ + var sound: String = js.native + + /** + * The sticky read-only property of the Notification interface specifies + * whether the notification should be 'sticky', i.e. not easily clearable + * by the user. This is specified in the sticky option of the + * Notification() constructor. + * + * MDN + */ + var sticky: Boolean = js.native + + /** + * The tag read-only property of the Notification interface signifies an + * identifying tag for the notification, as specified in the tag option + * of the Notification() constructor. + * + * The idea of notification tags is that more than one notification can + * share the same tag, linking them together. One notification can then + * be programmatically replaced with another to avoid the users' screen + * being filled up with a huge number of similar notifications. + * + * MDN + */ + var tag: String = js.native + + /** + * The title read-only property of the Notification interface indicates + * the title of the notification, as specified in the title parameter of + * the Notification() constructor. + * + * MDN + */ + var title: String = js.native + + /** + * The vibrate read-only property of the Notification interface. + * Specifies a vibration pattern for devices with vibration hardware + * to emit. + * + * MDN + */ + var vibrate: js.Array[Double] = js.native + + /** + * The requestPermission() method of the Notification interface requests + * permission from the user for the current origin to display + * notifications. + * + * MDN + */ + def requestPermission(callback:js.Function1[String, Unit]): Unit = js.native + + /** + * The close() method of the Notification interface is used to close a + * previously displayed notification. + * + * MDN + */ + def close(): Unit = js.native + } +} From 613003d8b50f80bf6f4a2571ba31deead149f4dd Mon Sep 17 00:00:00 2001 From: = Date: Tue, 1 Sep 2015 14:31:11 -0700 Subject: [PATCH 2/6] requested fixes --- example/src/main/scala/example/Example.scala | 61 +-- .../dom/experimental/Notification.scala | 437 ++++++++---------- 2 files changed, 212 insertions(+), 286 deletions(-) diff --git a/example/src/main/scala/example/Example.scala b/example/src/main/scala/example/Example.scala index 6307cd61b..0a1a7256b 100644 --- a/example/src/main/scala/example/Example.scala +++ b/example/src/main/scala/example/Example.scala @@ -18,7 +18,7 @@ object NodeAppendChild { @JSExport def main(div: html.Div) = { val child = dom.document - .createElement("div") + .createElement("div") child.textContent = "Hi from Scala-js-dom" @@ -66,9 +66,9 @@ object Canvas { @JSExport def main(c: html.Canvas) = { type Ctx2D = - dom.CanvasRenderingContext2D + dom.CanvasRenderingContext2D val ctx = c.getContext("2d") - .asInstanceOf[Ctx2D] + .asInstanceOf[Ctx2D] val w = 300 c.width = w c.height = w @@ -107,11 +107,11 @@ object EventHandler{ (e: dom.MouseEvent) => pre.textContent = s"""e.clientX ${e.clientX} - |e.clientY ${e.clientY} - |e.pageX ${e.pageX} - |e.pageY ${e.pageY} - |e.screenX ${e.screenX} - |e.screenY ${e.screenY} + |e.clientY ${e.clientY} + |e.pageX ${e.pageX} + |e.pageY ${e.pageY} + |e.screenX ${e.screenX} + |e.screenY ${e.screenY} """.stripMargin } } @@ -124,7 +124,7 @@ object XMLHttpRequest{ val xhr = new dom.XMLHttpRequest() xhr.open("GET", "http://api.openweathermap.org/" + - "data/2.5/weather?q=Singapore" + "data/2.5/weather?q=Singapore" ) xhr.onload = (e: dom.Event) => { if (xhr.status == 200) { @@ -162,47 +162,14 @@ object AjaxExtension { def main(pre: html.Pre) = { import dom.ext.Ajax import scalajs.concurrent - .JSExecutionContext - .Implicits - .runNow + .JSExecutionContext + .Implicits + .runNow val url = "http://api.openweathermap.org/" + - "data/2.5/weather?q=Singapore" + "data/2.5/weather?q=Singapore" Ajax.get(url).onSuccess{ case xhr => pre.textContent = xhr.responseText } } -} - - -@JSExport -object Notification { - @JSExport - def main(in: html.Button) = { - import org.scalajs.dom.experimental.Notification._ - - def notifyMe() { - // Let's check whether notification permissions have already been granted - if (dom.window.Notification.permission == "granted") { - // If it's okay let's create a notification - var notification = new Notification("Hi there!") - } - - // Otherwise, we need to ask the user for permission - else if (dom.window.Notification.permission != "denied") { - dom.window.Notification.requestPermission( (permission:String) => { - // If the user accepts, let's create a notification - if (permission == "granted") { - var notification = new Notification("Hi there!") - } - }) - } - // At last, if the user has denied notifications, and you - // want to be respectful there is no need to bother them any more. - } - - in.onclick = (e: dom.Event) => { - notifyMe - } - } -} +} \ No newline at end of file diff --git a/src/main/scala/org/scalajs/dom/experimental/Notification.scala b/src/main/scala/org/scalajs/dom/experimental/Notification.scala index b33205528..7b958db86 100644 --- a/src/main/scala/org/scalajs/dom/experimental/Notification.scala +++ b/src/main/scala/org/scalajs/dom/experimental/Notification.scala @@ -3,7 +3,7 @@ package org.scalajs.dom.experimental import org.scalajs.dom.raw.EventTarget import scala.language.implicitConversions import scala.scalajs.js - +import scala.scalajs.js.annotation.JSName trait NotificationOptions extends js.Object { /** @@ -20,7 +20,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var dir: String = js.native + val dir: String = js.native /** * The icon property of the Notification interface contains the @@ -28,7 +28,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var icon: String = js.native + val icon: String = js.native /** * The lang property of the Notification interface indicates the @@ -36,7 +36,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var lang: String = js.native + val lang: String = js.native /** * The noscreen property of the Notification interface specifies @@ -44,7 +44,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var noscreen: Boolean = js.native + val noscreen: Boolean = js.native /** * The renotify property of the Notification interface specifies @@ -53,7 +53,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var renotify: Boolean = js.native + val renotify: Boolean = js.native /** * The silent property of the Notification interface specifies @@ -62,7 +62,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var silent: Boolean = js.native + val silent: Boolean = js.native /** * The sound property of the Notification interface specifies the @@ -70,7 +70,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var sound: String = js.native + val sound: String = js.native /** * The sticky property of the Notification interface specifies @@ -79,7 +79,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var sticky: Boolean = js.native + val sticky: Boolean = js.native /** * The tag property of the Notification interface signifies an @@ -92,7 +92,7 @@ trait NotificationOptions extends js.Object { * * MDN */ - var tag: String = js.native + val tag: String = js.native /** * The title property of the Notification interface indicates @@ -100,9 +100,9 @@ trait NotificationOptions extends js.Object { * * MDN */ - var title: String = js.native + val title: String = js.native - var vibrate: js.Object = js.native + val vibrate: js.Array[Double] = js.native } object NotificationOptions { @@ -130,18 +130,19 @@ object NotificationOptions { * @return a new NotificationOptions */ @inline - def apply(body: js.UndefOr[String] = js.undefined, - dir: js.UndefOr[String] = js.undefined, - icon: js.UndefOr[String] = js.undefined, - lang: js.UndefOr[String] = js.undefined, - noscreen: js.UndefOr[Boolean] = js.undefined, - renotify: js.UndefOr[Boolean] = js.undefined, - silent: js.UndefOr[Boolean] = js.undefined, - sound: js.UndefOr[String] = js.undefined, - sticky: js.UndefOr[Boolean] = js.undefined, - tag: js.UndefOr[String] = js.undefined, - title: js.UndefOr[String] = js.undefined, - vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { + def apply( + body: js.UndefOr[String] = js.undefined, + dir: js.UndefOr[String] = js.undefined, + icon: js.UndefOr[String] = js.undefined, + lang: js.UndefOr[String] = js.undefined, + noscreen: js.UndefOr[Boolean] = js.undefined, + renotify: js.UndefOr[Boolean] = js.undefined, + silent: js.UndefOr[Boolean] = js.undefined, + sound: js.UndefOr[String] = js.undefined, + sticky: js.UndefOr[Boolean] = js.undefined, + tag: js.UndefOr[String] = js.undefined, + title: js.UndefOr[String] = js.undefined, + vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { val result = js.Dynamic.literal() body.foreach(result.body = _) dir.foreach(result.dir = _) @@ -164,226 +165,184 @@ object NotificationOptions { * * https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API */ -object Notification { - implicit def toNotification(w: org.scalajs.dom.Window): NotificationWindow = - w.asInstanceOf[NotificationWindow] +object Notification extends js.Object{ + /** + * The permission read-only property of the Notification interface + * indicates the current permission granted by the user for the current + * origin to display web notifications. + * + * MDN + */ + val permission: String = js.native - class NotificationWindow extends js.Any { - /** Return an interface to the Notification API */ - def Notification: Notification = js.native + /** + * The requestPermission() method of the Notification interface requests + * permission from the user for the current origin to display + * notifications. + * + * MDN + */ + def requestPermission(callback: js.Function1[String, Any]): Unit = js.native +} - } +/** + * The Notification interface allows to notify users of an incoming message + * or event + * NOTE: requires permission + * Note: This feature is available in Web Workers. + * + * @param title The text title of the notification + * @param options The options to configure this notification + * @return a new Notification + * MDN + */ +@JSName("Notification") +class Notification( title: String, + options: NotificationOptions = ???) extends EventTarget { /** - * The Notification interface allows to notify users of an incoming message - * or event - * NOTE: requires permission - * Note: This feature is available in Web Workers. + * The body read-only property of the Notification interface indicates the + * body string of the notification, as specified in the body option of the + * Notification() constructor. * * MDN */ - class Notification extends EventTarget { - /** - * Construct a new Notification - * - * @param title The text title of the notification - * @param options The options to configure this notification - * @return a new Notification - */ - def this(title:js.UndefOr[String] = js.undefined, - options:js.UndefOr[NotificationOptions] = js.undefined) = this() - - /** - * The body read-only property of the Notification interface indicates the - * body string of the notification, as specified in the body option of the - * Notification() constructor. - * - * MDN - */ - val body: String = js.native - - /** - * The data read-only property of the Notification interface returns a - * structured clone of the notification's data, as specified in the - * data option of the Notification() constructor. - * - * The notification's data can be any arbitrary data that you want - * associated with the notification. - * - * MDN - */ - var data: js.Object = js.native - - /** - * The dir read-only property of the Notification interface indicates the - * text direction of the notification, asspecified in the dir option of - * the Notification() constructor. - * - * MDN - */ - var dir: String = js.native - - /** - * The icon read-only property of the Notification interface contains the - * URL of an icon to be displayed as part of the notification, as specified - * in the icon option of the Notification() constructor. - * - * MDN - */ - var icon: String = js.native - - /** - * The lang read-only property of the Notification interface indicates the - * text direction of the notification, as specified in the lang option of - * the Notification() constructor. - * - * MDN - */ - var lang: String = js.native - - /** - * The noscreen read-only property of the Notification interface specifies - * whether the notification firing should enable the device's screen or not, - * as specified in the noscreen option of the Notification() constructor. - * - * MDN - */ - var noscreen: Boolean = js.native - - /** - * The onclick property of the Notification interface specifies an event - * listener to receive click events. These events occur when the user - * clicks on a displayed Notification. - * - * MDN - */ - var onclick: js.Function0[Unit] = js.native - - /** - * The onclose property of the Notification interface specifies an event - * listener to receive close events. These events occur when a Notification - * is closed. - * - * MDN - */ - @deprecated("This event handler is no longer listed in the Notifications API spec.", "forever") - var onclose: js.Function0[Unit] = js.native - - /** - * The onerror property of the Notification interface specifies an event - * listener to receive error events. These events occur when something goes - * wrong with a Notification (in many cases an error preventing the - * notification from being displayed.) - * - * MDN - */ - var onerror: js.Function0[Unit] = js.native - - /** - * The onshow property of the Notification interface specifies an event - * listener to receive show events. These events occur when a Notification - * is displayed. - * - * MDN - */ - @deprecated("This event handler is no longer listed in the Notifications API spec.", "forever") - var onshow: js.Function0[Unit] = js.native - - /** - * The permission read-only property of the Notification interface - * indicates the current permission granted by the user for the current - * origin to display web notifications. - * - * MDN - */ - var permission: String = js.native - - /** - * The renotify read-only property of the Notification interface specifies - * whether the user should be notified after a new notification replaces an - * old one, as specified in the renotify option of the Notification() - * constructor. - * - * MDN - */ - var renotify: Boolean = js.native - - /** - * The silent read-only property of the Notification interface specifies - * whether the notification should be silent, i.e. no sounds or vibrations - * should be issued, regardless of the device settings. This is specified - * in the renotify option of the Notification() constructor. - * - * MDN - */ - var silent: Boolean = js.native - - /** - * The sound read-only property of the Notification interface specifies the - * URL of an audio file to be played when the notification fires. This is - * specified in the sound option of the Notification() constructor. - * - * MDN - */ - var sound: String = js.native - - /** - * The sticky read-only property of the Notification interface specifies - * whether the notification should be 'sticky', i.e. not easily clearable - * by the user. This is specified in the sticky option of the - * Notification() constructor. - * - * MDN - */ - var sticky: Boolean = js.native - - /** - * The tag read-only property of the Notification interface signifies an - * identifying tag for the notification, as specified in the tag option - * of the Notification() constructor. - * - * The idea of notification tags is that more than one notification can - * share the same tag, linking them together. One notification can then - * be programmatically replaced with another to avoid the users' screen - * being filled up with a huge number of similar notifications. - * - * MDN - */ - var tag: String = js.native - - /** - * The title read-only property of the Notification interface indicates - * the title of the notification, as specified in the title parameter of - * the Notification() constructor. - * - * MDN - */ - var title: String = js.native - - /** - * The vibrate read-only property of the Notification interface. - * Specifies a vibration pattern for devices with vibration hardware - * to emit. - * - * MDN - */ - var vibrate: js.Array[Double] = js.native - - /** - * The requestPermission() method of the Notification interface requests - * permission from the user for the current origin to display - * notifications. - * - * MDN - */ - def requestPermission(callback:js.Function1[String, Unit]): Unit = js.native - - /** - * The close() method of the Notification interface is used to close a - * previously displayed notification. - * - * MDN - */ - def close(): Unit = js.native - } + val body: String = js.native + + /** + * The data read-only property of the Notification interface returns a + * structured clone of the notification's data, as specified in the + * data option of the Notification() constructor. + * + * The notification's data can be any arbitrary data that you want + * associated with the notification. + * + * MDN + */ + val data: js.Object = js.native + + /** + * The dir read-only property of the Notification interface indicates the + * text direction of the notification, asspecified in the dir option of + * the Notification() constructor. + * + * MDN + */ + val dir: String = js.native + + /** + * The icon read-only property of the Notification interface contains the + * URL of an icon to be displayed as part of the notification, as specified + * in the icon option of the Notification() constructor. + * + * MDN + */ + val icon: String = js.native + + /** + * The lang read-only property of the Notification interface indicates the + * text direction of the notification, as specified in the lang option of + * the Notification() constructor. + * + * MDN + */ + val lang: String = js.native + + /** + * The noscreen read-only property of the Notification interface specifies + * whether the notification firing should enable the device's screen or not, + * as specified in the noscreen option of the Notification() constructor. + * + * MDN + */ + val noscreen: Boolean = js.native + + /** + * The onclick property of the Notification interface specifies an event + * listener to receive click events. These events occur when the user + * clicks on a displayed Notification. + * + * MDN + */ + var onclick: js.Function0[Any] = js.native + + /** + * The onerror property of the Notification interface specifies an event + * listener to receive error events. These events occur when something goes + * wrong with a Notification (in many cases an error preventing the + * notification from being displayed.) + * + * MDN + */ + var onerror: js.Function0[Any] = js.native + + /** + * The renotify read-only property of the Notification interface specifies + * whether the user should be notified after a new notification replaces an + * old one, as specified in the renotify option of the Notification() + * constructor. + * + * MDN + */ + val renotify: Boolean = js.native + + /** + * The silent read-only property of the Notification interface specifies + * whether the notification should be silent, i.e. no sounds or vibrations + * should be issued, regardless of the device settings. This is specified + * in the renotify option of the Notification() constructor. + * + * MDN + */ + val silent: Boolean = js.native + + /** + * The sound read-only property of the Notification interface specifies the + * URL of an audio file to be played when the notification fires. This is + * specified in the sound option of the Notification() constructor. + * + * MDN + */ + val sound: String = js.native + + /** + * The sticky read-only property of the Notification interface specifies + * whether the notification should be 'sticky', i.e. not easily clearable + * by the user. This is specified in the sticky option of the + * Notification() constructor. + * + * MDN + */ + val sticky: Boolean = js.native + + /** + * The tag read-only property of the Notification interface signifies an + * identifying tag for the notification, as specified in the tag option + * of the Notification() constructor. + * + * The idea of notification tags is that more than one notification can + * share the same tag, linking them together. One notification can then + * be programmatically replaced with another to avoid the users' screen + * being filled up with a huge number of similar notifications. + * + * MDN + */ + val tag: String = js.native + + /** + * The vibrate read-only property of the Notification interface. + * Specifies a vibration pattern for devices with vibration hardware + * to emit. + * + * MDN + */ + val vibrate: js.Array[Double] = js.native + + /** + * The close() method of the Notification interface is used to close a + * previously displayed notification. + * + * MDN + */ + def close(): Unit = js.native } From e1282b8c3ade5faf890c2f24019fe51b01b7d675 Mon Sep 17 00:00:00 2001 From: coreyauger Date: Thu, 3 Sep 2015 08:53:54 -0700 Subject: [PATCH 3/6] remove title from Notification Options add onclick event to Notification Options --- .../dom/experimental/Notification.scala | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/scala/org/scalajs/dom/experimental/Notification.scala b/src/main/scala/org/scalajs/dom/experimental/Notification.scala index 7b958db86..d186011af 100644 --- a/src/main/scala/org/scalajs/dom/experimental/Notification.scala +++ b/src/main/scala/org/scalajs/dom/experimental/Notification.scala @@ -95,12 +95,23 @@ trait NotificationOptions extends js.Object { val tag: String = js.native /** - * The title property of the Notification interface indicates - * the title of the notification. + * The onclick property of the Notification interface specifies an event + * listener to receive click events. These events occur when the user + * clicks on a displayed Notification. + * + * MDN + */ + var onclick: js.Function0[Any] = js.native + + /** + * The onerror property of the Notification interface specifies an event + * listener to receive error events. These events occur when something goes + * wrong with a Notification (in many cases an error preventing the + * notification from being displayed.) * * MDN */ - val title: String = js.native + var onerror: js.Function0[Any] = js.native val vibrate: js.Array[Double] = js.native } @@ -141,7 +152,8 @@ object NotificationOptions { sound: js.UndefOr[String] = js.undefined, sticky: js.UndefOr[Boolean] = js.undefined, tag: js.UndefOr[String] = js.undefined, - title: js.UndefOr[String] = js.undefined, + onclick: js.UndefOr[js.Function0[Any]] = js.undefined, + onerror: js.UndefOr[js.Function0[Any]] = js.undefined, vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { val result = js.Dynamic.literal() body.foreach(result.body = _) @@ -154,7 +166,8 @@ object NotificationOptions { sound.foreach(result.sound = _) sticky.foreach(result.sticky = _) tag.foreach(result.tag = _) - title.foreach(result.title = _) + onclick.foreach(result.onclick = _) + onerror.foreach(result.onerror = _) vibrate.foreach(result.vibrate = _) result.asInstanceOf[NotificationOptions] } From 71760f34f0cf1bb2fc39d5328b0c1e009b45a659 Mon Sep 17 00:00:00 2001 From: coreyauger Date: Thu, 3 Sep 2015 16:37:32 -0700 Subject: [PATCH 4/6] revert changes to example --- example/src/main/scala/example/Example.scala | 57 ++++++++++---------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/example/src/main/scala/example/Example.scala b/example/src/main/scala/example/Example.scala index 0a1a7256b..e84b615ac 100644 --- a/example/src/main/scala/example/Example.scala +++ b/example/src/main/scala/example/Example.scala @@ -1,7 +1,9 @@ package example +import scala.scalajs.js.JSApp + import org.scalajs.dom -import dom.html + import scala.scalajs.js.annotation.JSExport @JSExport @@ -16,9 +18,9 @@ object Alert { @JSExport object NodeAppendChild { @JSExport - def main(div: html.Div) = { + def main(div: dom.HTMLDivElement) = { val child = dom.document - .createElement("div") + .createElement("div") child.textContent = "Hi from Scala-js-dom" @@ -30,7 +32,7 @@ object NodeAppendChild { @JSExport object ElementStyle { @JSExport - def main(div: html.Div) = { + def main(div: dom.HTMLDivElement) = { val colors = Seq( "red", "green", "blue" ) @@ -45,7 +47,8 @@ object ElementStyle { @JSExport object LocalStorage { @JSExport - def main(in: html.Input, box: html.Div) = { + def main(in: dom.HTMLInputElement, + box: dom.HTMLDivElement) = { val key = "my-key" in.value = @@ -64,11 +67,11 @@ object LocalStorage { @JSExport object Canvas { @JSExport - def main(c: html.Canvas) = { + def main(c: dom.HTMLCanvasElement) = { type Ctx2D = - dom.CanvasRenderingContext2D + dom.CanvasRenderingContext2D val ctx = c.getContext("2d") - .asInstanceOf[Ctx2D] + .asInstanceOf[Ctx2D] val w = 300 c.width = w c.height = w @@ -90,8 +93,8 @@ object Canvas { @JSExport object Base64 { @JSExport - def main(in: html.Input, - out: html.Div) = { + def main(in: dom.HTMLInputElement, + out: dom.HTMLDivElement) = { in.onkeyup = { (e: dom.Event) => out.textContent = dom.btoa(in.value) @@ -102,16 +105,16 @@ object Base64 { @JSExport object EventHandler{ @JSExport - def main(pre: html.Pre) = { + def main(pre: dom.HTMLPreElement) = { pre.onmousemove = { (e: dom.MouseEvent) => pre.textContent = s"""e.clientX ${e.clientX} - |e.clientY ${e.clientY} - |e.pageX ${e.pageX} - |e.pageY ${e.pageY} - |e.screenX ${e.screenX} - |e.screenY ${e.screenY} + |e.clientY ${e.clientY} + |e.pageX ${e.pageX} + |e.pageY ${e.pageY} + |e.screenX ${e.screenX} + |e.screenY ${e.screenY} """.stripMargin } } @@ -120,11 +123,11 @@ object EventHandler{ @JSExport object XMLHttpRequest{ @JSExport - def main(pre: html.Pre) = { + def main(pre: dom.HTMLPreElement) = { val xhr = new dom.XMLHttpRequest() xhr.open("GET", "http://api.openweathermap.org/" + - "data/2.5/weather?q=Singapore" + "data/2.5/weather?q=Singapore" ) xhr.onload = (e: dom.Event) => { if (xhr.status == 200) { @@ -139,8 +142,8 @@ object XMLHttpRequest{ @JSExport object Websocket { @JSExport - def main(in: html.Input, - pre: html.Pre) = { + def main(in: dom.HTMLInputElement, + pre: dom.HTMLPreElement) = { val echo = "ws://echo.websocket.org" val socket = new dom.WebSocket(echo) socket.onmessage = { @@ -159,17 +162,17 @@ object Websocket { @JSExport object AjaxExtension { @JSExport - def main(pre: html.Pre) = { - import dom.ext.Ajax + def main(pre: dom.HTMLPreElement) = { + import dom.extensions.Ajax import scalajs.concurrent - .JSExecutionContext - .Implicits - .runNow + .JSExecutionContext + .Implicits + .runNow val url = "http://api.openweathermap.org/" + - "data/2.5/weather?q=Singapore" + "data/2.5/weather?q=Singapore" Ajax.get(url).onSuccess{ case xhr => pre.textContent = xhr.responseText } } -} \ No newline at end of file +} From df47cbc681e7b241c8c16786e4ac680826a8a530 Mon Sep 17 00:00:00 2001 From: coreyauger Date: Thu, 3 Sep 2015 16:42:09 -0700 Subject: [PATCH 5/6] style fixes --- .../dom/experimental/Notification.scala | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/scala/org/scalajs/dom/experimental/Notification.scala b/src/main/scala/org/scalajs/dom/experimental/Notification.scala index d186011af..f23461eda 100644 --- a/src/main/scala/org/scalajs/dom/experimental/Notification.scala +++ b/src/main/scala/org/scalajs/dom/experimental/Notification.scala @@ -1,7 +1,6 @@ package org.scalajs.dom.experimental import org.scalajs.dom.raw.EventTarget -import scala.language.implicitConversions import scala.scalajs.js import scala.scalajs.js.annotation.JSName @@ -136,25 +135,24 @@ object NotificationOptions { * @param sticky Boolean indicating whether the notification should be * 'sticky', i.e. not easily clearable by the user. * @param tag A text identifying tag for the notification. - * @param title The text title of the notification * @param vibrate The vibration pattern for hardware to emit * @return a new NotificationOptions */ @inline def apply( - body: js.UndefOr[String] = js.undefined, - dir: js.UndefOr[String] = js.undefined, - icon: js.UndefOr[String] = js.undefined, - lang: js.UndefOr[String] = js.undefined, - noscreen: js.UndefOr[Boolean] = js.undefined, - renotify: js.UndefOr[Boolean] = js.undefined, - silent: js.UndefOr[Boolean] = js.undefined, - sound: js.UndefOr[String] = js.undefined, - sticky: js.UndefOr[Boolean] = js.undefined, - tag: js.UndefOr[String] = js.undefined, - onclick: js.UndefOr[js.Function0[Any]] = js.undefined, - onerror: js.UndefOr[js.Function0[Any]] = js.undefined, - vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { + body: js.UndefOr[String] = js.undefined, + dir: js.UndefOr[String] = js.undefined, + icon: js.UndefOr[String] = js.undefined, + lang: js.UndefOr[String] = js.undefined, + noscreen: js.UndefOr[Boolean] = js.undefined, + renotify: js.UndefOr[Boolean] = js.undefined, + silent: js.UndefOr[Boolean] = js.undefined, + sound: js.UndefOr[String] = js.undefined, + sticky: js.UndefOr[Boolean] = js.undefined, + tag: js.UndefOr[String] = js.undefined, + onclick: js.UndefOr[js.Function0[Any]] = js.undefined, + onerror: js.UndefOr[js.Function0[Any]] = js.undefined, + vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { val result = js.Dynamic.literal() body.foreach(result.body = _) dir.foreach(result.dir = _) @@ -178,7 +176,7 @@ object NotificationOptions { * * https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API */ -object Notification extends js.Object{ +object Notification extends js.Object { /** * The permission read-only property of the Notification interface * indicates the current permission granted by the user for the current @@ -211,7 +209,7 @@ object Notification extends js.Object{ */ @JSName("Notification") class Notification( title: String, - options: NotificationOptions = ???) extends EventTarget { + options: NotificationOptions = ???) extends EventTarget { /** * The body read-only property of the Notification interface indicates the From e478f01e5f36bc8e732c55faab5d21c602cf37d5 Mon Sep 17 00:00:00 2001 From: coreyauger Date: Tue, 8 Sep 2015 08:58:10 -0700 Subject: [PATCH 6/6] revert changes to example --- example/src/main/scala/example/Example.scala | 29 +++++++++----------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/example/src/main/scala/example/Example.scala b/example/src/main/scala/example/Example.scala index e84b615ac..fa0517b2e 100644 --- a/example/src/main/scala/example/Example.scala +++ b/example/src/main/scala/example/Example.scala @@ -1,9 +1,7 @@ package example -import scala.scalajs.js.JSApp - import org.scalajs.dom - +import dom.html import scala.scalajs.js.annotation.JSExport @JSExport @@ -18,7 +16,7 @@ object Alert { @JSExport object NodeAppendChild { @JSExport - def main(div: dom.HTMLDivElement) = { + def main(div: html.Div) = { val child = dom.document .createElement("div") @@ -32,7 +30,7 @@ object NodeAppendChild { @JSExport object ElementStyle { @JSExport - def main(div: dom.HTMLDivElement) = { + def main(div: html.Div) = { val colors = Seq( "red", "green", "blue" ) @@ -47,8 +45,7 @@ object ElementStyle { @JSExport object LocalStorage { @JSExport - def main(in: dom.HTMLInputElement, - box: dom.HTMLDivElement) = { + def main(in: html.Input, box: html.Div) = { val key = "my-key" in.value = @@ -67,7 +64,7 @@ object LocalStorage { @JSExport object Canvas { @JSExport - def main(c: dom.HTMLCanvasElement) = { + def main(c: html.Canvas) = { type Ctx2D = dom.CanvasRenderingContext2D val ctx = c.getContext("2d") @@ -93,8 +90,8 @@ object Canvas { @JSExport object Base64 { @JSExport - def main(in: dom.HTMLInputElement, - out: dom.HTMLDivElement) = { + def main(in: html.Input, + out: html.Div) = { in.onkeyup = { (e: dom.Event) => out.textContent = dom.btoa(in.value) @@ -105,7 +102,7 @@ object Base64 { @JSExport object EventHandler{ @JSExport - def main(pre: dom.HTMLPreElement) = { + def main(pre: html.Pre) = { pre.onmousemove = { (e: dom.MouseEvent) => pre.textContent = @@ -123,7 +120,7 @@ object EventHandler{ @JSExport object XMLHttpRequest{ @JSExport - def main(pre: dom.HTMLPreElement) = { + def main(pre: html.Pre) = { val xhr = new dom.XMLHttpRequest() xhr.open("GET", "http://api.openweathermap.org/" + @@ -142,8 +139,8 @@ object XMLHttpRequest{ @JSExport object Websocket { @JSExport - def main(in: dom.HTMLInputElement, - pre: dom.HTMLPreElement) = { + def main(in: html.Input, + pre: html.Pre) = { val echo = "ws://echo.websocket.org" val socket = new dom.WebSocket(echo) socket.onmessage = { @@ -162,8 +159,8 @@ object Websocket { @JSExport object AjaxExtension { @JSExport - def main(pre: dom.HTMLPreElement) = { - import dom.extensions.Ajax + def main(pre: html.Pre) = { + import dom.ext.Ajax import scalajs.concurrent .JSExecutionContext .Implicits