Added in jQuery.isFunction().

This commit is contained in:
John Resig 2007-01-14 06:22:20 +00:00
parent 2bd21fe3b3
commit ed5bda3020
5 changed files with 29 additions and 25 deletions

View file

@ -44,7 +44,7 @@ jQuery.fn.extend({
* @cat Ajax * @cat Ajax
*/ */
load: function( url, params, callback, ifModified ) { load: function( url, params, callback, ifModified ) {
if ( url.constructor == Function ) if ( jQuery.isFunction( url ) )
return this.bind("load", url); return this.bind("load", url);
callback = callback || function(){}; callback = callback || function(){};
@ -55,7 +55,7 @@ jQuery.fn.extend({
// If the second parameter was provided // If the second parameter was provided
if ( params ) if ( params )
// If it's a function // If it's a function
if ( params.constructor == Function ) { if ( jQuery.isFunction( params.constructor ) ) {
// We assume that it's the callback // We assume that it's the callback
callback = params; callback = params;
params = null; params = null;
@ -273,7 +273,7 @@ jQuery.extend({
*/ */
get: function( url, data, callback, type, ifModified ) { get: function( url, data, callback, type, ifModified ) {
// shift arguments if data argument was ommited // shift arguments if data argument was ommited
if ( data && data.constructor == Function ) { if ( jQuery.isFunction( data ) ) {
callback = data; callback = data;
data = null; data = null;
} }

View file

@ -88,7 +88,7 @@ jQuery.event = {
// Trigger the event // Trigger the event
var val = element["on" + type].apply( element, data ); var val = element["on" + type].apply( element, data );
if ( val !== false && element[ type ] && element[ type ].constructor == Function ) if ( val !== false && jQuery.isFunction( element[ type ] ) )
element[ type ](); element[ type ]();
} }
}, },

View file

@ -34,7 +34,7 @@ jQuery.fn.extend({
*/ */
show: function(speed,callback){ show: function(speed,callback){
var hidden = this.filter(":hidden"); var hidden = this.filter(":hidden");
speed ? return speed ?
hidden.animate({ hidden.animate({
height: "show", width: "show", opacity: "show" height: "show", width: "show", opacity: "show"
}, speed, callback) : }, speed, callback) :
@ -44,7 +44,6 @@ jQuery.fn.extend({
if ( jQuery.css(this,"display") == "none" ) if ( jQuery.css(this,"display") == "none" )
this.style.display = "block"; this.style.display = "block";
}); });
return this;
}, },
/** /**
@ -81,7 +80,7 @@ jQuery.fn.extend({
*/ */
hide: function(speed,callback){ hide: function(speed,callback){
var visible = this.filter(":visible"); var visible = this.filter(":visible");
speed ? return speed ?
visible.animate({ visible.animate({
height: "hide", width: "hide", opacity: "hide" height: "hide", width: "hide", opacity: "hide"
}, speed, callback) : }, speed, callback) :
@ -92,7 +91,6 @@ jQuery.fn.extend({
this.oldblock = "block"; this.oldblock = "block";
this.style.display = "none"; this.style.display = "none";
}); });
return this;
}, },
// Save the old toggle function // Save the old toggle function
@ -113,7 +111,7 @@ jQuery.fn.extend({
*/ */
toggle: function( fn, fn2 ){ toggle: function( fn, fn2 ){
var args = arguments; var args = arguments;
return fn && fn.constructor == Function && fn2 && fn2.constructor == Function ? return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
this._toggle( fn, fn2 ) : this._toggle( fn, fn2 ) :
this.each(function(){ this.each(function(){
jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ] jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]
@ -359,7 +357,7 @@ jQuery.extend({
speed: function(speed, easing, fn) { speed: function(speed, easing, fn) {
var opt = speed && speed.constructor == Object ? speed : { var opt = speed && speed.constructor == Object ? speed : {
complete: fn || !fn && easing || complete: fn || !fn && easing ||
speed && speed.constructor == Function && speed, jQuery.isFunction( speed ) && speed,
duration: speed, duration: speed,
easing: fn && easing || easing && easing.constructor != Function && easing easing: fn && easing || easing && easing.constructor != Function && easing
}; };
@ -369,11 +367,11 @@ jQuery.extend({
{ slow: 600, fast: 200 }[opt.duration]) || 400; { slow: 600, fast: 200 }[opt.duration]) || 400;
// Queueing // Queueing
opt.oldComplete = opt.complete; opt.old = opt.complete;
opt.complete = function(){ opt.complete = function(){
jQuery.dequeue(this, "fx"); jQuery.dequeue(this, "fx");
if ( opt.oldComplete && opt.oldComplete.constructor == Function ) if ( jQuery.isFunction( opt.old ) )
opt.oldComplete.apply( this ); opt.old.apply( this );
}; };
return opt; return opt;
@ -411,9 +409,11 @@ jQuery.extend({
var y = elem.style; var y = elem.style;
// Store display property // Store display property
var oldDisplay = jQuery.css(elem, 'display'); var oldDisplay = jQuery.css(elem, "display");
// Set display property to block for animation // Set display property to block for animation
y.display = "block"; y.display = "block";
// Make sure that nothing sneaks out // Make sure that nothing sneaks out
y.overflow = "hidden"; y.overflow = "hidden";
@ -487,7 +487,7 @@ jQuery.extend({
// Remember where we started, so that we can go back to it later // Remember where we started, so that we can go back to it later
elem.orig[prop] = this.cur(); elem.orig[prop] = this.cur();
if(oldDisplay == 'none') { if(oldDisplay == "none") {
options.show = true; options.show = true;
// Stupid IE, look what you made me do // Stupid IE, look what you made me do
@ -525,16 +525,16 @@ jQuery.extend({
if ( done ) { if ( done ) {
// Reset the overflow // Reset the overflow
y.overflow = ''; y.overflow = "";
// Reset the display // Reset the display
y.display = oldDisplay; y.display = oldDisplay;
if (jQuery.css(elem, 'display') == 'none') if (jQuery.css(elem, "display") == "none")
y.display = 'block'; y.display = "block";
// Hide the element if the "hide" operation was done // Hide the element if the "hide" operation was done
if ( options.hide ) if ( options.hide )
y.display = 'none'; y.display = "none";
// Reset the properties, if the item has been hidden or shown // Reset the properties, if the item has been hidden or shown
if ( options.hide || options.show ) if ( options.hide || options.show )
@ -542,11 +542,11 @@ jQuery.extend({
if (p == "opacity") if (p == "opacity")
jQuery.attr(y, p, elem.orig[p]); jQuery.attr(y, p, elem.orig[p]);
else else
y[p] = ''; y[p] = "";
} }
// If a callback was provided, execute it // If a callback was provided, execute it
if ( done && options.complete && options.complete.constructor == Function ) if ( done && jQuery.isFunction( options.complete ) )
// Execute the complete function // Execute the complete function
options.complete.apply( elem ); options.complete.apply( elem );
} else { } else {

10
src/jquery/jquery.js vendored
View file

@ -33,7 +33,7 @@ var jQuery = function(a,c) {
// HANDLE: $(function) // HANDLE: $(function)
// Shortcut for document ready // Shortcut for document ready
// Safari reports typeof on DOM NodeLists as a function // Safari reports typeof on DOM NodeLists as a function
if ( typeof a == "function" && !a.nodeType && a[0] == undefined ) if ( isFunction(a) && !a.nodeType && a[0] == undefined )
return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
// Handle HTML strings // Handle HTML strings
@ -864,7 +864,7 @@ jQuery.fn = jQuery.prototype = {
*/ */
filter: function(t) { filter: function(t) {
return this.pushStack( return this.pushStack(
t.constructor == Function && isFunction( t.constructor ) &&
jQuery.grep(this, function(el, index){ jQuery.grep(this, function(el, index){
return t.apply(el, [index]) return t.apply(el, [index])
}) || }) ||
@ -1212,6 +1212,10 @@ jQuery.extend({
$ = jQuery._$; $ = jQuery._$;
}, },
isFunction: function( fn ) {
return fn && typeof fn == "function";
},
/** /**
* A generic iterator function, which can be used to seemlessly * A generic iterator function, which can be used to seemlessly
* iterate over both objects and arrays. This function is not the same * iterate over both objects and arrays. This function is not the same
@ -1253,7 +1257,7 @@ jQuery.extend({
prop: function(elem, value, type){ prop: function(elem, value, type){
// Handle executable functions // Handle executable functions
if ( value.constructor == Function ) if ( isFunction( value ) )
return value.call( elem ); return value.call( elem );
// Handle passing in a number to a CSS property // Handle passing in a number to a CSS property

View file

@ -172,7 +172,7 @@ jQuery.extend({
// If the token match was found // If the token match was found
if ( m ) { if ( m ) {
// Map it against the token's handler // Map it against the token's handler
r = ret = jQuery.map( ret, jQuery.token[i+1].constructor == Function ? r = ret = jQuery.map( ret, jQuery.isFunction( jQuery.token[i+1] ) ?
jQuery.token[i+1] : jQuery.token[i+1] :
function(a){ return eval(jQuery.token[i+1]); }); function(a){ return eval(jQuery.token[i+1]); });