Skip to content

Commit

Permalink
Event: Stop shimming focusin & focusout events
Browse files Browse the repository at this point in the history
Latest versions of all browsers now implement focusin & focusout natively
and they all converged on a common event order so it doesn't make much sense
for us to normalize it to a different order anymore.

Note that it means we no longer guarantee that focusin fires before focus
and focusout before blur.

Fixes jquerygh-4300
Closes jquerygh-4362
  • Loading branch information
mgol authored Apr 29, 2019
1 parent 8fae212 commit 8a74137
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 93 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ Some example modules that can be excluded are:
- **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
- **event**: The `.on()` and `.off()` methods and all event functionality. Also removes `event/alias`.
- **event/alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`.
- **event/focusin**: Cross-browser support for the focusin and focusout events.
- **event/trigger**: The `.trigger()` and `.triggerHandler()` methods. Used by **alias** and **focusin** modules.
- **event/trigger**: The `.trigger()` and `.triggerHandler()` methods. Used by the **alias** module.
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
- **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
Expand Down
55 changes: 0 additions & 55 deletions src/event/focusin.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/event/support.js

This file was deleted.

1 change: 0 additions & 1 deletion src/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ define( [
"./queue/delay",
"./attributes",
"./event",
"./event/focusin",
"./manipulation",
"./manipulation/_evalUrl",
"./wrap",
Expand Down
45 changes: 34 additions & 11 deletions test/unit/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2946,39 +2946,62 @@ QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) {
ns.remove();
} );

QUnit.test( "Check order of focusin/focusout events", function( assert ) {
assert.expect( 2 );
QUnit.test( "focusout/focusin support", function( assert ) {
assert.expect( 6 );

var focus,
parent = jQuery( "<div>" ),
input = jQuery( "<input>" ),
inputExternal = jQuery( "<input>" );

var focus, blur,
input = jQuery( "#name" );
parent.append( input );
jQuery( "#qunit-fixture" ).append( parent ).append( inputExternal );

parent
.on( "focus", function() {
assert.ok( false, "parent: focus not fired" );
} )
.on( "focusin", function() {
assert.ok( true, "parent: focusin fired" );
} )
.on( "blur", function() {
assert.ok( false, "parent: blur not fired" );
} )
.on( "focusout", function() {
assert.ok( true, "parent: focusout fired" );
} );

input
.on( "focus", function() {
assert.ok( true, "element: focus fired" );
focus = true;
} )
.on( "focusin", function() {
assert.ok( !focus, "Focusin event should fire before focus does" );
focus = true;
assert.ok( true, "element: focusin fired" );
} )
.on( "blur", function() {
blur = true;
assert.ok( true, "parent: blur fired" );
} )
.on( "focusout", function() {
assert.ok( !blur, "Focusout event should fire before blur does" );
blur = true;
assert.ok( true, "element: focusout fired" );
} );

// gain focus
input.trigger( "focus" );

// then lose it
jQuery( "#search" ).trigger( "focus" );
inputExternal.trigger( "focus" );

// cleanup
parent.off();
input.off();

// DOM focus is unreliable in TestSwarm
if ( !focus ) {
if ( QUnit.isSwarm && !focus ) {
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
}
Expand Down
13 changes: 0 additions & 13 deletions test/unit/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": true,
Expand All @@ -83,7 +82,6 @@ testIframe(
"clearCloneStyle": false,
"cors": true,
"createHTMLDocument": true,
"focusin": true,
"noCloneChecked": false,
"optSelected": false,
"pixelBoxStyles": true,
Expand All @@ -100,7 +98,6 @@ testIframe(
"clearCloneStyle": false,
"cors": false,
"createHTMLDocument": true,
"focusin": true,
"noCloneChecked": false,
"optSelected": false,
"pixelBoxStyles": true,
Expand All @@ -117,7 +114,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": true,
Expand All @@ -134,7 +130,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": true,
Expand All @@ -151,7 +146,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": false,
Expand All @@ -168,7 +162,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": true,
Expand All @@ -185,7 +178,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": true,
Expand All @@ -202,7 +194,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": true,
Expand All @@ -219,7 +210,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": false,
Expand All @@ -236,7 +226,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": false,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": false,
Expand All @@ -253,7 +242,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": false,
Expand All @@ -270,7 +258,6 @@ testIframe(
"clearCloneStyle": true,
"cors": true,
"createHTMLDocument": true,
"focusin": false,
"noCloneChecked": true,
"optSelected": true,
"pixelBoxStyles": false,
Expand Down

0 comments on commit 8a74137

Please sign in to comment.