Permalink
Browse files

Event: Move event aliases to deprecated

Fixes gh-3214
  • Loading branch information...
dmethvin committed Dec 29, 2017
1 parent 3d732cc commit 022b69a44e42684bdd0029dd456bedb3b495cc24
Showing with 79 additions and 88 deletions.
  1. +3 −1 src/deprecated.js
  2. +0 −1 src/jquery.js
  3. +76 −0 test/unit/deprecated.js
  4. +0 −86 test/unit/event.js
View
@@ -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";
View
@@ -11,7 +11,6 @@ define( [
"./queue/delay",
"./attributes",
"./event",
"./event/alias",
"./event/focusin",
"./manipulation",
"./manipulation/_evalUrl",
View
@@ -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( "<li><a href='#'>Change location</a></li>" ).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( "<div />" ).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 );
View
@@ -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( "<div>craft</div>" )
.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( "<li><a href='#'>Change location</a></li>" ).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( "<div />" ).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 ) {

0 comments on commit 022b69a

Please sign in to comment.