annotate web/static/jquery.mobile.custom.js @ 208:ea800fcc1ad4

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