$ = this.$ || "$",
originaljQuery = jQuery,
original$ = $,
- amdDefined;
+ amdDefined;
/**
* Set up a mock AMD define function for testing AMD registration.
same(f, q.apply(q,c), a + " (" + b + ")");
}
+var fireNative;
+if ( document.createEvent ) {
+ fireNative = function( node, type ) {
+ var event = document.createEvent('HTMLEvents');
+ event.initEvent( type, true, true );
+ node.dispatchEvent( event );
+ };
+} else {
+ fireNative = function( node, type ) {
+ var event = document.createEventObject();
+ node.fireEvent( 'on' + type, event );
+ };
+}
+
/**
* Add random number to url to stop IE from caching
*
expect(3);
var handler = function( event, data ) {
- equal( data, 0, "non-null, defined data (zero) is correctly passed" );
- };
+ equal( data, 0, "non-null, defined data (zero) is correctly passed" );
+ };
jQuery("#foo").bind("foo", handler);
jQuery("#foo").live("foo", handler);
});
test("Handler changes and .trigger() order", function() {
- expect(1);
+ expect(1);
- var markup = jQuery(
- '<div><div><p><span><b class="a">b</b></span></p></div></div>'
- ),
- path = "";
+ var markup = jQuery(
+ '<div><div><p><span><b class="a">b</b></span></p></div></div>'
+ ),
+ path = "";
- markup
+ markup
.find( "*" ).andSelf().on( "click", function( e ) {
path += this.nodeName.toLowerCase() + " ";
})
}
});
- markup.find( "b" ).trigger( "click" );
+ markup.find( "b" ).trigger( "click" );
- equals( path, "b p div div ", "Delivered all events" );
+ equals( path, "b p div div ", "Delivered all events" );
- markup.remove();
+ markup.remove();
});
test("bind(), with data", function() {
expect(1);
var count = 0,
- handler = function(event) {
- count++;
- };
+ handler = function(event) {
+ count++;
+ };
jQuery("#firstp").bind("click mouseover foo bar baz", handler)
- .trigger("click").trigger("mouseover")
- .trigger("foo").trigger("bar")
- .trigger("baz");
+ .trigger("click").trigger("mouseover")
+ .trigger("foo").trigger("bar")
+ .trigger("baz");
- equals( count, 5, "bind() five events at once" );
+ equals( count, 5, "bind() five events at once" );
});
test("bind(), multiple events at once and namespaces", function() {
$elem.die('mouseleave');
- // Triggers handlrs and native
+ // Triggers handlrs and native
// Trigger 5
$elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
// IE requires focusable elements to be visible, so append to body
var $fixture = jQuery( "<input type='text' id='hook-fixture' />" ).appendTo( "body" ),
- saved = jQuery.event.fixHooks.click;
+ saved = jQuery.event.fixHooks.click;
// Ensure the property doesn't exist
$fixture.bind( "click", function( event ) {
ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" );
- })[0].click();
+ });
+ fireNative( $fixture[0], 'click' );
$fixture.unbind( "click" );
jQuery.event.fixHooks.click = {
// Trigger a native click and ensure the property is set
$fixture.bind( "click", function( event ) {
equals( event.blurrinessLevel, 42, "event.blurrinessLevel was set" );
- })[0].click();
+ });
+ fireNative( $fixture[0], 'click' );
delete jQuery.event.fixHooks.click;
$fixture.unbind( "click" ).remove();