Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

-- added a local cache for getClosestElementWithVirtualBinding

  • Loading branch information...
commit cd09190f3f3f93d24a75bafe451704cdc131c2e3 1 parent a1f3394
Hans-Peter Buniat authored May 28, 2012

Showing 1 changed file with 20 additions and 4 deletions. Show diff stats Hide diff stats

  1. 24  js/jquery.mobile.vmouse.js
24  js/jquery.mobile.vmouse.js 100644 → 100755
@@ -40,7 +40,8 @@ var dataPropertyName = "virtualMouseBindings",
40 40
 	eventCaptureSupported = "addEventListener" in document,
41 41
 	$document = $( document ),
42 42
 	nextTouchID = 1,
43  
-	lastTouchID = 0;
  43
+	lastTouchID = 0,
  44
+	virtualBindingElementCache = [];
44 45
 
45 46
 $.vmouse = {
46 47
 	moveDistanceThreshold: 10,
@@ -126,14 +127,23 @@ function getVirtualBindingFlags( element ) {
126 127
 }
127 128
 
128 129
 function getClosestElementWithVirtualBinding( element, eventType ) {
129  
-	var b;
130  
-	while ( element ) {
  130
+    if ( virtualBindingElementCache [ element[ $.expando ] ] ) {
  131
+        return virtualBindingElementCache [ element[ $.expando ] ];
  132
+    }
131 133
 
132  
-		b = $.data( element, dataPropertyName );
  134
+	var b,
  135
+	    elementId = element[ $.expando ];
  136
+	while ( element ) {
133 137
 
  138
+	    b = $.data( element, dataPropertyName );
134 139
 		if ( b && ( !eventType || b[ eventType ] ) ) {
  140
+		    if ( elementId ) {
  141
+		        virtualBindingElementCache [ elementId ] = element;
  142
+		    }
  143
+
135 144
 			return element;
136 145
 		}
  146
+
137 147
 		element = element.parentNode;
138 148
 	}
139 149
 	return null;
@@ -339,6 +349,9 @@ function getSpecialEventObject( eventType ) {
339 349
 				$.data( this, dataPropertyName, {});
340 350
 			}
341 351
 
  352
+			// clear the global cache for getClosestElementWithVirtualBinding
  353
+			virtualBindingElementCache = [];
  354
+
342 355
 			// If setup is called, we know it is the first binding for this
343 356
 			// eventType, so initialize the count for the eventType to zero.
344 357
 			var bindings = $.data( this, dataPropertyName );
@@ -426,6 +439,9 @@ function getSpecialEventObject( eventType ) {
426 439
 
427 440
 			$this.unbind( realType, dummyMouseHandler );
428 441
 
  442
+	         // clear the global cache for getClosestElementWithVirtualBinding
  443
+            virtualBindingElementCache = [];
  444
+
429 445
 			// If this is the last virtual mouse binding on the
430 446
 			// element, remove the binding data from the element.
431 447
 

0 notes on commit cd09190

Please sign in to comment.
Something went wrong with that request. Please try again.