Saturday, January 14, 2012

Upgrading from jQuery v1.4 to v1.5..

Apparently jQuery v1.5+ no longer allows extra data parameters. Instead, it's passed in as extra.data.
$("#mydiv").click(my_func, {'abc' : 123});  (old)
my_func = function(event) { alert(event.data); }
http://code.jquery.com/jquery-1.4.2.js
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error").split(" "), function( i, name ) {

// Handle event binding
jQuery.fn[ name ] = function( fn ) {
return fn ? this.bind( name, fn ) : this.trigger( name );
};

if ( jQuery.attrFn ) {
jQuery.attrFn[ name ] = true;
}
});
Note that the data parameter is no longer passed as an extra parameter:
http://code.jquery.com/jquery-1.7.js
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {

// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
if ( fn == null ) {
fn = data;
data = null;
}

return arguments.length > 0 ?
this.bind( name, data, fn ) :
this.trigger( name );
};

No comments:

Post a Comment