annotate web/static/jquery.mobile.custom.js @ 500:136b1343e640

merge
author Matt Johnston <matt@ucc.asn.au>
date Mon, 24 Mar 2014 20:49:00 +0800
parents 931408ce71d9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * jQuery Mobile v1.4.0
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 * http://jquerymobile.com
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 *
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * Copyright 2010, 2013 jQuery Foundation, Inc. and other contributors
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 * Released under the MIT license.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * http://jquery.org/license
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 *
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 */
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 (function ( root, doc, factory ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 if ( typeof define === "function" && define.amd ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 // AMD. Register as an anonymous module.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 define( [ "jquery" ], function ( $ ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 factory( $, root, doc );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 return $.mobile;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 } else {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 // Browser globals
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 factory( root.jQuery, root, doc );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 }( this, document, function ( jQuery, window, document, undefined ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 // This plugin is an experiment for abstracting away the touch and mouse
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 // events so that developers don't have to worry about which method of input
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 // the device their document is loaded on supports.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 //
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 // The idea here is to allow the developer to register listeners for the
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 // basic mouse events, such as mousedown, mousemove, mouseup, and click,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 // and the plugin will take care of registering the correct listeners
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 // behind the scenes to invoke the listener at the fastest possible time
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 // for that device, while still retaining the order of event firing in
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 // the traditional mouse environment, should multiple handlers be registered
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 // on the same element for different events.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 //
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 // The current version exposes the following virtual events to jQuery bind methods:
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 // "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel"
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 (function( $, window, document, undefined ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 var dataPropertyName = "virtualMouseBindings",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 touchTargetPropertyName = "virtualTouchID",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 virtualEventNames = "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split( " " ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 touchEventProps = "clientX clientY pageX pageY screenX screenY".split( " " ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 mouseHookProps = $.event.mouseHooks ? $.event.mouseHooks.props : [],
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 mouseEventProps = $.event.props.concat( mouseHookProps ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 activeDocHandlers = {},
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 resetTimerID = 0,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 startX = 0,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 startY = 0,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 didScroll = false,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 clickBlockList = [],
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 blockMouseTriggers = false,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 blockTouchTriggers = false,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 eventCaptureSupported = "addEventListener" in document,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 $document = $( document ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 nextTouchID = 1,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 lastTouchID = 0, threshold,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 i;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 $.vmouse = {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 moveDistanceThreshold: 10,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 clickDistanceThreshold: 10,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 resetTimerDuration: 1500
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 function getNativeEvent( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 while ( event && typeof event.originalEvent !== "undefined" ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 event = event.originalEvent;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 return event;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 function createVirtualEvent( event, eventType ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 var t = event.type,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 oe, props, ne, prop, ct, touch, i, j, len;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 event = $.Event( event );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 event.type = eventType;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 oe = event.originalEvent;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 props = $.event.props;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 // addresses separation of $.event.props in to $.event.mouseHook.props and Issue 3280
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 // https://github.com/jquery/jquery-mobile/issues/3280
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 if ( t.search( /^(mouse|click)/ ) > -1 ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 props = mouseEventProps;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 // copy original event properties over to the new event
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 // this would happen if we could call $.event.fix instead of $.Event
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 // but we don't have a way to force an event to be fixed multiple times
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 if ( oe ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 for ( i = props.length, prop; i; ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 prop = props[ --i ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 event[ prop ] = oe[ prop ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 // make sure that if the mouse and click virtual events are generated
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 // without a .which one is defined
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 if ( t.search(/mouse(down|up)|click/) > -1 && !event.which ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 event.which = 1;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 if ( t.search(/^touch/) !== -1 ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 ne = getNativeEvent( oe );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 t = ne.touches;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 ct = ne.changedTouches;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 touch = ( t && t.length ) ? t[0] : ( ( ct && ct.length ) ? ct[ 0 ] : undefined );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 if ( touch ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 for ( j = 0, len = touchEventProps.length; j < len; j++) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 prop = touchEventProps[ j ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 event[ prop ] = touch[ prop ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 return event;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 function getVirtualBindingFlags( element ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 var flags = {},
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 b, k;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 while ( element ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 b = $.data( element, dataPropertyName );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 for ( k in b ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 if ( b[ k ] ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 flags[ k ] = flags.hasVirtualBinding = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 element = element.parentNode;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 return flags;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 function getClosestElementWithVirtualBinding( element, eventType ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 var b;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 while ( element ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 b = $.data( element, dataPropertyName );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 if ( b && ( !eventType || b[ eventType ] ) ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 return element;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 element = element.parentNode;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 return null;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 function enableTouchBindings() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 blockTouchTriggers = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 function disableTouchBindings() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 blockTouchTriggers = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 function enableMouseBindings() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 lastTouchID = 0;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 clickBlockList.length = 0;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 blockMouseTriggers = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 // When mouse bindings are enabled, our
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 // touch bindings are disabled.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 disableTouchBindings();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 function disableMouseBindings() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 // When mouse bindings are disabled, our
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 // touch bindings are enabled.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 enableTouchBindings();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 function startResetTimer() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 clearResetTimer();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 resetTimerID = setTimeout( function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 resetTimerID = 0;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 enableMouseBindings();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 }, $.vmouse.resetTimerDuration );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 function clearResetTimer() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 if ( resetTimerID ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 clearTimeout( resetTimerID );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 resetTimerID = 0;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 function triggerVirtualEvent( eventType, event, flags ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 var ve;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199 if ( ( flags && flags[ eventType ] ) ||
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 ( !flags && getClosestElementWithVirtualBinding( event.target, eventType ) ) ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 ve = createVirtualEvent( event, eventType );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 $( event.target).trigger( ve );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207 return ve;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 function mouseEventCallback( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 var touchID = $.data( event.target, touchTargetPropertyName ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 ve;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 if ( !blockMouseTriggers && ( !lastTouchID || lastTouchID !== touchID ) ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 ve = triggerVirtualEvent( "v" + event.type, event );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216 if ( ve ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 if ( ve.isDefaultPrevented() ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218 event.preventDefault();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 if ( ve.isPropagationStopped() ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 event.stopPropagation();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 if ( ve.isImmediatePropagationStopped() ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224 event.stopImmediatePropagation();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230 function handleTouchStart( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232 var touches = getNativeEvent( event ).touches,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 target, flags, t;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 if ( touches && touches.length === 1 ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 target = event.target;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 flags = getVirtualBindingFlags( target );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 if ( flags.hasVirtualBinding ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242 lastTouchID = nextTouchID++;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 $.data( target, touchTargetPropertyName, lastTouchID );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245 clearResetTimer();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 disableMouseBindings();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 didScroll = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 t = getNativeEvent( event ).touches[ 0 ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 startX = t.pageX;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 startY = t.pageY;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 triggerVirtualEvent( "vmouseover", event, flags );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 triggerVirtualEvent( "vmousedown", event, flags );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 function handleScroll( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261 if ( blockTouchTriggers ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262 return;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
265 if ( !didScroll ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266 triggerVirtualEvent( "vmousecancel", event, getVirtualBindingFlags( event.target ) );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 didScroll = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270 startResetTimer();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 function handleTouchMove( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274 if ( blockTouchTriggers ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 return;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 var t = getNativeEvent( event ).touches[ 0 ],
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279 didCancel = didScroll,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 moveThreshold = $.vmouse.moveDistanceThreshold,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 flags = getVirtualBindingFlags( event.target );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 didScroll = didScroll ||
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 ( Math.abs( t.pageX - startX ) > moveThreshold ||
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 Math.abs( t.pageY - startY ) > moveThreshold );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 if ( didScroll && !didCancel ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 triggerVirtualEvent( "vmousecancel", event, flags );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 triggerVirtualEvent( "vmousemove", event, flags );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292 startResetTimer();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 function handleTouchEnd( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 if ( blockTouchTriggers ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 return;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300 disableTouchBindings();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 var flags = getVirtualBindingFlags( event.target ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303 ve, t;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 triggerVirtualEvent( "vmouseup", event, flags );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 if ( !didScroll ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 ve = triggerVirtualEvent( "vclick", event, flags );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308 if ( ve && ve.isDefaultPrevented() ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 // The target of the mouse events that follow the touchend
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 // event don't necessarily match the target used during the
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311 // touch. This means we need to rely on coordinates for blocking
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312 // any click that is generated.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 t = getNativeEvent( event ).changedTouches[ 0 ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 clickBlockList.push({
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315 touchID: lastTouchID,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 x: t.clientX,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317 y: t.clientY
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320 // Prevent any mouse events that follow from triggering
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 // virtual event notifications.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 blockMouseTriggers = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 triggerVirtualEvent( "vmouseout", event, flags);
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 didScroll = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
328 startResetTimer();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
331 function hasVirtualBindings( ele ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332 var bindings = $.data( ele, dataPropertyName ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333 k;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335 if ( bindings ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336 for ( k in bindings ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
337 if ( bindings[ k ] ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338 return true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
339 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
342 return false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
343 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
344
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
345 function dummyMouseHandler() {}
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
346
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
347 function getSpecialEventObject( eventType ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 var realType = eventType.substr( 1 );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
350 return {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 setup: function(/* data, namespace */) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
352 // If this is the first virtual mouse binding for this element,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353 // add a bindings object to its data.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355 if ( !hasVirtualBindings( this ) ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 $.data( this, dataPropertyName, {} );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359 // If setup is called, we know it is the first binding for this
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
360 // eventType, so initialize the count for the eventType to zero.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361 var bindings = $.data( this, dataPropertyName );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
362 bindings[ eventType ] = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364 // If this is the first virtual mouse event for this type,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
365 // register a global handler on the document.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
366
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
367 activeDocHandlers[ eventType ] = ( activeDocHandlers[ eventType ] || 0 ) + 1;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
368
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369 if ( activeDocHandlers[ eventType ] === 1 ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370 $document.bind( realType, mouseEventCallback );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
371 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
372
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
373 // Some browsers, like Opera Mini, won't dispatch mouse/click events
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374 // for elements unless they actually have handlers registered on them.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
375 // To get around this, we register dummy handlers on the elements.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 $( this ).bind( realType, dummyMouseHandler );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379 // For now, if event capture is not supported, we rely on mouse handlers.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380 if ( eventCaptureSupported ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 // If this is the first virtual mouse binding for the document,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382 // register our touchstart handler on the document.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384 activeDocHandlers[ "touchstart" ] = ( activeDocHandlers[ "touchstart" ] || 0) + 1;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
385
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 if ( activeDocHandlers[ "touchstart" ] === 1 ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 $document.bind( "touchstart", handleTouchStart )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 .bind( "touchend", handleTouchEnd )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 // On touch platforms, touching the screen and then dragging your finger
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391 // causes the window content to scroll after some distance threshold is
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 // exceeded. On these platforms, a scroll prevents a click event from being
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393 // dispatched, and on some platforms, even the touchend is suppressed. To
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
394 // mimic the suppression of the click event, we need to watch for a scroll
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395 // event. Unfortunately, some platforms like iOS don't dispatch scroll
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396 // events until *AFTER* the user lifts their finger (touchend). This means
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
397 // we need to watch both scroll and touchmove events to figure out whether
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398 // or not a scroll happenens before the touchend event is fired.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
399
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400 .bind( "touchmove", handleTouchMove )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
401 .bind( "scroll", handleScroll );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 teardown: function(/* data, namespace */) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 // If this is the last virtual binding for this eventType,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408 // remove its global handler from the document.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 --activeDocHandlers[ eventType ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412 if ( !activeDocHandlers[ eventType ] ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 $document.unbind( realType, mouseEventCallback );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 if ( eventCaptureSupported ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417 // If this is the last virtual mouse binding in existence,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 // remove our document touchstart listener.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420 --activeDocHandlers[ "touchstart" ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422 if ( !activeDocHandlers[ "touchstart" ] ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 $document.unbind( "touchstart", handleTouchStart )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424 .unbind( "touchmove", handleTouchMove )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425 .unbind( "touchend", handleTouchEnd )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426 .unbind( "scroll", handleScroll );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
428 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430 var $this = $( this ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 bindings = $.data( this, dataPropertyName );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433 // teardown may be called when an element was
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 // removed from the DOM. If this is the case,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
435 // jQuery core may have already stripped the element
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 // of any data bindings so we need to check it before
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437 // using it.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 if ( bindings ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 bindings[ eventType ] = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
440 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
442 // Unregister the dummy event handler.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
444 $this.unbind( realType, dummyMouseHandler );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
445
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 // If this is the last virtual mouse binding on the
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447 // element, remove the binding data from the element.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449 if ( !hasVirtualBindings( this ) ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450 $this.removeData( dataPropertyName );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
451 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
452 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456 // Expose our custom events to the jQuery bind/unbind mechanism.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458 for ( i = 0; i < virtualEventNames.length; i++ ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459 $.event.special[ virtualEventNames[ i ] ] = getSpecialEventObject( virtualEventNames[ i ] );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 // Add a capture click handler to block clicks.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 // Note that we require event capture support for this so if the device
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464 // doesn't support it, we punt for now and rely solely on mouse events.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465 if ( eventCaptureSupported ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466 document.addEventListener( "click", function( e ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 var cnt = clickBlockList.length,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468 target = e.target,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469 x, y, ele, i, o, touchID;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
470
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 if ( cnt ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 x = e.clientX;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473 y = e.clientY;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 threshold = $.vmouse.clickDistanceThreshold;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476 // The idea here is to run through the clickBlockList to see if
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
477 // the current click event is in the proximity of one of our
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
478 // vclick events that had preventDefault() called on it. If we find
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
479 // one, then we block the click.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
480 //
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
481 // Why do we have to rely on proximity?
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482 //
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
483 // Because the target of the touch event that triggered the vclick
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
484 // can be different from the target of the click event synthesized
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
485 // by the browser. The target of a mouse/click event that is synthesized
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
486 // from a touch event seems to be implementation specific. For example,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
487 // some browsers will fire mouse/click events for a link that is near
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488 // a touch event, even though the target of the touchstart/touchend event
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
489 // says the user touched outside the link. Also, it seems that with most
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
490 // browsers, the target of the mouse/click event is not calculated until the
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
491 // time it is dispatched, so if you replace an element that you touched
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
492 // with another element, the target of the mouse/click will be the new
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
493 // element underneath that point.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
494 //
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
495 // Aside from proximity, we also check to see if the target and any
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
496 // of its ancestors were the ones that blocked a click. This is necessary
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
497 // because of the strange mouse/click target calculation done in the
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
498 // Android 2.1 browser, where if you click on an element, and there is a
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
499 // mouse/click handler on one of its ancestors, the target will be the
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
500 // innermost child of the touched element, even if that child is no where
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
501 // near the point of touch.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
502
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
503 ele = target;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
504
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
505 while ( ele ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
506 for ( i = 0; i < cnt; i++ ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
507 o = clickBlockList[ i ];
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
508 touchID = 0;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
509
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
510 if ( ( ele === target && Math.abs( o.x - x ) < threshold && Math.abs( o.y - y ) < threshold ) ||
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
511 $.data( ele, touchTargetPropertyName ) === o.touchID ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
512 // XXX: We may want to consider removing matches from the block list
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
513 // instead of waiting for the reset timer to fire.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
514 e.preventDefault();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
515 e.stopPropagation();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
516 return;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
517 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
518 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
519 ele = ele.parentNode;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
520 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
521 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
522 }, true);
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
523 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
524 })( jQuery, window, document );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
525
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
526 (function( $ ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
527 $.mobile = {};
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
528 }( jQuery ));
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530 (function( $, undefined ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
531 var support = {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
532 touch: "ontouchend" in document
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
533 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
534
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
535 $.mobile.support = $.mobile.support || {};
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
536 $.extend( $.support, support );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
537 $.extend( $.mobile.support, support );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
538 }( jQuery ));
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
539
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
540
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
541 (function( $, window, undefined ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
542 var $document = $( document ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
543 supportTouch = $.mobile.support.touch,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
544 scrollEvent = "touchmove scroll",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
545 touchStartEvent = supportTouch ? "touchstart" : "mousedown",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
546 touchStopEvent = supportTouch ? "touchend" : "mouseup",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
547 touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
548
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
549 // setup new event shortcuts
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
550 $.each( ( "touchstart touchmove touchend " +
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551 "tap taphold " +
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
552 "swipe swipeleft swiperight " +
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
553 "scrollstart scrollstop" ).split( " " ), function( i, name ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
554
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
555 $.fn[ name ] = function( fn ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
556 return fn ? this.bind( name, fn ) : this.trigger( name );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
557 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
558
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
559 // jQuery < 1.8
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
560 if ( $.attrFn ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
561 $.attrFn[ name ] = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
562 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
563 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
564
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
565 function triggerCustomEvent( obj, eventType, event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
566 var originalType = event.type;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
567 event.type = eventType;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
568 $.event.dispatch.call( obj, event );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
569 event.type = originalType;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
570 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
571
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
572 // also handles scrollstop
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
573 $.event.special.scrollstart = {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
574
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
575 enabled: true,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
576 setup: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
577
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 var thisObject = this,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
579 $this = $( thisObject ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
580 scrolling,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
581 timer;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
583 function trigger( event, state ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
584 scrolling = state;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
585 triggerCustomEvent( thisObject, scrolling ? "scrollstart" : "scrollstop", event );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
586 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
587
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
588 // iPhone triggers scroll after a small delay; use touchmove instead
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
589 $this.bind( scrollEvent, function( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
590
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
591 if ( !$.event.special.scrollstart.enabled ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
592 return;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
593 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
594
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
595 if ( !scrolling ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
596 trigger( event, true );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
597 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
598
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
599 clearTimeout( timer );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
600 timer = setTimeout( function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
601 trigger( event, false );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
602 }, 50 );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
603 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
604 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
605 teardown: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
606 $( this ).unbind( scrollEvent );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
607 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
608 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
609
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
610 // also handles taphold
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
611 $.event.special.tap = {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
612 tapholdThreshold: 750,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
613 emitTapOnTaphold: true,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
614 setup: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
615 var thisObject = this,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
616 $this = $( thisObject ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
617 isTaphold = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
618
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
619 $this.bind( "vmousedown", function( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
620 isTaphold = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
621 if ( event.which && event.which !== 1 ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
622 return false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
623 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
624
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
625 var origTarget = event.target,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
626 timer;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
627
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
628 function clearTapTimer() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
629 clearTimeout( timer );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
630 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
631
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
632 function clearTapHandlers() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
633 clearTapTimer();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
634
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
635 $this.unbind( "vclick", clickHandler )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
636 .unbind( "vmouseup", clearTapTimer );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
637 $document.unbind( "vmousecancel", clearTapHandlers );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
638 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
639
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
640 function clickHandler( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
641 clearTapHandlers();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
642
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
643 // ONLY trigger a 'tap' event if the start target is
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
644 // the same as the stop target.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
645 if ( !isTaphold && origTarget === event.target ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
646 triggerCustomEvent( thisObject, "tap", event );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
647 } else if ( isTaphold ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
648 event.stopPropagation();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
649 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
650 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
651
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
652 $this.bind( "vmouseup", clearTapTimer )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
653 .bind( "vclick", clickHandler );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
654 $document.bind( "vmousecancel", clearTapHandlers );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
655
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
656 timer = setTimeout( function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
657 if ( !$.event.special.tap.emitTapOnTaphold ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
658 isTaphold = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
659 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
660 triggerCustomEvent( thisObject, "taphold", $.Event( "taphold", { target: origTarget } ) );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
661 }, $.event.special.tap.tapholdThreshold );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
662 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
663 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
664 teardown: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
665 $( this ).unbind( "vmousedown" ).unbind( "vclick" ).unbind( "vmouseup" );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
666 $document.unbind( "vmousecancel" );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
667 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
668 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
669
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
670 // also handles swipeleft, swiperight
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
671 $.event.special.swipe = {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
672 scrollSupressionThreshold: 30, // More than this horizontal displacement, and we will suppress scrolling.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
673
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
674 durationThreshold: 1000, // More time than this, and it isn't a swipe.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
675
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
676 horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
677
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
678 verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
679
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
680 start: function( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
681 var data = event.originalEvent.touches ?
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
682 event.originalEvent.touches[ 0 ] : event;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
683 return {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
684 time: ( new Date() ).getTime(),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
685 coords: [ data.pageX, data.pageY ],
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
686 origin: $( event.target )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
687 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
688 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
689
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
690 stop: function( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
691 var data = event.originalEvent.touches ?
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
692 event.originalEvent.touches[ 0 ] : event;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
693 return {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
694 time: ( new Date() ).getTime(),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
695 coords: [ data.pageX, data.pageY ]
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
696 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
697 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
698
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
699 handleSwipe: function( start, stop, thisObject, origTarget ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
700 if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
701 Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
702 Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
703 var direction = start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight";
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
704
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
705 triggerCustomEvent( thisObject, "swipe", $.Event( "swipe", { target: origTarget, swipestart: start, swipestop: stop }) );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
706 triggerCustomEvent( thisObject, direction,$.Event( direction, { target: origTarget, swipestart: start, swipestop: stop } ) );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
707 return true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
708 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
709 return false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
710
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
711 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
712
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
713 setup: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
714 var thisObject = this,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
715 $this = $( thisObject );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
716
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
717 $this.bind( touchStartEvent, function( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
718 var stop,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
719 start = $.event.special.swipe.start( event ),
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
720 origTarget = event.target,
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
721 emitted = false;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
722
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
723 function moveHandler( event ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
724 if ( !start ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
725 return;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
726 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
727
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
728 stop = $.event.special.swipe.stop( event );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
729 if ( !emitted ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
730 emitted = $.event.special.swipe.handleSwipe( start, stop, thisObject, origTarget );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
731 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
732 // prevent scrolling
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
733 if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
734 event.preventDefault();
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
735 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
736 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
737
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
738 $this.bind( touchMoveEvent, moveHandler )
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
739 .one( touchStopEvent, function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
740 emitted = true;
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
741 $this.unbind( touchMoveEvent, moveHandler );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
742 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
743 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
744 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
745
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
746 teardown: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
747 $( this ).unbind( touchStartEvent ).unbind( touchMoveEvent ).unbind( touchStopEvent );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
748 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
749 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
750 $.each({
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
751 scrollstop: "scrollstart",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
752 taphold: "tap",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
753 swipeleft: "swipe",
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
754 swiperight: "swipe"
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
755 }, function( event, sourceEvent ) {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
756
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
757 $.event.special[ event ] = {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
758 setup: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
759 $( this ).bind( sourceEvent, $.noop );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
760 },
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
761 teardown: function() {
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
762 $( this ).unbind( sourceEvent );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
763 }
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
764 };
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
765 });
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
766
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
767 })( jQuery, this );
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
768
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
769 }));