X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fattributes.js;h=aca9e055dbdf1e113ca5d798230fb103cd7130c2;hb=8effe3a7dee91c833cc1774646da9d743600c64c;hp=a5a6662c4f08f1607ad3cfa0a9e34047dc7a2107;hpb=2526e293538c0959597fee60976b4360390d69e0;p=jquery.git diff --git a/src/attributes.js b/src/attributes.js index a5a6662..aca9e05 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -9,17 +9,10 @@ var rclass = /[\n\t]/g, jQuery.fn.extend({ attr: function( name, value ) { - return access( this, name, value, true, jQuery.attr ); + return jQuery.access( this, name, value, true, jQuery.attr ); }, - removeAttr: function( name ) { - if ( jQuery.isFunction( name ) ) { - return this.each(function(i) { - var self = jQuery(this); - self.removeAttr( name.call(this, i, self.attr(name)) ); - }); - } - + removeAttr: function( name, fn ) { return this.each(function(){ jQuery.attr( this, name, "" ); if ( this.nodeType === 1 ) { @@ -47,12 +40,13 @@ jQuery.fn.extend({ elem.className = value; } else { - var className = " " + elem.className + " "; + var className = " " + elem.className + " ", setClass = elem.className; for ( var c = 0, cl = classNames.length; c < cl; c++ ) { if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { - elem.className += " " + classNames[c]; + setClass += " " + classNames[c]; } } + elem.className = jQuery.trim( setClass ); } } } @@ -81,7 +75,7 @@ jQuery.fn.extend({ for ( var c = 0, cl = classNames.length; c < cl; c++ ) { className = className.replace(" " + classNames[c] + " ", " "); } - elem.className = className.substring(1, className.length - 1); + elem.className = jQuery.trim( className ); } else { elem.className = ""; @@ -99,7 +93,7 @@ jQuery.fn.extend({ if ( jQuery.isFunction( value ) ) { return this.each(function(i) { var self = jQuery(this); - self.toggleClass( value.call(this, i, self.attr("class")), stateVal ); + self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal ); }); } @@ -195,28 +189,23 @@ jQuery.fn.extend({ return undefined; } - // Typecast once if the value is a number - if ( typeof value === "number" ) { - value += ""; - } - - var val = value; + var isFunction = jQuery.isFunction(value); return this.each(function(i) { - var self = jQuery(this); + var self = jQuery(this), val = value; - if ( jQuery.isFunction(value) ) { - val = value.call(this, i, self.val()); + if ( this.nodeType !== 1 ) { + return; + } - // Typecast each time if the value is a Function and the appended - // value is therefore different each time. - if ( typeof val === "number" ) { - val += ""; - } + if ( isFunction ) { + val = value.call(this, i, self.val()); } - if ( this.nodeType !== 1 ) { - return; + // Typecast each time if the value is a Function and the appended + // value is therefore different each time. + if ( typeof val === "number" ) { + val += ""; } if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) { @@ -226,7 +215,7 @@ jQuery.fn.extend({ var values = jQuery.makeArray(val); jQuery( "option", this ).each(function() { - this.selected = jQuery.inArray( self.val(), values ) >= 0; + this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; }); if ( !values.length ) { @@ -293,7 +282,7 @@ jQuery.extend({ if ( set ) { // We can't allow the type property to be changed (since it causes problems in IE) if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) { - throw "type property can't be changed"; + jQuery.error( "type property can't be changed" ); } elem[ name ] = value; @@ -342,7 +331,7 @@ jQuery.extend({ } // elem is actually elem.style ... set the style - // Using attr for specific style information is now deprecated. Use style insead. + // Using attr for specific style information is now deprecated. Use style instead. return jQuery.style( elem, name, value ); } });