Skip to content
Permalink
Browse files

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

  • Loading branch information...
dmethvin committed Nov 9, 2011
1 parent 45101de commit 39f9b846e722600aece0a5428e38e9b12217395e
Showing with 12 additions and 8 deletions.
  1. +10 −5 src/event.js
  2. +2 −3 test/unit/event.js
@@ -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: {
@@ -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");
});

0 comments on commit 39f9b84

Please sign in to comment.
You can’t perform that action at this time.