Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added in a bunch of fx fixes - and hide/show/toggle are decoupled fro…

…m later methods.
  • Loading branch information...
commit 48ec10044f011ccfe9bd232d629682b59cccbd97 1 parent a2af24b
@jeresig jeresig authored
Showing with 60 additions and 64 deletions.
  1. +3 −3 src/event/event.js
  2. +37 −25 src/fx/fx.js
  3. +20 −36 src/jquery/jquery.js
View
6 src/event/event.js
@@ -2,7 +2,7 @@ jQuery.fn.extend({
// We're overriding the old toggle function, so
// remember it for later
- //_toggle: jQuery.fn.toggle,
+ _toggle: jQuery.fn.toggle,
/**
* Toggle between two function calls every other click.
@@ -25,7 +25,7 @@ jQuery.fn.extend({
toggle: function(a,b) {
// If two functions are passed in, we're
// 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
this.last = this.last == a ? b : a;
@@ -37,7 +37,7 @@ jQuery.fn.extend({
}) :
// Otherwise, execute the old toggle function
- this._toggle();
+ this._toggle.apply( this, arguments );
},
/**
View
62 src/fx/fx.js
@@ -1,7 +1,7 @@
jQuery.fn.extend({
// overwrite the old show method
- //_show: jQuery.fn.show,
+ _show: jQuery.fn.show,
/**
* Show all matched elements using a graceful animation.
@@ -39,7 +39,7 @@ jQuery.fn.extend({
},
// Overwrite the old hide method
- //_hide: jQuery.fn.hide,
+ _hide: jQuery.fn.hide,
/**
* Hide all matched elements using a graceful animation.
@@ -261,14 +261,17 @@ jQuery.fn.extend({
*/
animate: function(prop,speed,callback) {
return this.queue(function(){
- var i = 0;
+
+ this.curAnim = 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 )
e.custom( e.cur(), prop[p] );
else
e[ prop[p] ]( prop );
}
+
});
},
@@ -328,7 +331,7 @@ jQuery.extend({
}
},
- speed: function(s,o,i) {
+ speed: function(s,o) {
o = o || {};
if ( o.constructor == Function )
@@ -344,9 +347,6 @@ jQuery.extend({
if ( o.oldComplete && o.oldComplete.constructor == Function )
o.oldComplete.apply( this );
};
-
- if ( i > 0 )
- o.complete = null;
return o;
},
@@ -405,6 +405,7 @@ jQuery.extend({
// My hate for IE will never die
} else if ( parseInt(z.now) )
y[prop] = parseInt(z.now) + "px";
+
y.display = "block";
};
@@ -454,7 +455,7 @@ jQuery.extend({
z.o.hide = true;
// 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
@@ -466,7 +467,6 @@ jQuery.extend({
z.el.oldOverflow = jQuery.css( z.el, "overflow" );
// Make sure that nothing sneaks out
- //if ( z.el.oldOverlay == "visible" )
y.overflow = "hidden";
// Each step of an animation
@@ -481,23 +481,35 @@ jQuery.extend({
z.now = lastNum;
z.a();
- // Hide the element if the "hide" operation was done
- if ( z.o.hide ) y.display = 'none';
-
- // Reset the overflow
- y.overflow = z.el.oldOverflow;
-
- // Reset the property, if the item has been hidden
- if ( z.o.hide )
- y[ prop ] = z.el.orig[ prop ].constructor == Number && prop != "opacity" ?
- z.el.orig[prop] + "px" : z.el.orig[prop];
-
- // set its height and/or width to auto
- if ( prop == 'height' || prop == 'width' )
- jQuery.setAuto( z.el, prop );
+ z.el.curAnim[ prop ] = true;
+
+ var done = true;
+ for ( var i in z.el.curAnim )
+ if ( z.el.curAnim[i] !== true )
+ done = false;
+
+ if ( done ) {
+ // Reset the overflow
+ y.overflow = z.el.oldOverflow;
+
+ // Hide the element if the "hide" operation was done
+ if ( z.o.hide )
+ 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( z.o.complete && z.o.complete.constructor == Function )
+ if( done && z.o.complete && z.o.complete.constructor == Function )
// Execute the complete function
z.o.complete.apply( z.el );
} else {
View
56 src/jquery/jquery.js
@@ -29,9 +29,6 @@ window.undefined = window.undefined;
*/
function jQuery(a,c) {
- // Initalize the extra macro functions
- if ( !jQuery.initDone ) jQuery.init();
-
// Shortcut for document ready (because $(document).each() is silly)
if ( a && a.constructor == Function && jQuery.fn.ready )
return jQuery(document).ready(a);
@@ -39,25 +36,6 @@ function jQuery(a,c) {
// Make sure that a selection was provided
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
if ( a.jquery )
return $( jQuery.merge( a, [] ) );
@@ -82,7 +60,10 @@ function jQuery(a,c) {
// Find the matching elements and save them for later
jQuery.find( a, c ) );
+ // See if an extra function was provided
var fn = arguments[ arguments.length - 1 ];
+
+ // If so, execute it in context
if ( fn && fn.constructor == Function )
this.each(fn);
}
@@ -811,8 +792,6 @@ jQuery.extend = jQuery.fn.extend = function(obj,prop) {
jQuery.extend({
/**
- *
- *
* @private
* @name init
* @type undefined
@@ -934,17 +913,21 @@ jQuery.extend({
if (jQuery.css(e,"display") != "none") {
oHeight = e.offsetHeight;
oWidth = e.offsetWidth;
- } else
- jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "block" },
- function(){
- oHeight = e.clientHeight;
- oWidth = e.clientWidth;
- });
+ } else {
+ e = $(e.cloneNode(true)).css({
+ visibility: "hidden", position: "absolute", display: "block"
+ }).prependTo("body")[0];
+
+ oHeight = e.clientHeight;
+ oWidth = e.clientWidth;
+
+ e.parentNode.removeChild(e);
+ }
});
return p == "height" ? oHeight : oWidth;
} 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 );
},
@@ -2417,7 +2400,7 @@ jQuery.macros = {
* @type jQuery
* @cat Effects
*/
- _show: function(){
+ show: function(){
this.style.display = this.oldblock ? this.oldblock : "";
if ( jQuery.css(this,"display") == "none" )
this.style.display = "block";
@@ -2440,7 +2423,7 @@ jQuery.macros = {
* @type jQuery
* @cat Effects
*/
- _hide: function(){
+ hide: function(){
this.oldblock = this.oldblock || jQuery.css(this,"display");
if ( this.oldblock == "none" )
this.oldblock = "block";
@@ -2460,9 +2443,8 @@ jQuery.macros = {
* @type jQuery
* @cat Effects
*/
- _toggle: function(){
- var d = jQuery.css(this,"display");
- $(this)[ !d || d == "none" ? "show" : "hide" ]();
+ toggle: function(){
+ $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
},
/**
@@ -2672,3 +2654,5 @@ jQuery.macros = {
}
}
};
+
+jQuery.init();
Please sign in to comment.
Something went wrong with that request. Please try again.