From 5f325b1bee41d9fcf4b6c59ff44674524fa70400 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Thu, 14 Nov 2013 16:33:12 -0500 Subject: [PATCH] Ref #14180, let focusin/out work on non-element targets. (cherry picked from commit c2aca17d457d302cb1683f925b9e5ee93f0984ea) Conflicts: src/event.js --- src/event.js | 4 ++-- test/unit/event.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/event.js b/src/event.js index 3f19bab30..307907aa0 100644 --- a/src/event.js +++ b/src/event.js @@ -899,7 +899,7 @@ if ( !support.focusinBubbles ) { jQuery.event.special[ fix ] = { setup: function() { - var doc = this.ownerDocument, + var doc = this.ownerDocument || this, attaches = jQuery._data( doc, fix ); if ( !attaches ) { @@ -908,7 +908,7 @@ if ( !support.focusinBubbles ) { jQuery._data( doc, fix, ( attaches || 0 ) + 1 ); }, teardown: function() { - var doc = this.ownerDocument, + var doc = this.ownerDocument || this, attaches = jQuery._data( doc, fix ) - 1; if ( !attaches ) { diff --git a/test/unit/event.js b/test/unit/event.js index 454943718..5c136afeb 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2462,6 +2462,19 @@ test("fixHooks extensions", function() { jQuery.event.fixHooks.click = saved; }); +test( "focusin using non-element targets", function() { + expect( 2 ); + + jQuery( document ).on( "focusin", function( e ) { + ok( e.type === "focusin", "got a focusin event on a document" ); + }).trigger( "focusin" ).off( "focusin" ); + + jQuery( window ).on( "focusin", function( e ) { + ok( e.type === "focusin", "got a focusin event on a window" ); + }).trigger( "focusin" ).off( "focusin" ); + +}); + testIframeWithCallback( "focusin from an iframe", "event/focusinCrossFrame.html", function( frameDoc ) { expect(1); -- 2.39.5