• Stars
    star
    453
  • Rank 96,197 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 12 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[deprecated] Pointer.js consolidates pointer-like input models across browsers and devices.

Important note (August 7, 2013)

This project is deprecated.

For your future pointer event needs, please use this PointerEvents polyfill, part of the Polymer Project.

An early pointer events polyfill

For background and motivation, see this blog post: http://smus.com/mouse-touch-pointer/.

Implementation

This is a library that enables MSPointer*-style pointer events in all browsers.

Pointer events

The whole point of pointer.js is to use pointer* events instead of mouse* and touch*. You can do this by subscribing to these events in the same way as you would regular events:

var el = document.querySelector(mySelector);
el.addEventListener('pointerdown', function(e) {
  // ...
});

Approach: override addEventListener to intercept pointer* events. (Theoretical alternative: have an explicit el.emitPointers call.)

As soon as you start listening for pointer* events, both mouse and touch events are hijacked, and do not fire.

The event payload for a pointer event includes the following important features:

  • {String} pointerType - the kind of pointer it is (touch, mouse, pen)
  • {Object} originalEvent - the original event payload from the underlying event.
  • {Function} getPointerList() - gets the list of active pointers (ie mouse pressed, fingers on the screen).

The bottom line is that you code your input to a single spec: pointer events from pointer.js. The library abstracts all of the input differences for you under the consolidated model.

Pointer API

Events: pointerdown, pointermove, pointerup

Event payload class: originalEvent, pointerType, getPointerList()

Pointer class: clientX, clientY, screenX, screenY, pageX, pageY, tiltX, tiltY, pressure, hwTimestamp, pointerType, identifier

Gesture events

Now that we have a solid touch/mouse/stylus abstraction, we can build higher level gestures on top. Some interesting events to support are tap, double tap, longpress, swipe, pinch-zoom, and rotate.

Gesture API

Emit new gesture* events. For example, gesturedoubletap, gesturelongpress, gesturescale, etc. This is incompatible with Safari's gesturestart events, but in the future can also be consolidated under one umbrella.

This is done with the same addEventListener hack as is used for pointer events. Each of these gesture* events has a recognizer associated with it. If, for example, gesturescale is specified, the pointer-event-based recognizer gets pulled into the event loop.

Each gesture has a custom event associated with it. This function takes an HTMLElement as its only argument. The following gestures are supported:

gesture           gesture event
===================================
Double Tap        gesturedoubletap
Long Press        gesturelongpress
Scale             gesturescale

This is a nice place to contribute if you're so inclined. Gesture recognizers can easily be plugged into this architecture. They are completely standalone and can be registered easily. For an example, take a look at the doubletap handler.

The scale gesture implements a pinch-zoom and provides the scaling factor as part of the event payload through evt.scale.

Demos

Open questions

  • Will the way addEventListener is overridden cause problems in the future?

  • Is the overhead of firing a custom event vs. calling a function too high? See this test on jsperf.com

  • Does the gesture approach make sense on iOS, which provides built-in gesture support? How to consolidate?

More Repositories

1

webvr-boilerplate

A starting point for web-based VR experiences that work on all VR headsets.
JavaScript
1,798
star
2

sonicnet.js

Ultrasonic Networking with the Web Audio API
JavaScript
859
star
3

device.js

Semantic client-side device detection with Media Queries
JavaScript
765
star
4

osmus

Multiplayer HTML5 Osmos
JavaScript
401
star
5

keysocket

JavaScript
381
star
6

srcset-polyfill

[Warning: not for production code]
JavaScript
351
star
7

MagicTouch

Spec-compatible touch events based on npTuioClient callbacks
JavaScript
347
star
8

spectrogram

Web Audio Spectrogram
HTML
288
star
9

oauth2-extensions

[Deprecated] An OAuth 2.0 Library for Chrome Extensions (please use chrome.identity)
JavaScript
220
star
10

markdown-preview

Enables Chrome to render markdown files as HTML
JavaScript
218
star
11

webaudioapi.com

Basic Web Audio API samples
HTML
146
star
12

ray-input

JavaScript
139
star
13

game-asset-loader

HTML5 Filesystem, offline capable loader for web game assets.
JavaScript
109
star
14

DevTools-Lab

JavaScript
92
star
15

lightning

static site generator
Python
91
star
16

CrowdForge

Django framework for crowdsourcing complex tasks using MTurk
Python
64
star
17

screencapture-www

