aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-11-06 20:12:00 -0500
committerDave Methvin <dave.methvin@gmail.com>2011-11-06 20:12:00 -0500
commita7e911b7fe84a35234d4be18102e168c6644e40d (patch)
tree471524f1a699c5ce95bc7a42603280f736556860 /src/event.js
parentf5250e15946b111de2bdc5ff5d321f3601db3e0a (diff)
downloadjquery-a7e911b7fe84a35234d4be18102e168c6644e40d.tar.gz
jquery-a7e911b7fe84a35234d4be18102e168c6644e40d.zip
Since we fixed .is(POS) let's use it and save bytes.
Also, creates a single jQuery object and reuses it in the delegation-test loop to make it more performancy.
Diffstat (limited to 'src/event.js')
-rw-r--r--src/event.js28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/event.js b/src/event.js
index 4cbd4b072..0ccf23da3 100644
--- a/src/event.js
+++ b/src/event.js
@@ -99,17 +99,10 @@ jQuery.event = {
handler: handler,
guid: handler.guid,
selector: selector,
+ quick: quickParse( selector ),
namespace: namespaces.join(".")
}, handleObjIn );
- // Delegated event; pre-analyze selector so it's processed quickly on event dispatch
- if ( selector ) {
- handleObj.quick = quickParse( selector );
- if ( !handleObj.quick && jQuery.expr.match.POS.test( selector ) ) {
- handleObj.isPositional = true;
- }
- }
-
// Init the event handler queue if we're the first
handlers = events[ type ];
if ( !handlers ) {
@@ -406,7 +399,7 @@ jQuery.event = {
run_all = !event.exclusive && !event.namespace,
specialHandle = ( jQuery.event.special[ event.type ] || {} ).handle,
handlerQueue = [],
- i, j, cur, ret, selMatch, matched, matches, handleObj, sel, hit, related;
+ i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related;
// Use the fix-ed jQuery.Event rather than the (read-only) native event
args[0] = event;
@@ -416,21 +409,24 @@ jQuery.event = {
// Avoid disabled elements in IE (#6911) and non-left-click bubbling in Firefox (#3861)
if ( delegateCount && !event.target.disabled && !(event.button && event.type === "click") ) {
+ // Pregenerate a single jQuery object for reuse with .is()
+ jqcur = jQuery(this);
+ jqcur.context = this.ownerDocument || this;
+
for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
selMatch = {};
matches = [];
+ jqcur[0] = cur;
for ( i = 0; i < delegateCount; i++ ) {
handleObj = handlers[ i ];
sel = handleObj.selector;
- hit = selMatch[ sel ];
- if ( handleObj.isPositional ) {
- // Since .is() does not work for positionals; see http://jsfiddle.net/eJ4yd/3/
- hit = ( hit || (selMatch[ sel ] = jQuery( sel )) ).index( cur ) >= 0;
- } else if ( hit === undefined ) {
- hit = selMatch[ sel ] = ( handleObj.quick ? quickIs( cur, handleObj.quick ) : jQuery( cur ).is( sel ) );
+ if ( selMatch[ sel ] === undefined ) {
+ selMatch[ sel ] = (
+ handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
+ );
}
- if ( hit ) {
+ if ( selMatch[ sel ] ) {
matches.push( handleObj );
}
}