X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=88930f227a4c6875b7eee5289617f57e90c2ea3b;hb=8937e088b6f06a0dbef36348aef5d7c10f3af340;hp=d21f685816b2261fb750492c6288595411d4a62f;hpb=58b8f1ddb8650ed69907abb4972064c643933479;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index d21f685..88930f2 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -1235,28 +1235,21 @@ jQuery.extend({ }, className: { - add: function(o,c){ - if (jQuery.className.has(o,c)) return; - o.className += ( o.className ? " " : "" ) + c; + add: function( elem, c ){ + if ( jQuery.className.has( elem, c ) ) + return; + elem.className += ( elem.className ? " " : "" ) + c; }, - remove: function(o,c){ - if( !c ) { - o.className = ""; - } else { - var classes = o.className.split(" "); - for(var i=0; iHello

* @result [

Hello

] * + * @example $("p").removeClass("selected") + * @before

Hello

+ * @result [

Hello

] + * * @name removeClass * @type jQuery - * @param String class A CSS class to remove from the elements + * @param String class (optional) A CSS class to remove from the elements * @cat DOM */ removeClass: function(c){ @@ -3174,12 +3188,24 @@ jQuery.macros = { * default behaviour. To stop both default action and event bubbling, your handler * has to return false. * + * In most cases, you can define your event handlers as anonymous functions + * (see first example). In cases where that is not possible, you can pass additional + * data as the second paramter (and the handler function as the third), see + * second example. + * * @example $("p").bind( "click", function() { * alert( $(this).text() ); * } ) * @before

Hello

* @result alert("Hello") * + * @example var handler = function(event) { + * alert(event.data.foo); + * }; + * $("p").bind( "click", {foo: "bar"}, handler) + * @result alert("bar") + * @desc Pass some additional data to the event handler. + * * @example $("form").bind( "submit", function() { return false; } ) * @desc Cancel a default action and prevent it from bubbling by returning false * from your function. @@ -3198,11 +3224,12 @@ jQuery.macros = { * @name bind * @type jQuery * @param String type An event type + * @param Object data (optional) Additional data passed to the event handler as event.data * @param Function fn A function to bind to the event on each of the set of matched elements * @cat Events */ - bind: function( type, fn ) { - jQuery.event.add( this, type, fn ); + bind: function( type, data, fn ) { + jQuery.event.add( this, type, fn || data, data ); }, /** @@ -3268,4 +3295,4 @@ jQuery.macros = { } }; -jQuery.init(); +jQuery.init(); \ No newline at end of file