]> 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:33:12 +0000 (16:33 -0500)
src/event.js
test/unit/event.js

index 5ca6d2e9696daa9252e979dda7354730752edc20..8d403121134ac173a2571d8f08b1e2dc419900c9 100644 (file)
@@ -728,7 +728,7 @@ if ( !support.focusinBubbles ) {
 
                jQuery.event.special[ fix ] = {
                        setup: function() {
-                               var doc = this.ownerDocument,
+                               var doc = this.ownerDocument || this,
                                        attaches = data_priv.access( doc, fix );
 
                                if ( !attaches ) {
@@ -737,7 +737,7 @@ if ( !support.focusinBubbles ) {
                                data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
                        },
                        teardown: function() {
-                               var doc = this.ownerDocument,
+                               var doc = this.ownerDocument || this,
                                        attaches = data_priv.access( doc, fix ) - 1;
 
                                if ( !attaches ) {
index a18f2f673efaa291cbc920f8071aebbc650c9cf7..334dc6b1c9a2de604cd10b38831b76071216c185 100644 (file)
@@ -2374,6 +2374,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);