Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
TouchEvent support
Browse files Browse the repository at this point in the history
  • Loading branch information
jacereda committed Jun 1, 2017
1 parent 2f6a825 commit 38ee0fd
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/DOM/Event/TouchEvent.js
Original file line number Diff line number Diff line change
@@ -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;
};
74 changes: 74 additions & 0 deletions src/DOM/Event/TouchEvent.purs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 38ee0fd

Please sign in to comment.