mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Move quickIs to Sizzle; Remove duplicate id matching in init; Added selector caching to Sizzle. Fixes #11826.
This commit is contained in:
parent
c18f1f119e
commit
713cc86096
38
src/core.js
38
src/core.js
@ -39,9 +39,9 @@ var
|
|||||||
trimLeft = /^\s+/,
|
trimLeft = /^\s+/,
|
||||||
trimRight = /\s+$/,
|
trimRight = /\s+$/,
|
||||||
|
|
||||||
// A simple way to check for HTML strings or ID strings
|
// A simple way to check for HTML strings
|
||||||
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
|
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
|
||||||
quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
|
rhtmlString = /^(?:[^#<]*(<[\w\W]+>)[^>]*$)/,
|
||||||
|
|
||||||
// Match a standalone tag
|
// Match a standalone tag
|
||||||
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
|
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
|
||||||
@ -90,8 +90,8 @@ jQuery.fn = jQuery.prototype = {
|
|||||||
init: function( selector, context, rootjQuery ) {
|
init: function( selector, context, rootjQuery ) {
|
||||||
var match, elem, ret, doc;
|
var match, elem, ret, doc;
|
||||||
|
|
||||||
// Handle $(""), $(null), or $(undefined)
|
// Handle $(""), $(null), $(undefined), $(false), or $("#") for location.hash
|
||||||
if ( !selector ) {
|
if ( !selector || selector === "#" ) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,14 +110,11 @@ jQuery.fn = jQuery.prototype = {
|
|||||||
match = [ null, selector, null ];
|
match = [ null, selector, null ];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
match = quickExpr.exec( selector );
|
match = rhtmlString.exec( selector );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify a match, and that no context was specified for #id
|
|
||||||
if ( match && (match[1] || !context) ) {
|
|
||||||
|
|
||||||
// HANDLE: $(html) -> $(array)
|
// HANDLE: $(html) -> $(array)
|
||||||
if ( match[1] ) {
|
if ( match && match[1] ) {
|
||||||
context = context instanceof jQuery ? context[0] : context;
|
context = context instanceof jQuery ? context[0] : context;
|
||||||
doc = ( context && context.nodeType ? context.ownerDocument || context : document );
|
doc = ( context && context.nodeType ? context.ownerDocument || context : document );
|
||||||
|
|
||||||
@ -138,29 +135,6 @@ jQuery.fn = jQuery.prototype = {
|
|||||||
|
|
||||||
return jQuery.merge( this, selector );
|
return jQuery.merge( this, selector );
|
||||||
|
|
||||||
// HANDLE: $("#id")
|
|
||||||
} else {
|
|
||||||
elem = document.getElementById( match[2] );
|
|
||||||
|
|
||||||
// Check parentNode to catch when Blackberry 4.6 returns
|
|
||||||
// nodes that are no longer in the document #6963
|
|
||||||
if ( elem && elem.parentNode ) {
|
|
||||||
// Handle the case where IE and Opera return items
|
|
||||||
// by name instead of ID
|
|
||||||
if ( elem.id !== match[2] ) {
|
|
||||||
return rootjQuery.find( selector );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, we inject the element directly into the jQuery object
|
|
||||||
this.length = 1;
|
|
||||||
this[0] = elem;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.context = document;
|
|
||||||
this.selector = selector;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HANDLE: $(expr, $(...))
|
// HANDLE: $(expr, $(...))
|
||||||
} else if ( !context || context.jquery ) {
|
} else if ( !context || context.jquery ) {
|
||||||
return ( context || rootjQuery ).find( selector );
|
return ( context || rootjQuery ).find( selector );
|
||||||
|
26
src/event.js
26
src/event.js
@ -4,25 +4,6 @@ var rformElems = /^(?:textarea|input|select)$/i,
|
|||||||
rkeyEvent = /^key/,
|
rkeyEvent = /^key/,
|
||||||
rmouseEvent = /^(?:mouse|contextmenu)|click/,
|
rmouseEvent = /^(?:mouse|contextmenu)|click/,
|
||||||
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
|
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
|
||||||
rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,
|
|
||||||
quickParse = function( selector ) {
|
|
||||||
var quick = rquickIs.exec( selector );
|
|
||||||
if ( quick ) {
|
|
||||||
// 0 1 2 3
|
|
||||||
// [ _, tag, id, class ]
|
|
||||||
quick[1] = ( quick[1] || "" ).toLowerCase();
|
|
||||||
quick[3] = quick[3] && new RegExp( "(?:^|\\s)" + quick[3] + "(?:\\s|$)" );
|
|
||||||
}
|
|
||||||
return quick;
|
|
||||||
},
|
|
||||||
quickIs = function( elem, m ) {
|
|
||||||
var attrs = elem.attributes || {};
|
|
||||||
return (
|
|
||||||
(!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
|
|
||||||
(!m[2] || (attrs.id || {}).value === m[2]) &&
|
|
||||||
(!m[3] || m[3].test( (attrs[ "class" ] || {}).value ))
|
|
||||||
);
|
|
||||||
},
|
|
||||||
hoverHack = function( events ) {
|
hoverHack = function( events ) {
|
||||||
return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
|
return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
|
||||||
};
|
};
|
||||||
@ -37,7 +18,7 @@ jQuery.event = {
|
|||||||
|
|
||||||
var elemData, eventHandle, events,
|
var elemData, eventHandle, events,
|
||||||
t, tns, type, namespaces, handleObj,
|
t, tns, type, namespaces, handleObj,
|
||||||
handleObjIn, quick, handlers, special;
|
handleObjIn, handlers, special;
|
||||||
|
|
||||||
// Don't attach events to noData or text/comment nodes (allow plain objects tho)
|
// Don't attach events to noData or text/comment nodes (allow plain objects tho)
|
||||||
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
|
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
|
||||||
@ -100,7 +81,6 @@ jQuery.event = {
|
|||||||
handler: handler,
|
handler: handler,
|
||||||
guid: handler.guid,
|
guid: handler.guid,
|
||||||
selector: selector,
|
selector: selector,
|
||||||
quick: selector && quickParse( selector ),
|
|
||||||
namespace: namespaces.join(".")
|
namespace: namespaces.join(".")
|
||||||
}, handleObjIn );
|
}, handleObjIn );
|
||||||
|
|
||||||
@ -418,9 +398,7 @@ jQuery.event = {
|
|||||||
sel = handleObj.selector;
|
sel = handleObj.selector;
|
||||||
|
|
||||||
if ( selMatch[ sel ] === undefined ) {
|
if ( selMatch[ sel ] === undefined ) {
|
||||||
selMatch[ sel ] = (
|
selMatch[ sel ] = jqcur.is( sel );
|
||||||
handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if ( selMatch[ sel ] ) {
|
if ( selMatch[ sel ] ) {
|
||||||
matches.push( handleObj );
|
matches.push( handleObj );
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 8881bb2d21a017e4918e4ff81ee2fe716420d2b2
|
Subproject commit d2a68c5835d648a00bce62d41a7e4cf43b1c17bc
|
@ -2793,50 +2793,6 @@ test("clone() delegated events (#11076)", function() {
|
|||||||
clone.remove();
|
clone.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("delegated events quickIs", function() {
|
|
||||||
expect(14);
|
|
||||||
var markup = jQuery(
|
|
||||||
'<div>'+
|
|
||||||
'<p class="D">'+
|
|
||||||
'dead<b class="devo-like">beat</b>club'+
|
|
||||||
'</p>'+
|
|
||||||
'<q id="famous">'+
|
|
||||||
'worked<em>or</em>borked?<em></em>'+
|
|
||||||
'</q>'+
|
|
||||||
'</div>'
|
|
||||||
),
|
|
||||||
str,
|
|
||||||
check = function(el, expect){
|
|
||||||
str = "";
|
|
||||||
markup.find( el ).trigger( "blink" );
|
|
||||||
equal( str, expect, "On " + el );
|
|
||||||
},
|
|
||||||
func = function(e){
|
|
||||||
var tag = this.nodeName.toLowerCase();
|
|
||||||
str += (str && " ") + tag + "|" + e.handleObj.selector;
|
|
||||||
ok( e.handleObj.quick, "Selector "+ e.handleObj.selector + " on " + tag + " is a quickIs case" );
|
|
||||||
};
|
|
||||||
|
|
||||||
// tag#id.class[name=value]
|
|
||||||
markup
|
|
||||||
.appendTo( "body" )
|
|
||||||
.on( "blink", "em", func )
|
|
||||||
.on( "blink", ".D", func )
|
|
||||||
.on( "blink", ".devo-like", func )
|
|
||||||
.on( "blink", ".devo", func )
|
|
||||||
.on( "blink", ".d", func )
|
|
||||||
.on( "blink", "p.d", func )
|
|
||||||
.on( "blink", "#famous", func );
|
|
||||||
|
|
||||||
check( ".devo-like", "b|.devo-like p|.D" );
|
|
||||||
check( ".devo", "" );
|
|
||||||
check( "p", "p|.D" );
|
|
||||||
check( "b", "b|.devo-like p|.D" );
|
|
||||||
check( "em", "em|em q|#famous em|em q|#famous" );
|
|
||||||
|
|
||||||
markup.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("fixHooks extensions", function() {
|
test("fixHooks extensions", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user