]> source.dussan.org Git - jquery.git/commitdiff
Ref #14180, let focusin/out work on non-element targets.
authorDave Methvin <dave.methvin@gmail.com>
Thu, 14 Nov 2013 21:33:12 +0000 (16:33 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Thu, 14 Nov 2013 21:40:22 +0000 (16:40 -0500)
(cherry picked from commit c2aca17d457d302cb1683f925b9e5ee93f0984ea)

Conflicts:
src/event.js

src/event.js
test/unit/event.js

index 3f19bab305252e50367cf2c9d1e18b5c17cba0f8..307907aa0d923306baac1870bc38302d42fb1680 100644 (file)
@@ -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 ) {
index 454943718c363e72718532e123ba42cbe072f29d..5c136afeb7f49486f654260039c5e6b62ed37c11 100644 (file)
@@ -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);