Skip to content
Permalink
Browse files

Merge branch 'master' of github.com:jquery/jquery

  • Loading branch information...
dmethvin committed Apr 7, 2011
2 parents 14193e4 + 6832595 commit c470db6950d05644fa9d99e79ce0b2bc3c6235a1
Showing with 535 additions and 319 deletions.
  1. +10 −17 src/core.js
  2. +30 −2 src/deferred.js
  3. +14 −3 src/effects.js
  4. +44 −1 src/queue.js
  5. +142 −152 src/support.js
  6. +20 −0 test/unit/core.js
  7. +252 −126 test/unit/deferred.js
  8. +23 −18 test/unit/effects.js
@@ -565,24 +565,17 @@ jQuery.extend({

noop: function() {},

// Evalulates a script in a global context
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
if ( data && rnotwhite.test(data) ) {
// Inspired by code by Andrea Giammarchi
// http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
script = document.createElement( "script" );

if ( jQuery.support.scriptEval() ) {
script.appendChild( document.createTextNode( data ) );
} else {
script.text = data;
}

// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709).
head.insertBefore( script, head.firstChild );
head.removeChild( script );
if ( data && rnotwhite.test( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
} )( data );
}
},

@@ -1,7 +1,7 @@
(function( jQuery ) {

var // Promise methods
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
promiseMethods = "done fail isResolved isRejected promise then always chain".split( " " ),
// Static reference to slice
sliceDeferred = [].slice;

@@ -100,10 +100,38 @@ jQuery.extend({
deferred.done( doneCallbacks ).fail( failCallbacks );
return this;
},
always: function() {
return deferred.done.apply( deferred, arguments ).fail.apply( this, arguments );
},
fail: failDeferred.done,
rejectWith: failDeferred.resolveWith,
reject: failDeferred.resolve,
isRejected: failDeferred.isResolved,
// Chain
chain: function( fnDone, fnFail ) {
return jQuery.Deferred(function( newDefer ) {
jQuery.each( {
done: [ fnDone, "resolve" ],
fail: [ fnFail, "reject" ]
}, function( handler, data ) {
var fn = data[ 0 ],
action = data[ 1 ],
returned;
if ( jQuery.isFunction( fn ) ) {
deferred[ handler ](function() {
returned = fn.apply( this, arguments );
if ( jQuery.isFunction( returned.promise ) ) {
returned.promise().then( newDefer.resolve, newDefer.reject );
} else {
newDefer[ action ]( returned );
}
});
} else {
deferred[ handler ]( newDefer[ action ] );
}
} );
}).promise();
},
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
@@ -169,4 +197,4 @@ jQuery.extend({
}
});

})( jQuery );
})( jQuery );
@@ -11,7 +11,17 @@ var elemdisplay = {},
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
// opacity animations
[ "opacity" ]
];
],
fxNow;

function clearFxNow() {
fxNow = undefined;
}

function createFxNow() {
setTimeout( clearFxNow, 0 );
return ( fxNow = jQuery.now() );
}

jQuery.fn.extend({
show: function( speed, easing, callback ) {
@@ -349,7 +359,7 @@ jQuery.fx.prototype = {
var self = this,
fx = jQuery.fx;

this.startTime = jQuery.now();
this.startTime = fxNow || createFxNow();
this.start = from;
this.end = to;
this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
@@ -394,7 +404,8 @@ jQuery.fx.prototype = {

// Each step of an animation
step: function( gotoEnd ) {
var t = jQuery.now(), done = true;
var t = fxNow || createFxNow(),
done = true;

if ( gotoEnd || t >= this.options.duration + this.startTime ) {
this.now = this.end;
@@ -28,7 +28,8 @@ jQuery.extend({
type = type || "fx";

var queue = jQuery.queue( elem, type ),
fn = queue.shift();
fn = queue.shift(),
defer;

// If the fx queue is dequeued, always remove the progress sentinel
if ( fn === "inprogress" ) {
@@ -49,6 +50,17 @@ jQuery.extend({

if ( !queue.length ) {
jQuery.removeData( elem, type + "queue", true );
// Look if we have observers and resolve if needed
if (( defer = jQuery.data( elem, type + "defer", undefined, true ) )) {
// Give room for hard-coded callbacks to fire first
// and eventually add another animation on the element
setTimeout( function() {
if ( !jQuery.data( elem, type + "queue", undefined, true ) ) {
jQuery.removeData( elem, type + "defer", true );
defer.resolve();
}
}, 0 );
}
}
}
});
@@ -93,6 +105,37 @@ jQuery.fn.extend({

clearQueue: function( type ) {
return this.queue( type || "fx", [] );
},

// Get a promise resolved when queues of a certain type
// are emptied (fx is the type by default)
promise: function( type, object ) {
if ( typeof type !== "string" ) {
object = type;
type = undefined;
}
type = type || "fx";
var defer = jQuery.Deferred(),
elements = this,
i = elements.length,
count = 1,
deferDataKey = type + "defer",
queueDataKey = type + "queue";
function resolve() {
if ( !( --count ) ) {
defer.resolveWith( elements, [ elements ] );
}
}
while( i-- ) {
if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
jQuery.data( elements[ i ], queueDataKey, undefined, true ) &&
jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
count++;
tmp.done( resolve );
}
}
resolve();
return defer.promise();
}
});

0 comments on commit c470db6

Please sign in to comment.
You can’t perform that action at this time.