Merge branch 'setterargs'
This commit is contained in:
commit
d6d5ed4c68
8 changed files with 654 additions and 264 deletions
|
@ -12,10 +12,20 @@ jQuery.fn.extend({
|
|||
return access( this, name, value, true, jQuery.attr );
|
||||
},
|
||||
|
||||
removeAttr: function( name, fn ) {
|
||||
return this.each(function(){
|
||||
jQuery.attr( this, name, "" );
|
||||
if ( this.nodeType === 1 ) {
|
||||
this.removeAttribute( name );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addClass: function( value ) {
|
||||
if ( jQuery.isFunction(value) ) {
|
||||
return this.each(function() {
|
||||
jQuery(this).addClass( value.call(this) );
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
self.addClass( value.call(this, i, self.attr("class")) );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -46,8 +56,9 @@ jQuery.fn.extend({
|
|||
|
||||
removeClass: function( value ) {
|
||||
if ( jQuery.isFunction(value) ) {
|
||||
return this.each(function() {
|
||||
jQuery(this).removeClass( value.call(this) );
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
self.removeClass( value.call(this, i, self.attr("class")) );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -75,6 +86,41 @@ jQuery.fn.extend({
|
|||
return this;
|
||||
},
|
||||
|
||||
toggleClass: function( value, stateVal ) {
|
||||
var type = typeof value, isBool = typeof stateVal === "boolean";
|
||||
|
||||
if ( jQuery.isFunction( value ) ) {
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
|
||||
});
|
||||
}
|
||||
|
||||
return this.each(function() {
|
||||
if ( type === "string" ) {
|
||||
// toggle individual class names
|
||||
var className, i = 0, self = jQuery(this),
|
||||
state = stateVal,
|
||||
classNames = value.split( rspace );
|
||||
|
||||
while ( (className = classNames[ i++ ]) ) {
|
||||
// check each className given, space seperated list
|
||||
state = isBool ? state : !self.hasClass( className );
|
||||
self[ state ? "addClass" : "removeClass" ]( className );
|
||||
}
|
||||
|
||||
} else if ( type === "undefined" || type === "boolean" ) {
|
||||
if ( this.className ) {
|
||||
// store className if set
|
||||
jQuery.data( this, "__className__", this.className );
|
||||
}
|
||||
|
||||
// toggle whole className
|
||||
this.className = this.className || value === false ? "" : jQuery.data( this, "__className__" ) || "";
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
hasClass: function( selector ) {
|
||||
var className = " " + selector + " ";
|
||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||
|
@ -142,30 +188,27 @@ jQuery.fn.extend({
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Typecast once if the value is a number
|
||||
if ( typeof value === "number" ) {
|
||||
value += "";
|
||||
}
|
||||
var isFunction = jQuery.isFunction(value);
|
||||
|
||||
var val = value;
|
||||
|
||||
return this.each(function() {
|
||||
if ( jQuery.isFunction(value) ) {
|
||||
val = value.call(this);
|
||||
|
||||
// Typecast each time if the value is a Function and the appended
|
||||
// value is therefore different each time.
|
||||
if ( typeof val === "number" ) {
|
||||
val += "";
|
||||
}
|
||||
}
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this), val = value;
|
||||
|
||||
if ( this.nodeType !== 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isFunction ) {
|
||||
val = value.call(this, i, self.val());
|
||||
}
|
||||
|
||||
// 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 ) ) {
|
||||
this.checked = jQuery.inArray( jQuery(this).val(), val ) >= 0;
|
||||
this.checked = jQuery.inArray( self.val(), val ) >= 0;
|
||||
|
||||
} else if ( jQuery.nodeName( this, "select" ) ) {
|
||||
var values = jQuery.makeArray(val);
|
||||
|
@ -185,50 +228,6 @@ jQuery.fn.extend({
|
|||
}
|
||||
});
|
||||
|
||||
jQuery.each({
|
||||
removeAttr: function( name ) {
|
||||
jQuery.attr( this, name, "" );
|
||||
if ( this.nodeType === 1 ) {
|
||||
this.removeAttribute( name );
|
||||
}
|
||||
},
|
||||
|
||||
toggleClass: function( classNames, state ) {
|
||||
var type = typeof classNames;
|
||||
|
||||
if ( type === "string" ) {
|
||||
// toggle individual class names
|
||||
var isBool = typeof state === "boolean", className, i = 0,
|
||||
classNames = classNames.split( rspace );
|
||||
|
||||
while ( (className = classNames[ i++ ]) ) {
|
||||
// check each className given, space seperated list
|
||||
state = isBool ? state : !jQuery(this).hasClass( className );
|
||||
jQuery(this)[ state ? "addClass" : "removeClass" ]( className );
|
||||
}
|
||||
|
||||
} else if ( type === "undefined" || type === "boolean" ) {
|
||||
if ( this.className ) {
|
||||
// store className if set
|
||||
jQuery.data( this, "__className__", this.className );
|
||||
}
|
||||
|
||||
// toggle whole className
|
||||
this.className = this.className || classNames === false ? "" : jQuery.data( this, "__className__" ) || "";
|
||||
}
|
||||
}
|
||||
}, function( name, fn ) {
|
||||
jQuery.fn[ name ] = function( val, state ) {
|
||||
if ( jQuery.isFunction( val ) ) {
|
||||
return this.each(function() {
|
||||
jQuery(this)[ name ]( val.call(this), state );
|
||||
});
|
||||
}
|
||||
|
||||
return this.each( fn, arguments );
|
||||
};
|
||||
});
|
||||
|
||||
jQuery.extend({
|
||||
attrFn: {
|
||||
val: true,
|
||||
|
|
|
@ -775,7 +775,7 @@ function access( elems, key, value, exec, fn, pass ) {
|
|||
exec = exec && jQuery.isFunction(value);
|
||||
|
||||
for ( var i = 0; i < length; i++ ) {
|
||||
fn( elems[i], key, exec ? value.call( elems[i], i ) : value, pass );
|
||||
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
|
||||
}
|
||||
|
||||
return elems;
|
||||
|
|
|
@ -33,8 +33,9 @@ if ( !jQuery.support.htmlSerialize ) {
|
|||
jQuery.fn.extend({
|
||||
text: function( text ) {
|
||||
if ( jQuery.isFunction(text) ) {
|
||||
return this.each(function() {
|
||||
return jQuery(this).text( text.call(this) );
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
return self.text( text.call(this, i, self.text()) );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -47,8 +48,8 @@ jQuery.fn.extend({
|
|||
|
||||
wrapAll: function( html ) {
|
||||
if ( jQuery.isFunction( html ) ) {
|
||||
return this.each(function() {
|
||||
jQuery(this).wrapAll( html.apply(this, arguments) );
|
||||
return this.each(function(i) {
|
||||
jQuery(this).wrapAll( html.call(this, i) );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -172,7 +173,7 @@ jQuery.fn.extend({
|
|||
|
||||
html: function( value ) {
|
||||
if ( value === undefined ) {
|
||||
return this[0] ?
|
||||
return this[0] && this[0].nodeType === 1 ?
|
||||
this[0].innerHTML.replace(rinlinejQuery, "") :
|
||||
null;
|
||||
|
||||
|
@ -195,6 +196,14 @@ jQuery.fn.extend({
|
|||
this.empty().append( value );
|
||||
}
|
||||
|
||||
} else if ( jQuery.isFunction( value ) ) {
|
||||
this.each(function(i){
|
||||
var self = jQuery(this), old = self.html();
|
||||
self.empty().append(function(){
|
||||
return value.call( this, i, old );
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
this.empty().append( value );
|
||||
}
|
||||
|
@ -228,9 +237,10 @@ jQuery.fn.extend({
|
|||
var results, first, value = args[0], scripts = [];
|
||||
|
||||
if ( jQuery.isFunction(value) ) {
|
||||
return this.each(function() {
|
||||
args[0] = value.call(this);
|
||||
return jQuery(this).domManip( args, table, callback );
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
args[0] = value.call(this, i, table ? self.html() : undefined);
|
||||
return self.domManip( args, table, callback );
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ if ( "getBoundingClientRect" in document.documentElement ) {
|
|||
}
|
||||
|
||||
if ( options ) {
|
||||
return this.each(function() {
|
||||
jQuery.offset.setOffset( this, options );
|
||||
return this.each(function( i ) {
|
||||
jQuery.offset.setOffset( this, options, i );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ if ( "getBoundingClientRect" in document.documentElement ) {
|
|||
}
|
||||
|
||||
if ( options ) {
|
||||
return this.each(function() {
|
||||
jQuery.offset.setOffset( this, options );
|
||||
return this.each(function( i ) {
|
||||
jQuery.offset.setOffset( this, options, i );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ jQuery.offset = {
|
|||
return { top: top, left: left };
|
||||
},
|
||||
|
||||
setOffset: function( elem, options ) {
|
||||
setOffset: function( elem, options, i ) {
|
||||
// set position first, in-case top/left are set even on static elem
|
||||
if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) {
|
||||
elem.style.position = "relative";
|
||||
|
@ -145,11 +145,16 @@ jQuery.offset = {
|
|||
var curElem = jQuery( elem ),
|
||||
curOffset = curElem.offset(),
|
||||
curTop = parseInt( jQuery.curCSS( elem, "top", true ), 10 ) || 0,
|
||||
curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10) || 0,
|
||||
props = {
|
||||
top: (options.top - curOffset.top) + curTop,
|
||||
left: (options.left - curOffset.left) + curLeft
|
||||
};
|
||||
curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0;
|
||||
|
||||
if ( jQuery.isFunction( options ) ) {
|
||||
options = options.call( elem, i, curOffset );
|
||||
}
|
||||
|
||||
var props = {
|
||||
top: (options.top - curOffset.top) + curTop,
|
||||
left: (options.left - curOffset.left) + curLeft
|
||||
};
|
||||
|
||||
if ( "using" in options ) {
|
||||
options.using.call( elem, props );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue