summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/bower_components/jquery.event.drag-new/event.drag/test/touch.js
blob: 78279081999f01311362697605920ed7492eb5a5 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
;(function(){
	
	module("Touch Interaction");

	if ( !document.createEvent ){
		test("Touch Simulation Not Supported",function(){
			ok( true, 'This browser does not support "document.createEvent" and cannot simulate touch events.');	
		});
		return;
	}

	// a simple re-usable test harness object
	var obj = {
		init: function( opts ){
			obj.$div = 	$('<div />')
				.css({
					position: 'absolute',
					top: 0,
					left: 0,
					height: 100,
					width: 100
				})
				.append('<div class="child" />')
				.appendTo( document.body )
				.bind("draginit dragstart drag dragend click", opts || {}, function( event ){
					obj[ event.type ] += 1;					
				});
			$.extend( obj, { draginit:0, dragstart:0, drag:0, dragend:0, click:0 });
		},
		done: function(){
			obj.$div.remove();
			start();
		}
	};

	asyncTest("default",function(){
		expect( 5 );
		// prep DEFAULT interaction
		obj.init();
		// simulate DEFAULT interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results	
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 0, "click");
		// clean-up interaction
		obj.done();
	});

	asyncTest('"not" option',function(){
		expect( 10 );
		// prep interaction
		obj.init({ not:'.child' });
		// simulate NOT interaction
		obj.$div.children()
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results		
		equals( obj.draginit, 0, "draginit");
		equals( obj.dragstart, 0, "dragstart");
		equals( obj.drag, 0, "drag");
		equals( obj.dragend, 0, "dragend");
		equals( obj.click, 1, "click");
		// simlate NON NOT interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 1, "click");
		// clean-up interaction
		obj.done();
	});

	asyncTest('"handle" option',function(){
		expect( 10 );
		// prep interaction
		obj.init({ handle:'.child' });
		// simulate HANDLE interaction
		obj.$div.children()
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 0, "click");	
		// simulate NON HANDLE interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 1, "click");
		// clean-up interaction
		obj.done();
	});
	
	asyncTest('"which" option',function(){
		expect( 11 );
		// prep interaction
		obj.init({ which:0 });
		// simulate WHICH interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50, button:5 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 0, "click");	
		ok( true, '"which" not supported with touch events...');
		// simulate NON WHICH interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results
		equals( obj.draginit, 2, "draginit");
		equals( obj.dragstart, 2, "dragstart");
		equals( obj.drag, 2, "drag");
		equals( obj.dragend, 2, "dragend");
		equals( obj.click, 0, "click");
		// clean-up interaction
		obj.done();
	});	

	asyncTest('"distance" option',function(){
		expect( 10 );
		// prep interaction
		obj.init({ distance:5 });
		// simulate NON DISTANCE interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 0, "dragstart");
		equals( obj.drag, 0, "drag");
		equals( obj.dragend, 0, "dragend");
		equals( obj.click, 1, "click");	
		// simulate DISTANCE interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:53, pageY:54 })
			.fire("touchend",{ pageX:53, pageY:54 })
			.fire("click");
		// inspect results		
		equals( obj.draginit, 2, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 1, "click");
		// clean-up interaction
		obj.done();
	});


	asyncTest('"click" option',function(){
		expect( 5 );
		// prep interaction
		obj.init({ click:true });
		// simulate CLICK interaction
		obj.$div
			.fire("touchstart",{ pageX:50, pageY:50 })
			.fire("touchmove",{ pageX:51, pageY:51 })
			.fire("touchend",{ pageX:51, pageY:51 })
			.fire("click");
		// inspect results	
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.click, 1, "click");	
		// clean-up interaction
		obj.done();
	});

})();