diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2013-09-17 18:51:54 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2013-10-22 21:48:50 -0400 |
commit | bba8366af48bd2c80c96e7a0f58b3e16fd736125 (patch) | |
tree | ae45739c43aebbbc12d71c646010a157670dcae9 /src/event.js | |
parent | aa708195982d2637f9949e9c250c475f88214af9 (diff) | |
download | jquery-bba8366af48bd2c80c96e7a0f58b3e16fd736125.tar.gz jquery-bba8366af48bd2c80c96e7a0f58b3e16fd736125.zip |
Fix #14180. Allow cross-frame use of focusin/out. Close gh-1369.
(cherry picked from commit 6d5dfa0eda2c19e8838930fafff83b596654eca2)
Manually edited for conflicts.
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 a6f69f49f..cc0fe1700 100644 --- a/src/event.js +++ b/src/event.js @@ -892,22 +892,29 @@ if ( !support.changeBubbles ) { 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 = jQuery._data( doc, "focusCount" ); + + if ( !attaches ) { + doc.addEventListener( orig, handler, true ); } + jQuery._data( doc, "focusCount", ( attaches || 0 ) + 1 ); }, teardown: function() { - if ( --attaches === 0 ) { - document.removeEventListener( orig, handler, true ); + var doc = this.ownerDocument, + attaches = jQuery._data( doc, "focusCount" ) - 1; + + if ( !attaches ) { + doc.removeEventListener( orig, handler, true ); } + jQuery._data( doc, "focusCount", attaches ); } }; }); |