Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Local cache for getClosestElementWithVirtualBinding #4467

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+20 −4
Split
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.