forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhammerjs-commonjs-tests.ts
117 lines (82 loc) · 3.01 KB
/
hammerjs-commonjs-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Tests based on examples at http://hammerjs.github.io/examples/
/// <reference path="hammerjs.d.ts" />
import Hammer = require("hammerjs");
(() =>
{
var myElement = document.getElementById( 'myElement' );
// create a simple instance
// by default, it only adds horizontal recognizers
var mc = new Hammer( myElement );
// listen to events...
mc.on( "panleft panright tap press", function ( ev )
{
myElement.textContent = ev.type + " gesture detected.";
} );
})();
(() =>
{
var myElement = document.getElementById( 'myElement' );
// create a simple instance
// by default, it only adds horizontal recognizers
var mc = new Hammer( myElement );
// let the pan gesture support all directions.
// this will block the vertical scrolling on a touch-device while on the element
mc.get( 'pan' ).set( {direction: Hammer.DIRECTION_ALL} );
// listen to events...
mc.on( "panleft panright panup pandown tap press", function ( ev:HammerInput )
{
myElement.textContent = ev.type + " gesture detected.";
} );
})();
(() =>
{
var myElement = document.getElementById( 'myElement' );
var mc = new Hammer.Manager( myElement );
// create a pinch and rotate recognizer
// these require 2 pointers
var pinch = new Hammer.Pinch();
var rotate = new Hammer.Rotate();
// we want to detect both the same time
pinch.recognizeWith( rotate );
// add to the Manager
mc.add( [pinch, rotate] );
mc.on( "pinch rotate", function ( ev:HammerInput )
{
myElement.textContent += ev.type + " ";
} );
})();
(() =>
{
var myElement = document.getElementById( 'myElement' );
// We create a manager object, which is the same as Hammer(), but without the presetted recognizers.
var mc = new Hammer.Manager( myElement );
// Default, tap recognizer
mc.add( new Hammer.Tap() );
// Tap recognizer with minimal 4 taps
mc.add( new Hammer.Tap( {event: 'quadrupletap', taps: 4} ) );
// we want to recognize this simulatenous, so a quadrupletap will be detected even while a tap has been recognized.
// the tap event will be emitted on every tap
mc.get( 'quadrupletap' ).recognizeWith( 'tap' );
mc.on( "tap quadrupletap", function ( ev )
{
myElement.textContent += ev.type + " ";
} );
})();
(() =>
{
var myElement = document.getElementById( 'myElement' );
// We create a manager object, which is the same as Hammer(), but without the presetted recognizers.
var mc = new Hammer.Manager( myElement );
// Tap recognizer with minimal 2 taps
mc.add( new Hammer.Tap( {event: 'doubletap', taps: 2} ) );
// Single tap recognizer
mc.add( new Hammer.Tap( {event: 'singletap'} ) );
// we want to recognize this simulatenous, so a quadrupletap will be detected even while a tap has been recognized.
mc.get( 'doubletap' ).recognizeWith( 'singletap' );
// we only want to trigger a tap, when we don't have detected a doubletap
mc.get( 'singletap' ).requireFailure( 'doubletap' );
mc.on( "singletap doubletap", function ( ev )
{
myElement.textContent += ev.type + " ";
} );
})();