diff options
Diffstat (limited to 'src/event.js')
-rw-r--r-- | src/event.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/event.js b/src/event.js index 2fd702c63..ce5b453d2 100644 --- a/src/event.js +++ b/src/event.js @@ -727,22 +727,29 @@ jQuery.each({ if ( !support.focusinBubbles ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { - // Attach a single capturing handler while someone wants focusin/focusout - var attaches = 0, - handler = function( event ) { + // Attach a single capturing handler on the document while someone wants focusin/focusout + var handler = function( event ) { jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); }; jQuery.event.special[ fix ] = { setup: function() { - if ( attaches++ === 0 ) { - document.addEventListener( orig, handler, true ); + var doc = this.ownerDocument, + attaches = data_priv.access( doc, "focusCount" ); + + if ( !attaches ) { + doc.addEventListener( orig, handler, true ); } + data_priv.access( doc, "focusCount", ( attaches || 0 ) + 1 ); }, teardown: function() { - if ( --attaches === 0 ) { - document.removeEventListener( orig, handler, true ); + var doc = this.ownerDocument, + attaches = data_priv.access( doc, "focusCount" ) - 1; + + if ( !attaches ) { + doc.removeEventListener( orig, handler, true ); } + data_priv.access( doc, "focusCount", attaches ); } }; }); |