element = window;
// if data is passed, bind to handler
- if( data != undefined ) {
+ if( data != handler ) {
// Create temporary function pointer to original handler
var fn = handler;
if (element.addEventListener)
element.addEventListener(type, element.$handle, false);
else if (element.attachEvent)
- element.attachEvent("on" + type, element.$handle, false);
+ element.attachEvent("on" + type, element.$handle);
}
// Add the function to the element's handler list
if (element.removeEventListener)
element.removeEventListener(type, element.$handle, false);
else if (element.detachEvent)
- element.detachEvent("on" + type, element.$handle, false);
+ element.detachEvent("on" + type, element.$handle);
ret = null;
delete events[type];
}
*/
bind: function( type, data, fn ) {
return this.each(function(){
- jQuery.event.add( this, type, fn || data, data );
+ jQuery.event.add( this, type, fn || data, fn && data );
});
},
jQuery.event.add( this, type, function(event) {
jQuery(this).unbind(event);
return (fn || data).apply( this, arguments);
- }, data);
+ }, fn && data);
});
},
module("event");
test("bind()", function() {
- expect(10);
+ expect(11);
var handler = function(event) {
ok( event.data, "bind() with data, check passed data exists" );
ok( event.data.foo == "bar", "bind() with data, Check value of passed data" );
- }
+ };
$("#firstp").bind("click", {foo: "bar"}, handler).click();
reset();
ok( event.data.foo == "bar", "Check value of passed data" );
ok( data, "Check trigger data" );
ok( data.bar == "foo", "Check value of trigger data" );
- }
+ };
$("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]);
+ var handler = function(event) {
+ ok ( !event.data, "Check that no data is added to the event object" );
+ };
+ $("#firstp").unbind().bind("click", handler).trigger("click");
+
// events don't work with iframes, see #939
var tmp = document.createElement('iframe');
document.body.appendChild( tmp );
var counter = 0;
function selectOnChange(event) {
equals( event.data, counter++, "Event.data is not a global event object" );
- }
+ };
$("select").each(function(i){
$(this).bind('change', i, selectOnChange);
}).trigger('change');
ok( a == 1, "check passed data" );
ok( b == "2", "check passed data" );
ok( c == "abc", "check passed data" );
- }
+ };
$("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]);
});