git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Found a better detect for deleting an expando, added back in removeAttribute as it...
[jquery.git]
/
src
/
attributes.js
diff --git
a/src/attributes.js
b/src/attributes.js
index
664a024
..
3e4c5f2
100644
(file)
--- a/
src/attributes.js
+++ b/
src/attributes.js
@@
-12,14
+12,7
@@
jQuery.fn.extend({
return access( this, name, value, true, jQuery.attr );
},
return 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 ) {
return this.each(function(){
jQuery.attr( this, name, "" );
if ( this.nodeType === 1 ) {
@@
-50,7
+43,7
@@
jQuery.fn.extend({
var className = " " + elem.className + " ";
for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
var className = " " + elem.className + " ";
for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
- elem.className += " " + classNames[c];
+ elem.className = jQuery.trim( elem.className + " " + classNames[c] );
}
}
}
}
}
}
@@
-81,7
+74,7
@@
jQuery.fn.extend({
for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
className = className.replace(" " + classNames[c] + " ", " ");
}
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 = "";
} else {
elem.className = "";
@@
-93,26
+86,27
@@
jQuery.fn.extend({
return this;
},
return this;
},
- toggleClass: function( classNames, state ) {
- var type = typeof classNames;
+ toggleClass: function( value, stateVal ) {
+ var type = typeof value, isBool = typeof stateVal === "boolean";
- if ( jQuery.isFunction( classNames ) ) {
+ if ( jQuery.isFunction( value ) ) {
return this.each(function(i) {
var self = jQuery(this);
return this.each(function(i) {
var self = jQuery(this);
- self.toggleClass( classNames.call(this, i, self.attr("class")), state );
+ self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
});
}
});
}
- return this.each(function(){
+ return this.each(function() {
if ( type === "string" ) {
// toggle individual class names
if ( type === "string" ) {
// toggle individual class names
- var isBool = typeof state === "boolean", className, i = 0,
- classNames = classNames.split( rspace );
+ var className, i = 0, self = jQuery(this),
+ state = stateVal,
+ classNames = value.split( rspace );
while ( (className = classNames[ i++ ]) ) {
// check each className given, space seperated list
while ( (className = classNames[ i++ ]) ) {
// check each className given, space seperated list
- state = isBool ? state : !jQuery(this).hasClass( className );
- jQuery(this)[ state ? "addClass" : "removeClass" ]( className );
+ state = isBool ? state : !self.hasClass( className );
+ self[ state ? "addClass" : "removeClass" ]( className );
}
} else if ( type === "undefined" || type === "boolean" ) {
}
} else if ( type === "undefined" || type === "boolean" ) {
@@
-122,7
+116,7
@@
jQuery.fn.extend({
}
// toggle whole className
}
// toggle whole className
- this.className = this.className || classNames === false ? "" : jQuery.data( this, "__className__" ) || "";
+ this.className = this.className || value === false ? "" : jQuery.data( this, "__className__" ) || "";
}
});
},
}
});
},
@@
-194,28
+188,23
@@
jQuery.fn.extend({
return undefined;
}
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) {
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 ) ) {
}
if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) {
@@
-225,7
+214,7
@@
jQuery.fn.extend({
var values = jQuery.makeArray(val);
jQuery( "option", this ).each(function() {
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 ) {
});
if ( !values.length ) {
@@
-292,7
+281,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 ) {
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;
}
elem[ name ] = value;
@@
-341,7
+330,7
@@
jQuery.extend({
}
// elem is actually elem.style ... set the style
}
// 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 );
}
});
return jQuery.style( elem, name, value );
}
});