Added in a bunch of fx fixes - and hide/show/toggle are decoupled from later methods.

This commit is contained in:
John Resig 2006-08-26 03:51:03 +00:00
parent a2af24b064
commit 48ec10044f
3 changed files with 59 additions and 63 deletions

View file

@ -2,7 +2,7 @@ jQuery.fn.extend({
// We're overriding the old toggle function, so // We're overriding the old toggle function, so
// remember it for later // remember it for later
//_toggle: jQuery.fn.toggle, _toggle: jQuery.fn.toggle,
/** /**
* Toggle between two function calls every other click. * Toggle between two function calls every other click.
@ -25,7 +25,7 @@ jQuery.fn.extend({
toggle: function(a,b) { toggle: function(a,b) {
// If two functions are passed in, we're // If two functions are passed in, we're
// toggling on a click // toggling on a click
return a && b ? this.click(function(e){ return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){
// Figure out which function to execute // Figure out which function to execute
this.last = this.last == a ? b : a; this.last = this.last == a ? b : a;
@ -37,7 +37,7 @@ jQuery.fn.extend({
}) : }) :
// Otherwise, execute the old toggle function // Otherwise, execute the old toggle function
this._toggle(); this._toggle.apply( this, arguments );
}, },
/** /**

View file

@ -1,7 +1,7 @@
jQuery.fn.extend({ jQuery.fn.extend({
// overwrite the old show method // overwrite the old show method
//_show: jQuery.fn.show, _show: jQuery.fn.show,
/** /**
* Show all matched elements using a graceful animation. * Show all matched elements using a graceful animation.
@ -39,7 +39,7 @@ jQuery.fn.extend({
}, },
// Overwrite the old hide method // Overwrite the old hide method
//_hide: jQuery.fn.hide, _hide: jQuery.fn.hide,
/** /**
* Hide all matched elements using a graceful animation. * Hide all matched elements using a graceful animation.
@ -261,14 +261,17 @@ jQuery.fn.extend({
*/ */
animate: function(prop,speed,callback) { animate: function(prop,speed,callback) {
return this.queue(function(){ return this.queue(function(){
var i = 0;
this.curAnim = prop;
for ( var p in prop ) { for ( var p in prop ) {
var e = new jQuery.fx( this, jQuery.speed(speed,callback,i++), p ); var e = new jQuery.fx( this, jQuery.speed(speed,callback), p );
if ( prop[p].constructor == Number ) if ( prop[p].constructor == Number )
e.custom( e.cur(), prop[p] ); e.custom( e.cur(), prop[p] );
else else
e[ prop[p] ]( prop ); e[ prop[p] ]( prop );
} }
}); });
}, },
@ -328,7 +331,7 @@ jQuery.extend({
} }
}, },
speed: function(s,o,i) { speed: function(s,o) {
o = o || {}; o = o || {};
if ( o.constructor == Function ) if ( o.constructor == Function )
@ -345,9 +348,6 @@ jQuery.extend({
o.oldComplete.apply( this ); o.oldComplete.apply( this );
}; };
if ( i > 0 )
o.complete = null;
return o; return o;
}, },
@ -405,6 +405,7 @@ jQuery.extend({
// My hate for IE will never die // My hate for IE will never die
} else if ( parseInt(z.now) ) } else if ( parseInt(z.now) )
y[prop] = parseInt(z.now) + "px"; y[prop] = parseInt(z.now) + "px";
y.display = "block"; y.display = "block";
}; };
@ -454,7 +455,7 @@ jQuery.extend({
z.o.hide = true; z.o.hide = true;
// Begin the animation // Begin the animation
z.custom(z.cur(),0); z.custom(z.el.orig[prop], 0);
}; };
// IE has trouble with opacity if it does not have layout // IE has trouble with opacity if it does not have layout
@ -466,7 +467,6 @@ jQuery.extend({
z.el.oldOverflow = jQuery.css( z.el, "overflow" ); z.el.oldOverflow = jQuery.css( z.el, "overflow" );
// Make sure that nothing sneaks out // Make sure that nothing sneaks out
//if ( z.el.oldOverlay == "visible" )
y.overflow = "hidden"; y.overflow = "hidden";
// Each step of an animation // Each step of an animation
@ -481,23 +481,35 @@ jQuery.extend({
z.now = lastNum; z.now = lastNum;
z.a(); z.a();
// Hide the element if the "hide" operation was done z.el.curAnim[ prop ] = true;
if ( z.o.hide ) y.display = 'none';
// Reset the overflow var done = true;
y.overflow = z.el.oldOverflow; for ( var i in z.el.curAnim )
if ( z.el.curAnim[i] !== true )
done = false;
// Reset the property, if the item has been hidden if ( done ) {
if ( z.o.hide ) // Reset the overflow
y[ prop ] = z.el.orig[ prop ].constructor == Number && prop != "opacity" ? y.overflow = z.el.oldOverflow;
z.el.orig[prop] + "px" : z.el.orig[prop];
// set its height and/or width to auto // Hide the element if the "hide" operation was done
if ( prop == 'height' || prop == 'width' ) if ( z.o.hide )
jQuery.setAuto( z.el, prop ); y.display = 'none';
// Reset the property, if the item has been hidden
if ( z.o.hide ) {
for ( var p in z.el.curAnim ) {
y[ p ] = z.el.orig[p] + ( p == "opacity" ? "" : "px" );
// set its height and/or width to auto
if ( p == 'height' || p == 'width' )
jQuery.setAuto( z.el, p );
}
}
}
// If a callback was provided, execute it // If a callback was provided, execute it
if( z.o.complete && z.o.complete.constructor == Function ) if( done && z.o.complete && z.o.complete.constructor == Function )
// Execute the complete function // Execute the complete function
z.o.complete.apply( z.el ); z.o.complete.apply( z.el );
} else { } else {

56
src/jquery/jquery.js vendored
View file

@ -29,9 +29,6 @@ window.undefined = window.undefined;
*/ */
function jQuery(a,c) { function jQuery(a,c) {
// Initalize the extra macro functions
if ( !jQuery.initDone ) jQuery.init();
// Shortcut for document ready (because $(document).each() is silly) // Shortcut for document ready (because $(document).each() is silly)
if ( a && a.constructor == Function && jQuery.fn.ready ) if ( a && a.constructor == Function && jQuery.fn.ready )
return jQuery(document).ready(a); return jQuery(document).ready(a);
@ -39,25 +36,6 @@ function jQuery(a,c) {
// Make sure that a selection was provided // Make sure that a selection was provided
a = a || jQuery.context || document; a = a || jQuery.context || document;
/*
* Handle support for overriding other $() functions. Way too many libraries
* provide this function to simply ignore it and overwrite it.
*/
/*
// Check to see if this is a possible collision case
if ( jQuery._$ && !c && a.constructor == String &&
// Make sure that the expression is a colliding one
!/[^a-zA-Z0-9_-]/.test(a) &&
// and that there are no elements that match it
// (this is the one truly ambiguous case)
!document.getElementsByTagName(a).length )
// Use the default method, in case it works some voodoo
return jQuery._$( a );
*/
// Watch for when a jQuery object is passed as the selector // Watch for when a jQuery object is passed as the selector
if ( a.jquery ) if ( a.jquery )
return $( jQuery.merge( a, [] ) ); return $( jQuery.merge( a, [] ) );
@ -82,7 +60,10 @@ function jQuery(a,c) {
// Find the matching elements and save them for later // Find the matching elements and save them for later
jQuery.find( a, c ) ); jQuery.find( a, c ) );
// See if an extra function was provided
var fn = arguments[ arguments.length - 1 ]; var fn = arguments[ arguments.length - 1 ];
// If so, execute it in context
if ( fn && fn.constructor == Function ) if ( fn && fn.constructor == Function )
this.each(fn); this.each(fn);
} }
@ -811,8 +792,6 @@ jQuery.extend = jQuery.fn.extend = function(obj,prop) {
jQuery.extend({ jQuery.extend({
/** /**
*
*
* @private * @private
* @name init * @name init
* @type undefined * @type undefined
@ -934,17 +913,21 @@ jQuery.extend({
if (jQuery.css(e,"display") != "none") { if (jQuery.css(e,"display") != "none") {
oHeight = e.offsetHeight; oHeight = e.offsetHeight;
oWidth = e.offsetWidth; oWidth = e.offsetWidth;
} else } else {
jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "block" }, e = $(e.cloneNode(true)).css({
function(){ visibility: "hidden", position: "absolute", display: "block"
oHeight = e.clientHeight; }).prependTo("body")[0];
oWidth = e.clientWidth;
}); oHeight = e.clientHeight;
oWidth = e.clientWidth;
e.parentNode.removeChild(e);
}
}); });
return p == "height" ? oHeight : oWidth; return p == "height" ? oHeight : oWidth;
} else if ( p == "opacity" && jQuery.browser.msie ) } else if ( p == "opacity" && jQuery.browser.msie )
return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1; return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
return jQuery.curCSS( e, p ); return jQuery.curCSS( e, p );
}, },
@ -2417,7 +2400,7 @@ jQuery.macros = {
* @type jQuery * @type jQuery
* @cat Effects * @cat Effects
*/ */
_show: function(){ show: function(){
this.style.display = this.oldblock ? this.oldblock : ""; this.style.display = this.oldblock ? this.oldblock : "";
if ( jQuery.css(this,"display") == "none" ) if ( jQuery.css(this,"display") == "none" )
this.style.display = "block"; this.style.display = "block";
@ -2440,7 +2423,7 @@ jQuery.macros = {
* @type jQuery * @type jQuery
* @cat Effects * @cat Effects
*/ */
_hide: function(){ hide: function(){
this.oldblock = this.oldblock || jQuery.css(this,"display"); this.oldblock = this.oldblock || jQuery.css(this,"display");
if ( this.oldblock == "none" ) if ( this.oldblock == "none" )
this.oldblock = "block"; this.oldblock = "block";
@ -2460,9 +2443,8 @@ jQuery.macros = {
* @type jQuery * @type jQuery
* @cat Effects * @cat Effects
*/ */
_toggle: function(){ toggle: function(){
var d = jQuery.css(this,"display"); $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
$(this)[ !d || d == "none" ? "show" : "hide" ]();
}, },
/** /**
@ -2672,3 +2654,5 @@ jQuery.macros = {
} }
} }
}; };
jQuery.init();