From 469150a27e90dcf523a30211a9e8667a64718b81 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 22 Oct 2013 22:47:34 -0400 Subject: [PATCH] Revert "Fix #14180. Allow cross-frame use of focusin/out. Close gh-1369." This reverts commit bba8366af48bd2c80c96e7a0f58b3e16fd736125. Because cross-frame focus sucks. --- src/event.js | 21 +++++++------------- test/data/event/focusinCrossFrame.html | 18 ----------------- test/unit/event.js | 27 -------------------------- 3 files changed, 7 insertions(+), 59 deletions(-) delete mode 100644 test/data/event/focusinCrossFrame.html diff --git a/src/event.js b/src/event.js index cc0fe1700..a6f69f49f 100644 --- a/src/event.js +++ b/src/event.js @@ -892,29 +892,22 @@ if ( !support.changeBubbles ) { if ( !support.focusinBubbles ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { - // Attach a single capturing handler on the document while someone wants focusin/focusout - var handler = function( event ) { + // Attach a single capturing handler while someone wants focusin/focusout + var attaches = 0, + handler = function( event ) { jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); }; jQuery.event.special[ fix ] = { setup: function() { - var doc = this.ownerDocument, - attaches = jQuery._data( doc, "focusCount" ); - - if ( !attaches ) { - doc.addEventListener( orig, handler, true ); + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); } - jQuery._data( doc, "focusCount", ( attaches || 0 ) + 1 ); }, teardown: function() { - var doc = this.ownerDocument, - attaches = jQuery._data( doc, "focusCount" ) - 1; - - if ( !attaches ) { - doc.removeEventListener( orig, handler, true ); + if ( --attaches === 0 ) { + document.removeEventListener( orig, handler, true ); } - jQuery._data( doc, "focusCount", attaches ); } }; }); diff --git a/test/data/event/focusinCrossFrame.html b/test/data/event/focusinCrossFrame.html deleted file mode 100644 index 487f8de8f..000000000 --- a/test/data/event/focusinCrossFrame.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - focusin event cross-frame (#14180) - - - - - - - - diff --git a/test/unit/event.js b/test/unit/event.js index 1310e050a..d81551da9 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2507,33 +2507,6 @@ test("fixHooks extensions", function() { jQuery.event.fixHooks.click = saved; }); -testIframeWithCallback( "focusin from an iframe", "event/focusinCrossFrame.html", function( frameDoc ) { - expect(1); - - var input = jQuery( frameDoc ).find( "#frame-input" ); - - // Create a focusin handler on the parent; shouldn't affect the iframe's fate - jQuery ( "body" ).on( "focusin.iframeTest", function() { - ok( false, "fired a focusin event in the parent document" ); - }); - - input.on( "focusin", function() { - ok( true, "fired a focusin event in the iframe" ); - }); - - // Avoid a native event; Chrome can't force focus to another frame - input.trigger( "focusin" ); - - // Must manually remove handler to avoid leaks in our data store - input.remove(); - - // Be sure it was removed; nothing should happen - input.trigger( "focusin" ); - - // Remove body handler manually since it's outside the fixture - jQuery( "body" ).off( "focusin.iframeTest" ); -}); - testIframeWithCallback( "jQuery.ready promise", "event/promiseReady.html", function( isOk ) { expect(1); ok( isOk, "$.when( $.ready ) works" ); -- 2.39.5