X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=7b712c955583cb26c0c0d0a72f96eb63ac155257;hb=65a88fae8919e5da774dcc45c9b42220f875b697;hp=4e9f4aca0f93b8974076104c3116b47c9e5b901f;hpb=a960b2d3b50bd4077b646d020ef0ec3cd7328b88;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 4e9f4ac..7b712c9 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -510,9 +510,9 @@ jQuery.fn = jQuery.prototype = { e = e || this; var t = ""; - for ( var j = 0; j < e.length; j++ ) { + for ( var j = 0, el = e.length; j < el; j++ ) { var r = e[j].childNodes; - for ( var i = 0; i < r.length; i++ ) + for ( var i = 0, rl = r.length; i < rl; i++ ) if ( r[i].nodeType != 8 ) t += r[i].nodeType != 1 ? r[i].nodeValue : jQuery.fn.text([ r[i] ]); @@ -882,7 +882,7 @@ jQuery.fn = jQuery.prototype = { return this.pushStack( t.constructor == Array && jQuery.map(this,function(a){ - for ( var i = 0; i < t.length; i++ ) + for ( var i = 0, tl = t.length; i < tl; i++ ) if ( jQuery.filter(t[i],[a]).r.length ) return a; return null; @@ -1030,7 +1030,7 @@ jQuery.fn = jQuery.prototype = { if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" ) obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody")); - for ( var i=0; i < a.length; i++ ) + for ( var i = 0, al = a.length; i < al; i++ ) fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] ); }); @@ -1164,7 +1164,7 @@ jQuery.extend({ jQuery.fn[ i ] = function(){ var a = arguments; return this.each(function(){ - for ( var j = 0; j < a.length; j++ ) + for ( var j = 0, al = a.length; j < al; j++ ) jQuery(a[j])[n]( this ); }); }; @@ -1229,34 +1229,26 @@ jQuery.extend({ for ( var i in obj ) fn.apply( obj[i], args || [i, obj[i]] ); else - for ( var i = 0; i < obj.length; i++ ) + for ( var i = 0, ol = obj.length; i < ol; i++ ) if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break; return obj; }, className: { - add: function(o,c){ - if (jQuery.className.has(o,c)) return; - o.className += ( o.className ? " " : "" ) + c; + add: function( elem, c ){ + jQuery.each( c.split(/\s+/), function(i, cur){ + if ( !jQuery.className.has( elem.className, cur ) ) + elem.className += ( elem.className ? " " : "" ) + cur; + }); }, - 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 +3187,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 +3223,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 +3294,4 @@ jQuery.macros = { } }; -jQuery.init(); +jQuery.init(); \ No newline at end of file