Fix #10712. Deal with focus/blur morphing to focusin/focusout.

This commit is contained in:
Dave Methvin 2011-11-08 23:08:04 -05:00
parent 45101de696
commit 39f9b846e7
2 changed files with 12 additions and 8 deletions

View File

@ -5,6 +5,7 @@ var rformElems = /^(?:textarea|input|select)$/i,
rhoverHack = /\bhover(\.\S+)?/,
rkeyEvent = /^key/,
rmouseEvent = /^(?:mouse|contextmenu)|click/,
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,
quickParse = function( selector ) {
var quick = rquickIs.exec( selector );
@ -247,6 +248,11 @@ jQuery.event = {
namespaces = [],
cache, exclusive, i, cur, old, ontype, special, handle, eventPath, bubbleType;
// focus/blur morphs to focusin/out; ensure we're not firing them right now
if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
return;
}
if ( type.indexOf( "!" ) >= 0 ) {
// Exclusive events trigger only for the exact event (no namespaces)
type = type.slice(0, -1);
@ -321,8 +327,9 @@ jQuery.event = {
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
bubbleType = special.delegateType || type;
cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
old = null;
for ( cur = elem.parentNode; cur; cur = cur.parentNode ) {
for ( ; cur; cur = cur.parentNode ) {
eventPath.push([ cur, bubbleType ]);
old = cur;
}
@ -572,12 +579,10 @@ jQuery.event = {
},
focus: {
delegateType: "focusin",
noBubble: true
delegateType: "focusin"
},
blur: {
delegateType: "focusout",
noBubble: true
delegateType: "focusout"
},
beforeunload: {

View File

@ -1563,13 +1563,12 @@ test(".live()/.die()", function() {
jQuery("#nothiddendiv div").die("click");
// div must have a tabindex to be focusable
// blur a non-input element, we should force-fire its handlers
// regardless of whether it's burring or not (unlike browsers)
jQuery("#nothiddendiv div")
.attr("tabindex", "0")
.live("blur", function(){
ok( true, "Live div trigger blur." );
})
.focus()
.trigger("blur")
.die("blur");
});