From 022b69a44e42684bdd0029dd456bedb3b495cc24 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Fri, 29 Dec 2017 16:58:45 -0500 Subject: [PATCH] Event: Move event aliases to deprecated Fixes gh-3214 --- src/deprecated.js | 4 +- src/jquery.js | 1 - test/unit/deprecated.js | 76 ++++++++++++++++++++++++++++++++++++ test/unit/event.js | 86 ----------------------------------------- 4 files changed, 79 insertions(+), 88 deletions(-) diff --git a/src/deprecated.js b/src/deprecated.js index 82ef686e0..0982f3a94 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -4,7 +4,9 @@ define( [ "./core/camelCase", "./var/isFunction", "./var/isWindow", - "./var/slice" + "./var/slice", + + "./event/alias" ], function( jQuery, nodeName, camelCase, isFunction, isWindow, slice ) { "use strict"; diff --git a/src/jquery.js b/src/jquery.js index 52fc87dbd..0e026a6c1 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -11,7 +11,6 @@ define( [ "./queue/delay", "./attributes", "./event", - "./event/alias", "./event/focusin", "./manipulation", "./manipulation/_evalUrl", diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index 19810151f..554ab443e 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -41,6 +41,82 @@ QUnit.test( "delegate/undelegate", function( assert ) { .remove(); } ); +if ( jQuery.fn.hover ) { + QUnit.test( "hover() mouseenter mouseleave", function( assert ) { + assert.expect( 1 ); + + var times = 0, + handler1 = function() { ++times; }, + handler2 = function() { ++times; }; + + jQuery( "#firstp" ) + .hover( handler1, handler2 ) + .mouseenter().mouseleave() + .off( "mouseenter", handler1 ) + .off( "mouseleave", handler2 ) + .hover( handler1 ) + .mouseenter().mouseleave() + .off( "mouseenter mouseleave", handler1 ) + .mouseenter().mouseleave(); + + assert.equal( times, 4, "hover handlers fired" ); + + } ); +} + + +QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) { + assert.expect( 5 ); + + var counter, clickCounter, + elem = jQuery( "
  • Change location
  • " ).prependTo( "#firstUL" ); + elem.find( "a" ).on( "click", function() { + var close = jQuery( "spanx", this ); // same with jQuery(this).find("span"); + assert.equal( close.length, 0, "Context element does not exist, length must be zero" ); + assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" ); + return false; + } ).click(); + + // manually clean up detached elements + elem.remove(); + + jQuery( "#check1" ).click( function() { + assert.ok( true, "click event handler for checkbox gets fired twice, see #815" ); + } ).click(); + + counter = 0; + jQuery( "#firstp" )[ 0 ].onclick = function() { + counter++; + }; + jQuery( "#firstp" ).click(); + assert.equal( counter, 1, "Check that click, triggers onclick event handler also" ); + + clickCounter = 0; + jQuery( "#simon1" )[ 0 ].onclick = function() { + clickCounter++; + }; + jQuery( "#simon1" ).click(); + assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); +} ); + +QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) { + + // Explicitly skipping focus/blur events due to their flakiness + var $elem = jQuery( "
    " ).appendTo( "#qunit-fixture" ), + aliases = ( "resize scroll click dblclick mousedown mouseup " + + "mousemove mouseover mouseout mouseenter mouseleave change " + + "select submit keydown keypress keyup contextmenu" ).split( " " ); + assert.expect( aliases.length ); + + jQuery.each( aliases, function( i, name ) { + + // e.g. $(elem).click(...).click(); + $elem[ name ]( function( event ) { + assert.equal( event.type, name, "triggered " + name ); + } )[ name ]().off( name ); + } ); +} ); + QUnit.test( "jQuery.parseJSON", function( assert ) { assert.expect( 20 ); diff --git a/test/unit/event.js b/test/unit/event.js index 5dc17722d..f146df86a 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -872,29 +872,6 @@ QUnit.test( "off(eventObject)", function( assert ) { check( 0 ); } ); -if ( jQuery.fn.hover ) { - QUnit.test( "hover() mouseenter mouseleave", function( assert ) { - assert.expect( 1 ); - - var times = 0, - handler1 = function() { ++times; }, - handler2 = function() { ++times; }; - - jQuery( "#firstp" ) - .hover( handler1, handler2 ) - .mouseenter().mouseleave() - .off( "mouseenter", handler1 ) - .off( "mouseleave", handler2 ) - .hover( handler1 ) - .mouseenter().mouseleave() - .off( "mouseenter mouseleave", handler1 ) - .mouseenter().mouseleave(); - - assert.equal( times, 4, "hover handlers fired" ); - - } ); -} - QUnit.test( "mouseover triggers mouseenter", function( assert ) { assert.expect( 1 ); @@ -2434,17 +2411,6 @@ QUnit.test( "checkbox state (#3827)", function( assert ) { jQuery( cb ).triggerHandler( "click" ); } ); -QUnit.test( "hover event no longer special since 1.9", function( assert ) { - assert.expect( 1 ); - - jQuery( "
    craft
    " ) - .on( "hover", function( e ) { - assert.equal( e.type, "hover", "I am hovering!" ); - } ) - .trigger( "hover" ) - .off( "hover" ); -} ); - QUnit.test( "event object properties on natively-triggered event", function( assert ) { assert.expect( 3 ); @@ -2959,58 +2925,6 @@ QUnit.test( "trigger('click') on radio passes extra params", function( assert ) $radio.trigger( "click", [ true ] ); } ); -QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) { - assert.expect( 5 ); - - var counter, clickCounter, - elem = jQuery( "
  • Change location
  • " ).prependTo( "#firstUL" ); - elem.find( "a" ).on( "click", function() { - var close = jQuery( "spanx", this ); // same with jQuery(this).find("span"); - assert.equal( close.length, 0, "Context element does not exist, length must be zero" ); - assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" ); - return false; - } ).click(); - - // manually clean up detached elements - elem.remove(); - - jQuery( "#check1" ).click( function() { - assert.ok( true, "click event handler for checkbox gets fired twice, see #815" ); - } ).click(); - - counter = 0; - jQuery( "#firstp" )[ 0 ].onclick = function() { - counter++; - }; - jQuery( "#firstp" ).click(); - assert.equal( counter, 1, "Check that click, triggers onclick event handler also" ); - - clickCounter = 0; - jQuery( "#simon1" )[ 0 ].onclick = function() { - clickCounter++; - }; - jQuery( "#simon1" ).click(); - assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); -} ); - -QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) { - - // Explicitly skipping focus/blur events due to their flakiness - var $elem = jQuery( "
    " ).appendTo( "#qunit-fixture" ), - aliases = ( "resize scroll click dblclick mousedown mouseup " + - "mousemove mouseover mouseout mouseenter mouseleave change " + - "select submit keydown keypress keyup contextmenu" ).split( " " ); - assert.expect( aliases.length ); - - jQuery.each( aliases, function( i, name ) { - - // e.g. $(elem).click(...).click(); - $elem[ name ]( function( event ) { - assert.equal( event.type, name, "triggered " + name ); - } )[ name ]().off( name ); - } ); -} ); - // Support: IE <=9 only // https://msdn.microsoft.com/en-us/library/hh801223(v=vs.85).aspx QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) { -- 2.39.5