From 38ee0fdb39d9d308b4d9c9d147fb2f82bde416ce Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Thu, 1 Jun 2017 11:52:43 +0200 Subject: [PATCH] TouchEvent support --- src/DOM/Event/TouchEvent.js | 71 +++++++++++++++++++++++++++++++++ src/DOM/Event/TouchEvent.purs | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 src/DOM/Event/TouchEvent.js create mode 100644 src/DOM/Event/TouchEvent.purs diff --git a/src/DOM/Event/TouchEvent.js b/src/DOM/Event/TouchEvent.js new file mode 100644 index 0000000..415fe49 --- /dev/null +++ b/src/DOM/Event/TouchEvent.js @@ -0,0 +1,71 @@ +"use strict"; + +exports.identifier = function (t) { + return t.identifier; +}; + +exports.screenX = function (t) { + return t.screenX; +}; + +exports.screenY = function (t) { + return t.screenY; +}; + +exports.clientX = function (t) { + return t.clientX; +}; + +exports.clientY = function (t) { + return t.clientY; +}; + +exports.pageX = function (t) { + return t.pageX; +}; + +exports.pageY = function (t) { + return t.pageY; +}; + +exports.target = function (t) { + return t.target; +}; + +exports.length = function (l) { + return l.length; +}; + +exports._item = function (i) { + return function(l) { + return l.item(i); + }; +}; + +exports.touches = function (e) { + return e.touches; +}; + +exports.targetTouches = function (e) { + return e.targetTouches; +}; + +exports.changedTouches = function (e) { + return e.changedTouches; +}; + +exports.altKey = function (e) { + return e.altKey; +}; + +exports.metaKey = function (e) { + return e.metaKey; +}; + +exports.ctrlKey = function (e) { + return e.ctrlKey; +}; + +exports.shiftKey = function (e) { + return e.shiftKey; +}; diff --git a/src/DOM/Event/TouchEvent.purs b/src/DOM/Event/TouchEvent.purs new file mode 100644 index 0000000..24fc086 --- /dev/null +++ b/src/DOM/Event/TouchEvent.purs @@ -0,0 +1,74 @@ +module DOM.Event.TouchEvent + ( module T + , Touch + , TouchList + , eventToTouchEvent + , screenX + , screenY + , clientX + , clientY + , pageX + , pageY + , target + , length + , item + , touches + , targetTouches + , changedTouches + , altKey + , metaKey + , ctrlKey + , shiftKey + ) where + +import Prelude +import DOM.Event.Types (Event, EventTarget, TouchEvent, readTouchEvent) +import DOM.Event.Types (TouchEvent, touchEventToEvent, readTouchEvent) as T +import Data.Foreign (F, toForeign) +import Data.Maybe (Maybe) +import Data.Nullable (Nullable, toMaybe) + +foreign import data Touch :: Type + +foreign import identifier :: Touch -> Int + +foreign import screenX :: Touch -> Int + +foreign import screenY :: Touch -> Int + +foreign import clientX :: Touch -> Int + +foreign import clientY :: Touch -> Int + +foreign import pageX :: Touch -> Int + +foreign import pageY :: Touch -> Int + +foreign import target :: Touch -> EventTarget + + +foreign import data TouchList :: Type + +foreign import length :: TouchList -> Int + +foreign import _item :: Int -> TouchList -> Nullable Touch + +item :: Int -> TouchList -> Maybe Touch +item i = toMaybe <<< _item i + +eventToTouchEvent :: Event -> F TouchEvent +eventToTouchEvent = readTouchEvent <<< toForeign + +foreign import touches :: TouchEvent -> TouchList + +foreign import targetTouches :: TouchEvent -> TouchList + +foreign import changedTouches :: TouchEvent -> TouchList + +foreign import altKey :: TouchEvent -> Boolean + +foreign import metaKey :: TouchEvent -> Boolean + +foreign import ctrlKey :: TouchEvent -> Boolean + +foreign import shiftKey :: TouchEvent -> Boolean