nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery.event.drag-new / event.drag / test / touch.js
1 ;(function(){
2         
3         module("Touch Interaction");
4
5         if ( !document.createEvent ){
6                 test("Touch Simulation Not Supported",function(){
7                         ok( true, 'This browser does not support "document.createEvent" and cannot simulate touch events.');    
8                 });
9                 return;
10         }
11
12         // a simple re-usable test harness object
13         var obj = {
14                 init: function( opts ){
15                         obj.$div =      $('<div />')
16                                 .css({
17                                         position: 'absolute',
18                                         top: 0,
19                                         left: 0,
20                                         height: 100,
21                                         width: 100
22                                 })
23                                 .append('<div class="child" />')
24                                 .appendTo( document.body )
25                                 .bind("draginit dragstart drag dragend click", opts || {}, function( event ){
26                                         obj[ event.type ] += 1;                                 
27                                 });
28                         $.extend( obj, { draginit:0, dragstart:0, drag:0, dragend:0, click:0 });
29                 },
30                 done: function(){
31                         obj.$div.remove();
32                         start();
33                 }
34         };
35
36         asyncTest("default",function(){
37                 expect( 5 );
38                 // prep DEFAULT interaction
39                 obj.init();
40                 // simulate DEFAULT interaction
41                 obj.$div
42                         .fire("touchstart",{ pageX:50, pageY:50 })
43                         .fire("touchmove",{ pageX:51, pageY:51 })
44                         .fire("touchend",{ pageX:51, pageY:51 })
45                         .fire("click");
46                 // inspect results      
47                 equals( obj.draginit, 1, "draginit");
48                 equals( obj.dragstart, 1, "dragstart");
49                 equals( obj.drag, 1, "drag");
50                 equals( obj.dragend, 1, "dragend");
51                 equals( obj.click, 0, "click");
52                 // clean-up interaction
53                 obj.done();
54         });
55
56         asyncTest('"not" option',function(){
57                 expect( 10 );
58                 // prep interaction
59                 obj.init({ not:'.child' });
60                 // simulate NOT interaction
61                 obj.$div.children()
62                         .fire("touchstart",{ pageX:50, pageY:50 })
63                         .fire("touchmove",{ pageX:51, pageY:51 })
64                         .fire("touchend",{ pageX:51, pageY:51 })
65                         .fire("click");
66                 // inspect results              
67                 equals( obj.draginit, 0, "draginit");
68                 equals( obj.dragstart, 0, "dragstart");
69                 equals( obj.drag, 0, "drag");
70                 equals( obj.dragend, 0, "dragend");
71                 equals( obj.click, 1, "click");
72                 // simlate NON NOT interaction
73                 obj.$div
74                         .fire("touchstart",{ pageX:50, pageY:50 })
75                         .fire("touchmove",{ pageX:51, pageY:51 })
76                         .fire("touchend",{ pageX:51, pageY:51 })
77                         .fire("click");
78                 // inspect results              
79                 equals( obj.draginit, 1, "draginit");
80                 equals( obj.dragstart, 1, "dragstart");
81                 equals( obj.drag, 1, "drag");
82                 equals( obj.dragend, 1, "dragend");
83                 equals( obj.click, 1, "click");
84                 // clean-up interaction
85                 obj.done();
86         });
87
88         asyncTest('"handle" option',function(){
89                 expect( 10 );
90                 // prep interaction
91                 obj.init({ handle:'.child' });
92                 // simulate HANDLE interaction
93                 obj.$div.children()
94                         .fire("touchstart",{ pageX:50, pageY:50 })
95                         .fire("touchmove",{ pageX:51, pageY:51 })
96                         .fire("touchend",{ pageX:51, pageY:51 })
97                         .fire("click");
98                 // inspect results              
99                 equals( obj.draginit, 1, "draginit");
100                 equals( obj.dragstart, 1, "dragstart");
101                 equals( obj.drag, 1, "drag");
102                 equals( obj.dragend, 1, "dragend");
103                 equals( obj.click, 0, "click"); 
104                 // simulate NON HANDLE interaction
105                 obj.$div
106                         .fire("touchstart",{ pageX:50, pageY:50 })
107                         .fire("touchmove",{ pageX:51, pageY:51 })
108                         .fire("touchend",{ pageX:51, pageY:51 })
109                         .fire("click");
110                 // inspect results              
111                 equals( obj.draginit, 1, "draginit");
112                 equals( obj.dragstart, 1, "dragstart");
113                 equals( obj.drag, 1, "drag");
114                 equals( obj.dragend, 1, "dragend");
115                 equals( obj.click, 1, "click");
116                 // clean-up interaction
117                 obj.done();
118         });
119         
120         asyncTest('"which" option',function(){
121                 expect( 11 );
122                 // prep interaction
123                 obj.init({ which:0 });
124                 // simulate WHICH interaction
125                 obj.$div
126                         .fire("touchstart",{ pageX:50, pageY:50, button:5 })
127                         .fire("touchmove",{ pageX:51, pageY:51 })
128                         .fire("touchend",{ pageX:51, pageY:51 })
129                         .fire("click");
130                 // inspect results
131                 equals( obj.draginit, 1, "draginit");
132                 equals( obj.dragstart, 1, "dragstart");
133                 equals( obj.drag, 1, "drag");
134                 equals( obj.dragend, 1, "dragend");
135                 equals( obj.click, 0, "click"); 
136                 ok( true, '"which" not supported with touch events...');
137                 // simulate NON WHICH interaction
138                 obj.$div
139                         .fire("touchstart",{ pageX:50, pageY:50 })
140                         .fire("touchmove",{ pageX:51, pageY:51 })
141                         .fire("touchend",{ pageX:51, pageY:51 })
142                         .fire("click");
143                 // inspect results
144                 equals( obj.draginit, 2, "draginit");
145                 equals( obj.dragstart, 2, "dragstart");
146                 equals( obj.drag, 2, "drag");
147                 equals( obj.dragend, 2, "dragend");
148                 equals( obj.click, 0, "click");
149                 // clean-up interaction
150                 obj.done();
151         });     
152
153         asyncTest('"distance" option',function(){
154                 expect( 10 );
155                 // prep interaction
156                 obj.init({ distance:5 });
157                 // simulate NON DISTANCE interaction
158                 obj.$div
159                         .fire("touchstart",{ pageX:50, pageY:50 })
160                         .fire("touchmove",{ pageX:51, pageY:51 })
161                         .fire("touchend",{ pageX:51, pageY:51 })
162                         .fire("click");
163                 // inspect results              
164                 equals( obj.draginit, 1, "draginit");
165                 equals( obj.dragstart, 0, "dragstart");
166                 equals( obj.drag, 0, "drag");
167                 equals( obj.dragend, 0, "dragend");
168                 equals( obj.click, 1, "click"); 
169                 // simulate DISTANCE interaction
170                 obj.$div
171                         .fire("touchstart",{ pageX:50, pageY:50 })
172                         .fire("touchmove",{ pageX:53, pageY:54 })
173                         .fire("touchend",{ pageX:53, pageY:54 })
174                         .fire("click");
175                 // inspect results              
176                 equals( obj.draginit, 2, "draginit");
177                 equals( obj.dragstart, 1, "dragstart");
178                 equals( obj.drag, 1, "drag");
179                 equals( obj.dragend, 1, "dragend");
180                 equals( obj.click, 1, "click");
181                 // clean-up interaction
182                 obj.done();
183         });
184
185
186         asyncTest('"click" option',function(){
187                 expect( 5 );
188                 // prep interaction
189                 obj.init({ click:true });
190                 // simulate CLICK interaction
191                 obj.$div
192                         .fire("touchstart",{ pageX:50, pageY:50 })
193                         .fire("touchmove",{ pageX:51, pageY:51 })
194                         .fire("touchend",{ pageX:51, pageY:51 })
195                         .fire("click");
196                 // inspect results      
197                 equals( obj.draginit, 1, "draginit");
198                 equals( obj.dragstart, 1, "dragstart");
199                 equals( obj.drag, 1, "drag");
200                 equals( obj.dragend, 1, "dragend");
201                 equals( obj.click, 1, "click"); 
202                 // clean-up interaction
203                 obj.done();
204         });
205
206 })();