Skip to content

Commit 164e13e

Browse files
committed
Add touch events
1 parent f0a5a64 commit 164e13e

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

src/main/scala/org/scalajs/dom/ext/Extensions.scala

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.scalajs.dom.ext
22

3-
import org.scalajs.dom.html
3+
import scala.language.implicitConversions
4+
import scala.concurrent.{Promise, Future}
45

56
import scala.scalajs.js
7+
68
import org.scalajs.dom
9+
import org.scalajs.dom.{html, raw}
710

811
/**
912
* Used to extend out javascript *Collections to make them usable as normal
@@ -151,7 +154,7 @@ object KeyCode {
151154
val z = 90
152155
}
153156

154-
import scala.concurrent.{Promise, Future}
157+
155158
/**
156159
* Thrown when `Ajax.get` or `Ajax.post` receives a non-20X response code.
157160
* Contains the XMLHttpRequest that resulted in that response
@@ -245,3 +248,58 @@ sealed class Storage(domStorage: dom.Storage) {
245248
object SessionStorage extends Storage(dom.sessionStorage)
246249

247250
object LocalStorage extends Storage(dom.localStorage)
251+
252+
/**
253+
* W3C recommendation for touch events
254+
*
255+
* @see http://www.w3.org/TR/touch-events/
256+
*/
257+
trait TouchEvents extends js.Object {
258+
/**
259+
* The touchstart event is fired when a touch point is placed on the touch
260+
* surface.
261+
*
262+
* MDN
263+
*/
264+
var ontouchstart: js.Function1[raw.TouchEvent, _] = js.native
265+
266+
/**
267+
* The touchmove event is fired when a touch point is moved along the touch
268+
* surface.
269+
*
270+
* MDN
271+
*/
272+
var ontouchmove: js.Function1[raw.TouchEvent, _] = js.native
273+
274+
/**
275+
* The touchend event is fired when a touch point is removed from the touch
276+
* surface.
277+
*
278+
* MDN
279+
*/
280+
var ontouchend: js.Function1[raw.TouchEvent, _] = js.native
281+
282+
/**
283+
* The touchcancel event is fired when a touch point has been disrupted in an
284+
* implementation-specific manner (too many touch points for example).
285+
*
286+
* MDN
287+
*/
288+
var ontouchcancel: js.Function1[raw.TouchEvent, _] = js.native
289+
}
290+
291+
/**
292+
* Implicits to add touch event handlers to [[raw.HTMLDocument]] and
293+
* [[raw.Window]].
294+
*
295+
* @note Touch events may not be available on all modern browsers. See
296+
* http://www.quirksmode.org/mobile/tableTouch.html#t00 for a compatibility
297+
* table.
298+
*/
299+
object TouchEvents {
300+
implicit def HTMLDocumentToTouchEvents(html: raw.HTMLDocument): TouchEvents =
301+
html.asInstanceOf[TouchEvents]
302+
303+
implicit def WindowToTouchEvents(window: raw.Window): TouchEvents =
304+
window.asInstanceOf[TouchEvents]
305+
}

0 commit comments

Comments
 (0)