2019-02-18 18:02:38 +00:00
|
|
|
QUnit.module( "deprecated", { afterEach: moduleTeardown } );
|
2013-04-08 22:18:45 +00:00
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
if ( includesModule( "deprecated" ) ) {
|
2015-10-01 20:03:10 +00:00
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
QUnit.test( "bind/unbind", function( assert ) {
|
2015-10-01 20:03:10 +00:00
|
|
|
assert.expect( 4 );
|
|
|
|
|
|
|
|
var markup = jQuery(
|
|
|
|
"<div><p><span><b>b</b></span></p></div>"
|
|
|
|
);
|
|
|
|
|
|
|
|
markup
|
|
|
|
.find( "b" )
|
|
|
|
.bind( "click", { bindData: 19 }, function( e, trig ) {
|
|
|
|
assert.equal( e.type, "click", "correct event type" );
|
|
|
|
assert.equal( e.data.bindData, 19, "correct trigger data" );
|
|
|
|
assert.equal( trig, 42, "correct bind data" );
|
2016-05-10 09:12:28 +00:00
|
|
|
assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
|
2015-10-01 20:03:10 +00:00
|
|
|
} )
|
|
|
|
.trigger( "click", [ 42 ] )
|
|
|
|
.unbind( "click" )
|
|
|
|
.trigger( "click" )
|
|
|
|
.remove();
|
|
|
|
} );
|
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
QUnit.test( "delegate/undelegate", function( assert ) {
|
2015-10-01 20:03:10 +00:00
|
|
|
assert.expect( 2 );
|
|
|
|
|
|
|
|
var markup = jQuery(
|
|
|
|
"<div><p><span><b>b</b></span></p></div>"
|
|
|
|
);
|
|
|
|
|
|
|
|
markup
|
|
|
|
.delegate( "b", "click", function( e ) {
|
|
|
|
assert.equal( e.type, "click", "correct event type" );
|
2016-05-10 09:12:28 +00:00
|
|
|
assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
|
2015-10-01 20:03:10 +00:00
|
|
|
} )
|
|
|
|
.find( "b" )
|
|
|
|
.trigger( "click" )
|
|
|
|
.end()
|
|
|
|
.undelegate( "b", "click" )
|
|
|
|
.remove();
|
2016-02-24 22:47:19 +00:00
|
|
|
} );
|
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
QUnit.test( "hover() mouseenter mouseleave", function( assert ) {
|
2019-05-13 19:39:56 +00:00
|
|
|
assert.expect( 1 );
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
var times = 0,
|
2023-09-18 16:39:00 +00:00
|
|
|
handler1 = function() {
|
|
|
|
++times;
|
|
|
|
},
|
|
|
|
handler2 = function() {
|
|
|
|
++times;
|
|
|
|
};
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
jQuery( "#firstp" )
|
|
|
|
.hover( handler1, handler2 )
|
|
|
|
.mouseenter().mouseleave()
|
|
|
|
.off( "mouseenter", handler1 )
|
|
|
|
.off( "mouseleave", handler2 )
|
|
|
|
.hover( handler1 )
|
|
|
|
.mouseenter().mouseleave()
|
|
|
|
.off( "mouseenter mouseleave", handler1 )
|
|
|
|
.mouseenter().mouseleave();
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2019-05-13 19:39:56 +00:00
|
|
|
assert.equal( times, 4, "hover handlers fired" );
|
|
|
|
} );
|
2017-12-29 21:58:45 +00:00
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
QUnit.test( "trigger() shortcuts", function( assert ) {
|
2017-12-29 21:58:45 +00:00
|
|
|
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() {
|
2022-01-04 15:27:18 +00:00
|
|
|
assert.ok( true, "click event handler for checkbox gets fired twice, see trac-815" );
|
2017-12-29 21:58:45 +00:00
|
|
|
} ).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;
|
2024-08-12 18:01:19 +00:00
|
|
|
jQuery( "#john1" )[ 0 ].onclick = function() {
|
2017-12-29 21:58:45 +00:00
|
|
|
clickCounter++;
|
|
|
|
};
|
2024-08-12 18:01:19 +00:00
|
|
|
jQuery( "#john1" ).click();
|
2017-12-29 21:58:45 +00:00
|
|
|
assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
|
|
|
|
} );
|
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
if ( includesModule( "ajax" ) ) {
|
2023-03-15 10:44:08 +00:00
|
|
|
ajaxTest( "Ajax events aliases (with context)", 12, function( assert ) {
|
2020-01-07 22:59:08 +00:00
|
|
|
var context = document.createElement( "div" );
|
|
|
|
|
|
|
|
function event( e ) {
|
|
|
|
assert.equal( this, context, e.type );
|
|
|
|
}
|
|
|
|
|
|
|
|
function callback( msg ) {
|
|
|
|
return function() {
|
|
|
|
assert.equal( this, context, "context is preserved on callback " + msg );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
setup: function() {
|
|
|
|
jQuery( context ).appendTo( "#foo" )
|
2023-03-15 10:44:08 +00:00
|
|
|
.ajaxSend( event )
|
|
|
|
.ajaxComplete( event )
|
|
|
|
.ajaxError( event )
|
|
|
|
.ajaxSuccess( event );
|
2020-01-07 22:59:08 +00:00
|
|
|
},
|
|
|
|
requests: [ {
|
|
|
|
url: url( "name.html" ),
|
|
|
|
context: context,
|
|
|
|
beforeSend: callback( "beforeSend" ),
|
|
|
|
success: callback( "success" ),
|
|
|
|
complete: callback( "complete" )
|
|
|
|
}, {
|
|
|
|
url: url( "404.txt" ),
|
|
|
|
context: context,
|
|
|
|
beforeSend: callback( "beforeSend" ),
|
|
|
|
error: callback( "error" ),
|
|
|
|
complete: callback( "complete" )
|
|
|
|
} ]
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
QUnit.test( "Event aliases", function( assert ) {
|
2017-12-29 21:58:45 +00:00
|
|
|
|
|
|
|
// Explicitly skipping focus/blur events due to their flakiness
|
2020-03-16 20:49:29 +00:00
|
|
|
var $elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ),
|
2017-12-29 21:58:45 +00:00
|
|
|
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 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2022-06-28 10:39:01 +00:00
|
|
|
QUnit.test( "jQuery.proxy", function( assert ) {
|
2017-12-11 17:58:35 +00:00
|
|
|
assert.expect( 9 );
|
|
|
|
|
|
|
|
var test2, test3, test4, fn, cb,
|
|
|
|
test = function() {
|
|
|
|
assert.equal( this, thisObject, "Make sure that scope is set properly." );
|
|
|
|
},
|
|
|
|
thisObject = { foo: "bar", method: test };
|
|
|
|
|
|
|
|
// Make sure normal works
|
|
|
|
test.call( thisObject );
|
|
|
|
|
|
|
|
// Basic scoping
|
|
|
|
jQuery.proxy( test, thisObject )();
|
|
|
|
|
|
|
|
// Another take on it
|
|
|
|
jQuery.proxy( thisObject, "method" )();
|
|
|
|
|
|
|
|
// Make sure it doesn't freak out
|
|
|
|
assert.equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
|
|
|
|
|
|
|
|
// Partial application
|
|
|
|
test2 = function( a ) {
|
|
|
|
assert.equal( a, "pre-applied", "Ensure arguments can be pre-applied." );
|
|
|
|
};
|
|
|
|
jQuery.proxy( test2, null, "pre-applied" )();
|
|
|
|
|
|
|
|
// Partial application w/ normal arguments
|
|
|
|
test3 = function( a, b ) {
|
|
|
|
assert.equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." );
|
|
|
|
};
|
|
|
|
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
|
|
|
|
|
|
|
|
// Test old syntax
|
|
|
|
test4 = { "meth": function( a ) {
|
|
|
|
assert.equal( a, "boom", "Ensure old syntax works." );
|
|
|
|
} };
|
|
|
|
jQuery.proxy( test4, "meth" )( "boom" );
|
|
|
|
|
|
|
|
// jQuery 1.9 improved currying with `this` object
|
|
|
|
fn = function() {
|
|
|
|
assert.equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
|
|
|
|
assert.equal( this.foo, "bar", "this-object passed" );
|
|
|
|
};
|
|
|
|
cb = jQuery.proxy( fn, null, "arg1", "arg2" );
|
|
|
|
cb.call( thisObject, "arg3" );
|
|
|
|
} );
|
2022-06-28 10:39:01 +00:00
|
|
|
|
|
|
|
}
|