Permalink
Browse files

-- added a local cache for getClosestElementWithVirtualBinding

  • Loading branch information...
1 parent a1f3394 commit cd09190f3f3f93d24a75bafe451704cdc131c2e3 @hpbuniat committed May 28, 2012
Showing with 20 additions and 4 deletions.
  1. +20 −4 js/jquery.mobile.vmouse.js
View
24 js/jquery.mobile.vmouse.js 100644 → 100755
@@ -40,7 +40,8 @@ var dataPropertyName = "virtualMouseBindings",
eventCaptureSupported = "addEventListener" in document,
$document = $( document ),
nextTouchID = 1,
- lastTouchID = 0;
+ lastTouchID = 0,
+ virtualBindingElementCache = [];
$.vmouse = {
moveDistanceThreshold: 10,
@@ -126,14 +127,23 @@ function getVirtualBindingFlags( element ) {
}
function getClosestElementWithVirtualBinding( element, eventType ) {
- var b;
- while ( element ) {
+ if ( virtualBindingElementCache [ element[ $.expando ] ] ) {
+ return virtualBindingElementCache [ element[ $.expando ] ];
+ }
- b = $.data( element, dataPropertyName );
+ var b,
+ elementId = element[ $.expando ];
+ while ( element ) {
+ b = $.data( element, dataPropertyName );
if ( b && ( !eventType || b[ eventType ] ) ) {
+ if ( elementId ) {
+ virtualBindingElementCache [ elementId ] = element;
+ }
+
return element;
}
+
element = element.parentNode;
}
return null;
@@ -339,6 +349,9 @@ function getSpecialEventObject( eventType ) {
$.data( this, dataPropertyName, {});
}
+ // clear the global cache for getClosestElementWithVirtualBinding
+ virtualBindingElementCache = [];
+
// If setup is called, we know it is the first binding for this
// eventType, so initialize the count for the eventType to zero.
var bindings = $.data( this, dataPropertyName );
@@ -426,6 +439,9 @@ function getSpecialEventObject( eventType ) {
$this.unbind( realType, dummyMouseHandler );
+ // clear the global cache for getClosestElementWithVirtualBinding
+ virtualBindingElementCache = [];
+
// If this is the last virtual mouse binding on the
// element, remove the binding data from the element.

0 comments on commit cd09190

Please sign in to comment.