Adds imgur upload functionality to OS X's builtin Command - Shift - 4 screencapture tool
Shell
51
star
18

chrome-screencast

Video screencasts in Chrome
JavaScript
33
star
19

copresence-vr

WebVR copresence using WebRTC.
JavaScript
32
star
20

physical-units

A modest proposal for using real physical units for web-based UIs.
JavaScript
28
star
21

webrtc-samples

Hacking around with WebRTC
JavaScript
27
star
22

moving-music

Musical tracks on tracks
JavaScript
25
star
23

jsperfview

Charting for JSPerf
JavaScript
24
star
24

Question-Monitor-for-Stack-Exchange

Chrome extension for monitoring Stack Exchange sites such as Stack Overflow, etc.
CSS
23
star
25

Music-Visualizer-Chrome-Extension

JavaScript
21
star
26

music-of-touch

JavaScript
21
star
27

smus.com-2012

Old blog. New link below:
JavaScript
20
star
28

jshint-extension

JavaScript
20
star
29

Chrome-Media-Keys

Chrome extension to bind your keyboard's media keys to your favorite web-based music player.
JavaScript
17
star
30

mobile-web-samples

a dumping ground for random mobile web samples
JavaScript
15
star
31

sensor-fusion

Implementing sensor fusion used in WebVR polyfill
JavaScript
13
star
32

gestural-music-direction

JavaScript
12
star
33

spatial-audio

JavaScript
11
star
34

touch-laptop-experiments

Touch screen laptop experiments: responsive input and simultaneous interactions using both mouse/trackpad and touchscreen.
JavaScript
11
star
35

html5slidedown

Write HTML5 slides in markdown
JavaScript
8
star
36

jQuery-Mobile-Hacker-News

A Hacker News client written in jQuery Mobile
Java
7
star
37

smusique-extension

Chrome extension to do client side scraping from ultimate-guitar and imslp
JavaScript
7
star
38

asimov

Asimov's Chronology of Science and Discovery
JavaScript
7
star
39

web-component-samples

Playground for web components.
JavaScript
6
star
40

image-zoom

Lightroom-like image comparison view for seeing differences between compression quality levels, compression formats (JPEG, WebP) and sizes (1x, 2x).
JavaScript
6
star
41

time-sync

Playing with network and audio time synchronization
JavaScript
6
star
42

infinite-scroll

A simple infinite scrolling solution.
JavaScript
6
star
43

android-nxt

Sample code for integrating Android and Mindstorms NXT
Java
5
star
44

Chronos

Greek god of Chrome Time Tracking
JavaScript
5
star
45

smus.com

Content for smus.com
JavaScript
5
star
46

That-Trip

KML Tours in Google Earth
JavaScript
5
star
47

webplatform-tools

Tools for automating tasks on the web platform docs project.
Python
5
star
48

Radio-61

Chrome extension for thesixtyone
JavaScript
5
star
49

Running-Gestures

Prototype code for detecting pace of a runner, and then detecting when they skip
Python
4
star
50

smustalks

Repository of Talks
JavaScript
4
star
51

School-Connect

A sample jQuery Mobile application
JavaScript
4
star
52

Web-Storage-Benchmark

How much storage space is available to you if you use localStorage? WebSQL? IndexedDB? etc
JavaScript
4
star
53

humanbody.js

Java
3
star
54

smusique-uploader

A proxy server that converts and uploads PDFs to smusique.com
JavaScript
3
star
55

inequality-simulator

Simulating wealth inequality
JavaScript
3
star
56

ontonight

Weekend project: preview live music nearby to decide if you want to see the show or not.
TypeScript
3
star
57

llm4cld

JavaScript
2
star
58

asimov-gpt

Python
2
star
59

sensor-streamer

Streaming sensor data from one webpage to another using firebase.
JavaScript
2
star
60

smus.com-template

theme for the new smus.com
JavaScript
2
star
61

Chrome-Brazil

JavaScript
2
star
62

exupery

A voice-powered sketching robot. "Draw me a sheep!"
TypeScript
2
star
63

central-asia-maps

A better look at Central Asia in the middle ages. Inspired by "Thirteenth Tribe" and "Lost Enlightenment"
JavaScript
1
star
64

death-metal-english

Stay tuned
TypeScript
1
star
65

media-control-prototype

How media controls might work in Chrome
JavaScript
1
star
66

istherewind.com

App Engine application for checking the wind.
Python
1
star
67

automerge-playground

JavaScript
1
star
68

cld-tools

JavaScript
1
star