From 51aa9c5f3260c54609d633b5fada0f6ed56d26fd Mon Sep 17 00:00:00 2001 From: timmywil Date: Sat, 28 May 2011 21:39:34 -0400 Subject: [PATCH 01/26] Style edits, code reductions, and optimizations for the effects module --- src/effects.js | 87 +++++++++++++++++++++++++------------------------- src/queue.js | 22 +++++++------ 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/effects.js b/src/effects.js index 22496277..88986af7 100644 --- a/src/effects.js +++ b/src/effects.js @@ -120,7 +120,7 @@ jQuery.fn.extend({ }, animate: function( prop, speed, easing, callback ) { - var optall = jQuery.speed(speed, easing, callback); + var optall = jQuery.speed( speed, easing, callback ); if ( jQuery.isEmptyObject( prop ) ) { return this.each( optall.complete, [ false ] ); @@ -140,8 +140,7 @@ jQuery.fn.extend({ var opt = jQuery.extend( {}, optall ), isElement = this.nodeType === 1, hidden = isElement && jQuery(this).is(":hidden"), - name, val, p, - display, e, + name, val, p, e, parts, start, end, unit; // will store per property easing and be used to determine when an animation is complete @@ -182,21 +181,14 @@ jQuery.fn.extend({ // animated if ( jQuery.css( this, "display" ) === "inline" && jQuery.css( this, "float" ) === "none" ) { - if ( !jQuery.support.inlineBlockNeedsLayout ) { + + // inline-level elements accept inline-block; + // block-level elements need to be inline with layout + if ( !jQuery.support.inlineBlockNeedsLayout || defaultDisplay( this.nodeName ) === "inline" ) { this.style.display = "inline-block"; } else { - display = defaultDisplay( this.nodeName ); - - // inline-level elements accept inline-block; - // block-level elements need to be inline with layout - if ( display === "inline" ) { - this.style.display = "inline-block"; - - } else { - this.style.display = "inline"; - this.style.zoom = 1; - } + this.style.zoom = 1; } } } @@ -210,7 +202,7 @@ jQuery.fn.extend({ e = new jQuery.fx( this, opt, p ); val = prop[ p ]; - if ( rfxtypes.test(val) ) { + if ( rfxtypes.test( val ) ) { e[ val === "toggle" ? hidden ? "show" : "hide" : val ](); } else { @@ -259,10 +251,10 @@ jQuery.fn.extend({ jQuery._unmark( true, this ); } while ( i-- ) { - if ( timers[i].elem === this ) { - if (gotoEnd) { + if ( timers[ i ].elem === this ) { + if ( gotoEnd ) { // force the next step to be the last - timers[i](true); + timers[ i ]( true ); } timers.splice(i, 1); @@ -294,7 +286,7 @@ function clearFxNow() { function genFx( type, num ) { var obj = {}; - jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() { + jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice( 0, num )), function() { obj[ this ] = type; }); @@ -303,9 +295,9 @@ function genFx( type, num ) { // Generate shortcuts for custom animations jQuery.each({ - slideDown: genFx("show", 1), - slideUp: genFx("hide", 1), - slideToggle: genFx("toggle", 1), + slideDown: genFx( "show", 1 ), + slideUp: genFx( "hide", 1 ), + slideToggle: genFx( "toggle", 1 ), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" }, fadeToggle: { opacity: "toggle" } @@ -317,15 +309,15 @@ jQuery.each({ jQuery.extend({ speed: function( speed, easing, fn ) { - var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : { + var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : { complete: fn || !fn && easing || jQuery.isFunction( speed ) && speed, duration: speed, - easing: fn && easing || easing && !jQuery.isFunction(easing) && easing + easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing }; opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration : - opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default; + opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default; // Queueing opt.old = opt.complete; @@ -372,12 +364,12 @@ jQuery.fx.prototype = { this.options.step.call( this.elem, this.now, this ); } - (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this ); + (jQuery.fx.step[ this.prop ] || jQuery.fx.step._default)( this ); }, // Get the current size cur: function() { - if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) { + if ( this.elem[ this.prop ] != null && (!this.elem.style || this.elem.style[ this.prop ] == null) ) { return this.elem[ this.prop ]; } @@ -396,14 +388,13 @@ jQuery.fx.prototype = { raf; this.startTime = fxNow || createFxNow(); - this.start = from; this.end = to; - this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" ); - this.now = this.start; + this.now = this.start = from; this.pos = this.state = 0; + this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" ); function t( gotoEnd ) { - return self.step(gotoEnd); + return self.step( gotoEnd ); } t.elem = this.elem; @@ -429,13 +420,13 @@ jQuery.fx.prototype = { // Simple 'show' function show: function() { // Remember where we started, so that we can go back to it later - this.options.orig[this.prop] = jQuery.style( this.elem, this.prop ); + this.options.orig[ this.prop ] = jQuery.style( this.elem, this.prop ); this.options.show = true; // Begin the animation // Make sure that we start at a small width/height to avoid any // flash of content - this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur()); + this.custom( this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur() ); // Start by showing the element jQuery( this.elem ).show(); @@ -444,11 +435,11 @@ jQuery.fx.prototype = { // Simple 'hide' function hide: function() { // Remember where we started, so that we can go back to it later - this.options.orig[this.prop] = jQuery.style( this.elem, this.prop ); + this.options.orig[ this.prop ] = jQuery.style( this.elem, this.prop ); this.options.hide = true; // Begin the animation - this.custom(this.cur(), 0); + this.custom( this.cur(), 0 ); }, // Each step of an animation @@ -467,7 +458,7 @@ jQuery.fx.prototype = { options.animatedProperties[ this.prop ] = true; for ( i in options.animatedProperties ) { - if ( options.animatedProperties[i] !== true ) { + if ( options.animatedProperties[ i ] !== true ) { done = false; } } @@ -476,14 +467,14 @@ jQuery.fx.prototype = { // Reset the overflow if ( options.overflow != null && !jQuery.support.shrinkWrapBlocks ) { - jQuery.each( [ "", "X", "Y" ], function (index, value) { - elem.style[ "overflow" + value ] = options.overflow[index]; + jQuery.each( [ "", "X", "Y" ], function( index, value ) { + elem.style[ "overflow" + value ] = options.overflow[ index ]; }); } // Hide the element if the "hide" operation was done if ( options.hide ) { - jQuery(elem).hide(); + jQuery( elem ).hide(); } // Reset the properties, if the item has been hidden or shown @@ -508,8 +499,8 @@ jQuery.fx.prototype = { this.state = n / options.duration; // Perform the easing function, defaults to swing - this.pos = jQuery.easing[ options.animatedProperties[ this.prop ] ]( this.state, n, 0, 1, options.duration ); - this.now = this.start + ((this.end - this.start) * this.pos); + this.pos = jQuery.easing[ options.animatedProperties[this.prop] ]( this.state, n, 0, 1, options.duration ); + this.now = this.start + ( (this.end - this.start) * this.pos ); } // Perform the next step of the animation this.update(); @@ -522,7 +513,7 @@ jQuery.fx.prototype = { jQuery.extend( jQuery.fx, { tick: function() { for ( var timers = jQuery.timers, i = 0 ; i < timers.length ; ++i ) { - if ( !timers[i]() ) { + if ( !timers[ i ]() ) { timers.splice(i--, 1); } } @@ -553,7 +544,7 @@ jQuery.extend( jQuery.fx, { _default: function( fx ) { if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) { - fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit; + fx.elem.style[ fx.prop ] = fx.now + fx.unit; } else { fx.elem[ fx.prop ] = fx.now; } @@ -561,6 +552,14 @@ jQuery.extend( jQuery.fx, { } }); +// Adds width/height step functions +// Do not set anything below 0 +jQuery.each([ "width", "height" ], function( i, prop ) { + jQuery.fx.step[ prop ] = function( fx ) { + jQuery.style( fx.elem, prop, Math.max(0, fx.now) ); + }; +}); + if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.animated = function( elem ) { return jQuery.grep(jQuery.timers, function( fn ) { diff --git a/src/queue.js b/src/queue.js index 66383c19..c57d8e5f 100644 --- a/src/queue.js +++ b/src/queue.js @@ -4,15 +4,15 @@ function handleQueueMarkDefer( elem, type, src ) { var deferDataKey = type + "defer", queueDataKey = type + "queue", markDataKey = type + "mark", - defer = jQuery.data( elem, deferDataKey, undefined, true ); + defer = jQuery._data( elem, deferDataKey ); if ( defer && - ( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) && - ( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) { + ( src === "queue" || !jQuery._data(elem, queueDataKey) ) && + ( src === "mark" || !jQuery._data(elem, markDataKey) ) ) { // Give room for hard-coded callbacks to fire first // and eventually mark/queue something else on the element setTimeout( function() { - if ( !jQuery.data( elem, queueDataKey, undefined, true ) && - !jQuery.data( elem, markDataKey, undefined, true ) ) { + if ( !jQuery._data( elem, queueDataKey ) && + !jQuery._data( elem, markDataKey ) ) { jQuery.removeData( elem, deferDataKey, true ); defer.resolve(); } @@ -25,7 +25,7 @@ jQuery.extend({ _mark: function( elem, type ) { if ( elem ) { type = (type || "fx") + "mark"; - jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true ); + jQuery._data( elem, type, (jQuery._data( elem, type ) || 0) + 1 ); } }, @@ -38,9 +38,9 @@ jQuery.extend({ if ( elem ) { type = type || "fx"; var key = type + "mark", - count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 ); + count = force ? 0 : ( (jQuery._data( elem, key ) || 1) - 1 ); if ( count ) { - jQuery.data( elem, key, count, true ); + jQuery._data( elem, key, count ); } else { jQuery.removeData( elem, key, true ); handleQueueMarkDefer( elem, type, "mark" ); @@ -49,13 +49,15 @@ jQuery.extend({ }, queue: function( elem, type, data ) { + var q; if ( elem ) { type = (type || "fx") + "queue"; - var q = jQuery.data( elem, type, undefined, true ); + q = jQuery._data( elem, type ); + // Speed up dequeue by getting out quickly if this is just a lookup if ( data ) { if ( !q || jQuery.isArray(data) ) { - q = jQuery.data( elem, type, jQuery.makeArray(data), true ); + q = jQuery._data( elem, type, jQuery.makeArray(data) ); } else { q.push( data ); } From d729ef951c480dd21bb1266948706589f8566d5a Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 30 May 2011 01:18:09 -0400 Subject: [PATCH 02/26] Animation state is tracked on toggled/stopped animations using the private data cache. Tests added. Fixes #8685. - Example: http://jsfiddle.net/timmywil/gqZL5/17/ - http://bugs.jquery.com/ticket/8685 --- src/effects.js | 52 ++++++++--- test/unit/effects.js | 207 ++++++++++++++++++++++++++----------------- 2 files changed, 163 insertions(+), 96 deletions(-) diff --git a/src/effects.js b/src/effects.js index 88986af7..c18a671d 100644 --- a/src/effects.js +++ b/src/effects.js @@ -141,7 +141,8 @@ jQuery.fn.extend({ isElement = this.nodeType === 1, hidden = isElement && jQuery(this).is(":hidden"), name, val, p, e, - parts, start, end, unit; + parts, start, end, unit, + method; // will store per property easing and be used to determine when an animation is complete opt.animatedProperties = {}; @@ -203,7 +204,15 @@ jQuery.fn.extend({ val = prop[ p ]; if ( rfxtypes.test( val ) ) { - e[ val === "toggle" ? hidden ? "show" : "hide" : val ](); + // Tracks whether to show or hide based on private + // data attached to the element + method = jQuery._data( this, "toggle" + p ) || (val === "toggle" ? hidden ? "show" : "hide" : 0); + if ( method ) { + jQuery._data( this, "toggle" + p, method === "show" ? "hide" : "show" ); + e[ method ](); + } else { + e[ val ](); + } } else { parts = rfxnum.exec( val ); @@ -246,6 +255,7 @@ jQuery.fn.extend({ this.each(function() { var timers = jQuery.timers, i = timers.length; + // clear marker counters if we know they won't be if ( !gotoEnd ) { jQuery._unmark( true, this ); @@ -255,6 +265,8 @@ jQuery.fn.extend({ if ( gotoEnd ) { // force the next step to be the last timers[ i ]( true ); + } else { + timers[ i ].saveState(); } timers.splice(i, 1); @@ -398,6 +410,11 @@ jQuery.fx.prototype = { } t.elem = this.elem; + t.saveState = function() { + if ( self.options.hide && jQuery._data( self.elem, "fxshow" + self.prop ) === undefined ) { + jQuery._data( self.elem, "fxshow" + self.prop, self.start ); + } + }; if ( t() && jQuery.timers.push(t) && !timerId ) { // Use requestAnimationFrame instead of setInterval if available @@ -419,14 +436,20 @@ jQuery.fx.prototype = { // Simple 'show' function show: function() { + var dataShow = jQuery._data( this.elem, "fxshow" + this.prop ); + // Remember where we started, so that we can go back to it later - this.options.orig[ this.prop ] = jQuery.style( this.elem, this.prop ); + this.options.orig[ this.prop ] = dataShow || jQuery.style( this.elem, this.prop ); this.options.show = true; // Begin the animation - // Make sure that we start at a small width/height to avoid any - // flash of content - this.custom( this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur() ); + // Make sure that we start at a small width/height to avoid any flash of content + if ( dataShow !== undefined ) { + // This show is picking up where a previous hide or show left off + this.custom( this.cur(), dataShow ); + } else { + this.custom( this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur() ); + } // Start by showing the element jQuery( this.elem ).show(); @@ -435,7 +458,7 @@ jQuery.fx.prototype = { // Simple 'hide' function hide: function() { // Remember where we started, so that we can go back to it later - this.options.orig[ this.prop ] = jQuery.style( this.elem, this.prop ); + this.options.orig[ this.prop ] = jQuery._data( this.elem, "fxshow" + this.prop ) || jQuery.style( this.elem, this.prop ); this.options.hide = true; // Begin the animation @@ -448,7 +471,7 @@ jQuery.fx.prototype = { done = true, elem = this.elem, options = this.options, - i, n; + p, n; if ( gotoEnd || t >= options.duration + this.startTime ) { this.now = this.end; @@ -457,8 +480,8 @@ jQuery.fx.prototype = { options.animatedProperties[ this.prop ] = true; - for ( i in options.animatedProperties ) { - if ( options.animatedProperties[ i ] !== true ) { + for ( p in options.animatedProperties ) { + if ( options.animatedProperties[ p ] !== true ) { done = false; } } @@ -479,8 +502,11 @@ jQuery.fx.prototype = { // Reset the properties, if the item has been hidden or shown if ( options.hide || options.show ) { - for ( var p in options.animatedProperties ) { - jQuery.style( elem, p, options.orig[p] ); + for ( p in options.animatedProperties ) { + jQuery.style( elem, p, options.orig[ p ] ); + jQuery.removeData( elem, "fxshow" + p, true ); + // Toggle data is no longer needed + jQuery.removeData( elem, "toggle" + p, true ); } } @@ -512,7 +538,7 @@ jQuery.fx.prototype = { jQuery.extend( jQuery.fx, { tick: function() { - for ( var timers = jQuery.timers, i = 0 ; i < timers.length ; ++i ) { + for ( var timers = jQuery.timers, i = 0; i < timers.length; i++ ) { if ( !timers[ i ]() ) { timers.splice(i--, 1); } diff --git a/test/unit/effects.js b/test/unit/effects.js index 864c4a40..5a5a3ec1 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -660,63 +660,63 @@ test("CSS Overflow and Display", function() { .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay); }); -jQuery.each( { - "CSS Auto": function(elem,prop){ - jQuery(elem).addClass("auto" + prop) - .text("This is a long string of text."); +jQuery.each({ + "CSS Auto": function( elem, prop ) { + jQuery( elem ).addClass( "auto" + prop ) + .text( "This is a long string of text." ); return ""; }, - "JS Auto": function(elem,prop){ - jQuery(elem).css(prop,"") - .text("This is a long string of text."); + "JS Auto": function( elem, prop ) { + jQuery( elem ).css( prop, "" ) + .text( "This is a long string of text." ); return ""; }, - "CSS 100": function(elem,prop){ - jQuery(elem).addClass("large" + prop); + "CSS 100": function( elem, prop ) { + jQuery( elem ).addClass( "large" + prop ); return ""; }, - "JS 100": function(elem,prop){ - jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px"); - return prop == "opacity" ? 1 : 100; + "JS 100": function( elem, prop ) { + jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" ); + return prop === "opacity" ? 1 : 100; }, - "CSS 50": function(elem,prop){ - jQuery(elem).addClass("med" + prop); + "CSS 50": function( elem, prop ) { + jQuery( elem ).addClass( "med" + prop ); return ""; }, - "JS 50": function(elem,prop){ - jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px"); - return prop == "opacity" ? 0.5 : 50; + "JS 50": function( elem, prop ) { + jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" ); + return prop === "opacity" ? 0.5 : 50; }, - "CSS 0": function(elem,prop){ - jQuery(elem).addClass("no" + prop); + "CSS 0": function( elem, prop ) { + jQuery( elem ).addClass( "no" + prop ); return ""; }, - "JS 0": function(elem,prop){ - jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px"); + "JS 0": function( elem, prop ) { + jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" ); return 0; } }, function( fn, f ) { jQuery.each({ - "show": function(elem,prop){ - jQuery(elem).hide().addClass("wide"+prop); + "show": function( elem, prop ) { + jQuery( elem ).hide( ).addClass( "wide" + prop ); return "show"; }, - "hide": function(elem,prop){ - jQuery(elem).addClass("wide"+prop); + "hide": function( elem, prop ) { + jQuery( elem ).addClass( "wide" + prop ); return "hide"; }, - "100": function(elem,prop){ - jQuery(elem).addClass("wide"+prop); + "100": function( elem, prop ) { + jQuery( elem ).addClass( "wide" + prop ); return prop == "opacity" ? 1 : 100; }, - "50": function(elem,prop){ + "50": function( elem, prop ) { return prop == "opacity" ? 0.50 : 50; }, - "0": function(elem,prop){ - jQuery(elem).addClass("noback"); + "0": function( elem, prop ) { + jQuery( elem ).addClass( "noback" ); return 0; } - }, function(tn, t){ + }, function( tn, t ) { test(fn + " to " + tn, function() { var elem = jQuery.makeTest( fn + " to " + tn ); @@ -731,77 +731,82 @@ jQuery.each( { if ( t_h == "show" ) num++; if ( t_w == "show" ) num++; - if ( t_w == "hide"||t_w == "show" ) num++; - if ( t_h == "hide"||t_h == "show" ) num++; - if ( t_o == "hide"||t_o == "show" ) num++; + if ( t_w == "hide" || t_w == "show" ) num++; + if ( t_h == "hide" || t_h == "show" ) num++; + if ( t_o == "hide" || t_o == "show" ) num++; if ( t_w == "hide" ) num++; if ( t_o.constructor == Number ) num += 2; if ( t_w.constructor == Number ) num += 2; if ( t_h.constructor == Number ) num +=2; - expect(num); + expect( num ); stop(); var anim = { width: t_w, height: t_h, opacity: t_o }; elem.animate(anim, 50); - jQuery.when( elem ).done(function( elem ){ + jQuery.when( elem ).done(function( elem ) { elem = elem[ 0 ]; - if ( t_w == "show" ) - equals( elem.style.display, "block", "Showing, display should block: " + elem.style.display); + if ( t_w == "show" ) { + equals( elem.style.display, "block", "Showing, display should block: " + elem.style.display ); + } - if ( t_w == "hide"||t_w == "show" ) - ok(f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + elem.style.width); + if ( t_w == "hide" || t_w == "show" ) { + ok( f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf( f_w ) === 0, "Width must be reset to " + f_w + ": " + elem.style.width ); + } - if ( t_h == "hide"||t_h == "show" ) - ok(f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + elem.style.height); + if ( t_h == "hide" || t_h == "show" ) { + ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height ); + } var cur_o = jQuery.style(elem, "opacity"); - if ( t_o == "hide" || t_o == "show" ) - equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o); + if ( t_o == "hide" || t_o == "show" ) { + equals( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o ); + } - if ( t_w == "hide" ) - equals(elem.style.display, "none", "Hiding, display should be none: " + elem.style.display); + if ( t_w == "hide" ) { + equals( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display ); + } if ( t_o.constructor == Number ) { - equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o); + equals( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o ); - ok(jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o); + ok( jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o ); } if ( t_w.constructor == Number ) { - equals(elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width); + equals( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width ); - var cur_w = jQuery.css(elem,"width"); + var cur_w = jQuery.css( elem,"width" ); - ok(elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w); + ok( elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w ); } if ( t_h.constructor == Number ) { - equals(elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height); + equals( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height ); - var cur_h = jQuery.css(elem,"height"); + var cur_h = jQuery.css( elem,"height" ); - ok(elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w); + ok( elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w ); } if ( t_h == "show" ) { - var old_h = jQuery.css(elem, "height"); - jQuery(elem).append("
Some more text
and some more..."); + var old_h = jQuery.css( elem, "height" ); + jQuery( elem ).append("
Some more text
and some more..."); if ( /Auto/.test( fn ) ) { - notEqual(jQuery.css(elem, "height"), old_h, "Make sure height is auto."); + notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." ); } else { - equals(jQuery.css(elem, "height"), old_h, "Make sure height is not auto."); + equals( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." ); } } // manually remove generated element - jQuery(elem).remove(); + jQuery( elem ).remove(); start(); }); @@ -809,7 +814,7 @@ jQuery.each( { }); }); -jQuery.fn.saveState = function(hiddenOverflow){ +jQuery.fn.saveState = function( hiddenOverflow ) { var check = ["opacity", "height", "width", "display", "overflow"]; expect(check.length); @@ -817,83 +822,83 @@ jQuery.fn.saveState = function(hiddenOverflow){ return this.each(function(){ var self = this; self.save = {}; - jQuery.each(check, function(i,c){ - self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c); + jQuery.each(check, function( i, c ) { + self.save[ c ] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css( self, c ); }); }); }; -jQuery.checkState = function(){ +jQuery.checkState = function() { var self = this; - jQuery.each(this.save, function(c,v){ - var cur = self.style[ c ] || jQuery.css(self, c); + jQuery.each(this.save, function( c, v ) { + var cur = self.style[ c ] || jQuery.css( self, c ); equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")"); }); // manually clean data on modified element - jQuery.removeData(this, "olddisplay", true); + jQuery.removeData( this, "olddisplay", true ); start(); }; // Chaining Tests test("Chain fadeOut fadeIn", function() { - jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast",jQuery.checkState); + jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast", jQuery.checkState ); }); test("Chain fadeIn fadeOut", function() { - jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast",jQuery.checkState); + jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast", jQuery.checkState ); }); test("Chain hide show", function() { - jQuery("#show div").saveState(jQuery.support.shrinkWrapBlocks).hide("fast").show("fast",jQuery.checkState); + jQuery("#show div").saveState( jQuery.support.shrinkWrapBlocks ).hide("fast").show("fast", jQuery.checkState ); }); test("Chain show hide", function() { - jQuery("#hide div").saveState(jQuery.support.shrinkWrapBlocks).show("fast").hide("fast",jQuery.checkState); + jQuery("#hide div").saveState( jQuery.support.shrinkWrapBlocks ).show("fast").hide("fast", jQuery.checkState ); }); test("Chain show hide with easing and callback", function() { - jQuery("#hide div").saveState().show("fast").hide("fast","linear",jQuery.checkState); + jQuery("#hide div").saveState().show("fast").hide("fast","linear", jQuery.checkState ); }); test("Chain toggle in", function() { - jQuery("#togglein div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast",jQuery.checkState); + jQuery("#togglein div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState ); }); test("Chain toggle out", function() { - jQuery("#toggleout div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast",jQuery.checkState); + jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState ); }); test("Chain toggle out with easing and callback", function() { - jQuery("#toggleout div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast","linear",jQuery.checkState); + jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast","linear", jQuery.checkState ); }); test("Chain slideDown slideUp", function() { - jQuery("#slidedown div").saveState(jQuery.support.shrinkWrapBlocks).slideDown("fast").slideUp("fast",jQuery.checkState); + jQuery("#slidedown div").saveState( jQuery.support.shrinkWrapBlocks ).slideDown("fast").slideUp("fast", jQuery.checkState ); }); test("Chain slideUp slideDown", function() { - jQuery("#slideup div").saveState(jQuery.support.shrinkWrapBlocks).slideUp("fast").slideDown("fast",jQuery.checkState); + jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast", jQuery.checkState ); }); test("Chain slideUp slideDown with easing and callback", function() { - jQuery("#slideup div").saveState(jQuery.support.shrinkWrapBlocks).slideUp("fast").slideDown("fast","linear",jQuery.checkState); + jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast","linear", jQuery.checkState ); }); test("Chain slideToggle in", function() { - jQuery("#slidetogglein div").saveState(jQuery.support.shrinkWrapBlocks).slideToggle("fast").slideToggle("fast",jQuery.checkState); + jQuery("#slidetogglein div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState ); }); test("Chain slideToggle out", function() { - jQuery("#slidetoggleout div").saveState(jQuery.support.shrinkWrapBlocks).slideToggle("fast").slideToggle("fast",jQuery.checkState); + jQuery("#slidetoggleout div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState ); }); test("Chain fadeToggle in", function() { - jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast",jQuery.checkState); + jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState ); }); test("Chain fadeToggle out", function() { - jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast",jQuery.checkState); + jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState ); }); test("Chain fadeTo 0.5 1.0 with easing and callback)", function() { - jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear",jQuery.checkState); + jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear", jQuery.checkState ); }); jQuery.makeTest = function( text ){ var elem = jQuery("
") - .attr("id", "test" + jQuery.makeTest.id++) + .attr( "id", "test" + jQuery.makeTest.id++ ) .addClass("box"); jQuery("

") @@ -921,6 +926,42 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () }); }); +jQuery.each({ + "slideToggle": function( $elem ) { + return $elem.height(); + }, + "fadeToggle": function( $elem ) { + return $elem.css("opacity"); + }, + "toggle": function( $elem ) { + return $elem.width(); + } +}, +function( method, defProp ) { + test( method + "().stop()." + method + "()", function() { + expect( 4 ); + + jQuery.each([ "in", "out" ], function( i, type ) { + var $elem = jQuery( "#" + method.toLowerCase() + type ), + startVal = defProp( $elem ); + + $elem[ method ]("fast"); + stop(); + + setTimeout( function() { + $elem.stop(); + + notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." ); + + $elem[ method ]("fast", function() { + equal( defProp( jQuery(this) ), startVal, "After doing .stop() halfway, check that state has been saved for returning to original property value." ); + start(); + }); + }, 100); + }); + }); +}); + test("animate with per-property easing", function(){ expect(5); From 5293495a5f36331d59c91c7e8bcaec36fc98f83e Mon Sep 17 00:00:00 2001 From: timmywil Date: Sat, 4 Jun 2011 22:21:47 -0400 Subject: [PATCH 03/26] Remove unnecessary var in queue.js --- src/effects.js | 8 ++++---- src/queue.js | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/effects.js b/src/effects.js index c18a671d..92498dd7 100644 --- a/src/effects.js +++ b/src/effects.js @@ -178,8 +178,7 @@ jQuery.fn.extend({ opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ]; // Set display property to inline-block for height/width - // animations on inline elements that are having width/height - // animated + // animations on inline elements that are having width/height animated if ( jQuery.css( this, "display" ) === "inline" && jQuery.css( this, "float" ) === "none" ) { @@ -254,7 +253,8 @@ jQuery.fn.extend({ this.each(function() { var timers = jQuery.timers, - i = timers.length; + i = timers.length, + timer; // clear marker counters if we know they won't be if ( !gotoEnd ) { @@ -269,7 +269,7 @@ jQuery.fn.extend({ timers[ i ].saveState(); } - timers.splice(i, 1); + timers.splice( i, 1 ); } } }); diff --git a/src/queue.js b/src/queue.js index c57d8e5f..cd6aeb26 100644 --- a/src/queue.js +++ b/src/queue.js @@ -70,8 +70,7 @@ jQuery.extend({ type = type || "fx"; var queue = jQuery.queue( elem, type ), - fn = queue.shift(), - defer; + fn = queue.shift(); // If the fx queue is dequeued, always remove the progress sentinel if ( fn === "inprogress" ) { @@ -86,7 +85,7 @@ jQuery.extend({ } fn.call(elem, function() { - jQuery.dequeue(elem, type); + jQuery.dequeue( elem, type ); }); } @@ -123,7 +122,7 @@ jQuery.fn.extend({ // Based off of the plugin by Clint Helfers, with permission. // http://blindsignals.com/index.php/2009/07/jquery-delay/ delay: function( time, type ) { - time = jQuery.fx ? jQuery.fx.speeds[time] || time : time; + time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time; type = type || "fx"; return this.queue( type, function() { From 3d646c54031c9fb3cc54125884547065812006b6 Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 7 Jun 2011 17:29:56 -0400 Subject: [PATCH 04/26] Remove unnecessary var in effects --- src/effects.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/effects.js b/src/effects.js index 92498dd7..b732004b 100644 --- a/src/effects.js +++ b/src/effects.js @@ -253,8 +253,7 @@ jQuery.fn.extend({ this.each(function() { var timers = jQuery.timers, - i = timers.length, - timer; + i = timers.length; // clear marker counters if we know they won't be if ( !gotoEnd ) { From 0a80be67f4fe968d99777564a02aeddbde1fbf35 Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 6 Jun 2011 20:13:50 -0400 Subject: [PATCH 05/26] Add catch block to try/finally in deferred. Fixes #9033. Test case needed. --- src/deferred.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/deferred.js b/src/deferred.js index 5cc5fb5b..3d53344e 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -58,8 +58,9 @@ jQuery.extend({ while( callbacks[ 0 ] ) { callbacks.shift().apply( context, args ); } - } - finally { + } catch( e ) { + throw e; + } finally { fired = [ context, args ]; firing = 0; } From db437be6e31c924aade13bb719f9facc122b3d9c Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 7 Jun 2011 20:54:11 -0400 Subject: [PATCH 06/26] Check classes passed for duplicates. Fixes #9499. --- src/attributes.js | 47 ++++++++++++++++++++++------------------- src/effects.js | 4 ++-- test/data/testsuite.css | 2 +- test/unit/attributes.js | 13 ++++++++++-- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index abe52b89..5b68773c 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -37,30 +37,31 @@ jQuery.fn.extend({ }, addClass: function( value ) { + var classNames, i, l, elem, setClass, c, cl; + if ( jQuery.isFunction( value ) ) { - return this.each(function(i) { - var self = jQuery(this); - self.addClass( value.call(this, i, self.attr("class") || "") ); + return this.each(function( j ) { + var self = jQuery( this ); + self.addClass( value.call(this, j, self.attr("class") || "") ); }); } if ( value && typeof value === "string" ) { - var classNames = (value || "").split( rspace ); + classNames = value.split( rspace ); - for ( var i = 0, l = this.length; i < l; i++ ) { - var elem = this[i]; + for ( i = 0, l = this.length; i < l; i++ ) { + elem = this[ i ]; if ( elem.nodeType === 1 ) { - if ( !elem.className ) { + if ( !elem.className && classNames.length === 1 ) { elem.className = value; } else { - var className = " " + elem.className + " ", - setClass = elem.className; + setClass = elem.className; - for ( var c = 0, cl = classNames.length; c < cl; c++ ) { - if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { - setClass += " " + classNames[c]; + for ( c = 0, cl = classNames.length; c < cl; c++ ) { + if ( !~setClass.indexOf(classNames[ c ]) ) { + setClass += " " + classNames[ c ]; } } elem.className = jQuery.trim( setClass ); @@ -73,24 +74,26 @@ jQuery.fn.extend({ }, removeClass: function( value ) { - if ( jQuery.isFunction(value) ) { - return this.each(function(i) { - var self = jQuery(this); - self.removeClass( value.call(this, i, self.attr("class")) ); + var classNames, i, l, elem, className, c, cl; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + var self = jQuery( this ); + self.removeClass( value.call(this, j, self.attr("class")) ); }); } if ( (value && typeof value === "string") || value === undefined ) { - var classNames = (value || "").split( rspace ); + classNames = (value || "").split( rspace ); - for ( var i = 0, l = this.length; i < l; i++ ) { - var elem = this[i]; + for ( i = 0, l = this.length; i < l; i++ ) { + elem = this[ i ]; if ( elem.nodeType === 1 && elem.className ) { if ( value ) { - var className = (" " + elem.className + " ").replace(rclass, " "); - for ( var c = 0, cl = classNames.length; c < cl; c++ ) { - className = className.replace(" " + classNames[c] + " ", " "); + className = (" " + elem.className + " ").replace( rclass, " " ); + for ( c = 0, cl = classNames.length; c < cl; c++ ) { + className = className.replace(" " + classNames[ c ] + " ", " "); } elem.className = jQuery.trim( className ); diff --git a/src/effects.js b/src/effects.js index 22496277..3a4e2663 100644 --- a/src/effects.js +++ b/src/effects.js @@ -15,8 +15,8 @@ var elemdisplay = {}, ], fxNow, requestAnimationFrame = window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame; + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame; jQuery.fn.extend({ show: function( speed, easing, callback ) { diff --git a/test/data/testsuite.css b/test/data/testsuite.css index 47caf34a..295740f5 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -119,5 +119,5 @@ sup { display: none; } dfn { display: none; } /* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ -body, div { background: url(http://www.ctemploymentlawblog.com/test.jpg) no-repeat -1000px 0; } +body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 56c398e5..37260f2f 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -761,12 +761,14 @@ test("val(select) after form.reset() (Bug #2551)", function() { }); var testAddClass = function(valueObj) { - expect(5); + expect(7); var div = jQuery("div"); div.addClass( valueObj("test") ); var pass = true; for ( var i = 0; i < div.size(); i++ ) { - if ( div.get(i).className.indexOf("test") == -1 ) pass = false; + if ( !~div.get(i).className.indexOf("test") ) { + pass = false; + } } ok( pass, "Add Class" ); @@ -787,6 +789,13 @@ var testAddClass = function(valueObj) { div.attr("class", "foo"); div.addClass( valueObj("bar baz") ); equals( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." ); + + div.removeAttr("class"); + div.addClass( valueObj("foo") ).addClass( valueObj("foo") ) + equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." ); + div.removeAttr("class"); + div.addClass( valueObj("bar bar") ); + equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." ); }; test("addClass(String)", function() { From 39a2f29c29fdb296bb178b3c55d805ea0dc2f0ce Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 8 Jun 2011 10:55:52 -0400 Subject: [PATCH 07/26] Revert "Add catch block to try/finally in deferred. Fixes #9033. Test case needed." Line of exception was lost when debugging. This reverts commit 0a80be67f4fe968d99777564a02aeddbde1fbf35. --- src/deferred.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/deferred.js b/src/deferred.js index 3d53344e..5cc5fb5b 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -58,9 +58,8 @@ jQuery.extend({ while( callbacks[ 0 ] ) { callbacks.shift().apply( context, args ); } - } catch( e ) { - throw e; - } finally { + } + finally { fired = [ context, args ]; firing = 0; } From 641ad802111d2dc16ccf4b3721784a6addaf20df Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 13 Jun 2011 10:02:13 -0400 Subject: [PATCH 08/26] Attribute hooks do not need to be attached in XML docs. Fixes #9568. --- src/attributes.js | 31 +++++++++++++++++-------------- test/data/dashboard.xml | 2 +- test/unit/attributes.js | 7 ++++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index 5b68773c..ce7b3502 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -320,21 +320,23 @@ jQuery.extend({ notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); // Normalize the name if needed - name = notxml && jQuery.attrFix[ name ] || name; + if ( notxml ) { + name = jQuery.attrFix[ name ] || name; - hooks = jQuery.attrHooks[ name ]; + hooks = jQuery.attrHooks[ name ]; - if ( !hooks ) { - // Use boolHook for boolean attributes - if ( rboolean.test( name ) ) { + if ( !hooks ) { + // Use boolHook for boolean attributes + if ( rboolean.test( name ) ) { - hooks = boolHook; + hooks = boolHook; - // Use formHook for forms and if the name contains certain characters - } else if ( formHook && name !== "className" && - (jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) { + // Use formHook for forms and if the name contains certain characters + } else if ( formHook && name !== "className" && + (jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) { - hooks = formHook; + hooks = formHook; + } } } @@ -465,10 +467,11 @@ jQuery.extend({ var ret, hooks, notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); - // Try to normalize/fix the name - name = notxml && jQuery.propFix[ name ] || name; - - hooks = jQuery.propHooks[ name ]; + if ( notxml ) { + // Fix name and attach hooks + name = jQuery.propFix[ name ] || name; + hooks = jQuery.propHooks[ name ]; + } if ( value !== undefined ) { if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { diff --git a/test/data/dashboard.xml b/test/data/dashboard.xml index 10f6b334..5a6f5614 100644 --- a/test/data/dashboard.xml +++ b/test/data/dashboard.xml @@ -1,7 +1,7 @@ - + diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 37260f2f..831f729c 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -132,11 +132,12 @@ test("attr(String)", function() { if ( !isLocal ) { test("attr(String) in XML Files", function() { - expect(2); + expect(3); stop(); jQuery.get("data/dashboard.xml", function( xml ) { - equals( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" ); - equals( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" ); + equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" ); + equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" ); + equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" ); start(); }); }); From 6926247bf441deaa0441872849bb3786c257a4cf Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 14 Jun 2011 15:38:46 -0400 Subject: [PATCH 09/26] Landing pull request 397. withinElement rewrite in event. Fixes #6234, #9357, #9447. More Details: - https://github.com/jquery/jquery/pull/397 - http://bugs.jquery.com/ticket/6234 - http://bugs.jquery.com/ticket/9357 - http://bugs.jquery.com/ticket/9447 --- src/event.js | 31 ++++++++++++------------------- test/unit/event.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/event.js b/src/event.js index 3f53ab5c..131739b1 100644 --- a/src/event.js +++ b/src/event.js @@ -650,34 +650,27 @@ jQuery.Event.prototype = { // Checks if an event happened on an element within another element // Used in jQuery.event.special.mouseenter and mouseleave handlers var withinElement = function( event ) { - // Check if mouse(over|out) are still within the same parent element - var parent = event.relatedTarget; - // set the correct event type + // Check if mouse(over|out) are still within the same parent element + var related = event.relatedTarget, + inside = false, + eventType = event.type; + event.type = event.data; - // Firefox sometimes assigns relatedTarget a XUL element - // which we cannot access the parentNode property of - try { + if ( related !== this ) { - // Chrome does something similar, the parentNode property - // can be accessed but is null. - if ( parent && parent !== document && !parent.parentNode ) { - return; + if ( related ) { + inside = jQuery.contains( this, related ); } - // Traverse up the tree - while ( parent && parent !== this ) { - parent = parent.parentNode; - } + if ( !inside ) { - if ( parent !== this ) { - // handle event if we actually just moused on to a non sub-element jQuery.event.handle.apply( this, arguments ); - } - // assuming we've left the element since we most likely mousedover a xul element - } catch(e) { } + event.type = eventType; + } + } }, // In case of event delegation, we only need to rename the event.type, diff --git a/test/unit/event.js b/test/unit/event.js index f71c7b29..7c628880 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -780,6 +780,43 @@ test("mouseover triggers mouseenter", function() { elem.remove(); }); +test("withinElement implemented with jQuery.contains()", function() { + + expect(1); + + jQuery("#qunit-fixture").append('
'); + + jQuery("#jc-outer").bind("mouseenter mouseleave", function( event ) { + + equal( this.id, "jc-outer", this.id + " " + event.type ); + + }).trigger("mouseenter"); + + jQuery("#jc-inner").trigger("mousenter"); + + jQuery("#jc-outer").unbind("mouseenter mouseleave").remove(); + jQuery("#jc-inner").remove(); + +}); + +test("mouseenter, mouseleave don't catch exceptions", function() { + expect(2); + + var elem = jQuery("#firstp").hover(function() { throw "an Exception"; }); + + try { + elem.mouseenter(); + } catch (e) { + equals( e, "an Exception", "mouseenter doesn't catch exceptions" ); + } + + try { + elem.mouseleave(); + } catch (e) { + equals( e, "an Exception", "mouseleave doesn't catch exceptions" ); + } +}); + test("trigger() shortcuts", function() { expect(6); From 13ceb0f56b380b395ed5a26b468bf2bf00d88216 Mon Sep 17 00:00:00 2001 From: Greg Hazel Date: Tue, 14 Jun 2011 15:51:03 -0400 Subject: [PATCH 10/26] Landing pull request 410. Moves jQuery attachment comment to outro. More Details: - https://github.com/jquery/jquery/pull/410 --- src/core.js | 1 - src/outro.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 3a32d6f0..2c27bf7c 100644 --- a/src/core.js +++ b/src/core.js @@ -923,7 +923,6 @@ function doScrollCheck() { jQuery.ready(); } -// Expose jQuery to the global object return jQuery; })(); diff --git a/src/outro.js b/src/outro.js index 32b0d087..b49305e7 100644 --- a/src/outro.js +++ b/src/outro.js @@ -1,2 +1,3 @@ +// Expose jQuery to the global object window.jQuery = window.$ = jQuery; })(window); From 5eef5917fdb399ace2698154c4cd7bbd24f13182 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 14 Jun 2011 15:59:22 -0400 Subject: [PATCH 11/26] Landing pull request 409. Adds fillOpacity to internal cssNumber. Fixes #9548. More Details: - https://github.com/jquery/jquery/pull/409 - http://bugs.jquery.com/ticket/9548 --- src/css.js | 9 +++++---- test/unit/css.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/css.js b/src/css.js index fcc784d2..c60bcdde 100644 --- a/src/css.js +++ b/src/css.js @@ -50,13 +50,14 @@ jQuery.extend({ // Exclude the following css properties to add px cssNumber: { - "zIndex": true, + "fillOpacity": true, "fontWeight": true, - "opacity": true, - "zoom": true, "lineHeight": true, + "opacity": true, + "orphans": true, "widows": true, - "orphans": true + "zIndex": true, + "zoom": true }, // Add in properties whose names you wish to fix before diff --git a/test/unit/css.js b/test/unit/css.js index e631f496..f421f7bd 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -475,3 +475,13 @@ test("widows & orphans #8936", function () { $p.remove(); }); + +test("Do not append px to 'fill-opacity' #9548", 1, function() { + + var $div = jQuery("
").appendTo("#qunit-fixture"); + + $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () { + equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'"); + }); + +}); From 8a532d15757f8c3ba491ae14d024e353de6b4c7f Mon Sep 17 00:00:00 2001 From: Schalk Neethling Date: Tue, 14 Jun 2011 16:01:50 -0400 Subject: [PATCH 12/26] Landing pull request 378. Comment typo in core.js. More Details: - https://github.com/jquery/jquery/pull/378 --- src/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 2c27bf7c..ab0d9f7b 100644 --- a/src/core.js +++ b/src/core.js @@ -792,7 +792,7 @@ jQuery.extend({ }, // Mutifunctional method to get and set values to a collection - // The value/s can be optionally by executed if its a function + // The value/s can optionally be executed if it's a function access: function( elems, key, value, exec, fn, pass ) { var length = elems.length; From d443e533aa83e89e6a1b02280dfc77f741cb4db6 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 14 Jun 2011 14:54:23 -0700 Subject: [PATCH 13/26] Tagging the 1.6.2rc1 release. --- build/release-notes.js | 4 ++-- test/qunit | 2 +- version.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/release-notes.js b/build/release-notes.js index 0166732e..57d03789 100644 --- a/build/release-notes.js +++ b/build/release-notes.js @@ -9,8 +9,8 @@ var fs = require("fs"), extract = /(.*?)<[^"]+"component">\s*(\S+)/g; var opts = { - version: "1.6.1 RC 1", - short_version: "1.6rc1", + version: "1.6.1", + short_version: "1.6.1", final_version: "1.6.1", categories: [] }; diff --git a/test/qunit b/test/qunit index d4f23f8a..d97b37ec 160000 --- a/test/qunit +++ b/test/qunit @@ -1 +1 @@ -Subproject commit d4f23f8a882d13b71768503e2db9fa33ef169ba0 +Subproject commit d97b37ec322136406790e75d03333559f38bbecb diff --git a/version.txt b/version.txt index 22e67ce2..a0de7ec1 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.2pre \ No newline at end of file +1.6.2rc1 \ No newline at end of file From 138d5b7b811845950279f5ee5391339d7d31e360 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 14 Jun 2011 14:55:14 -0700 Subject: [PATCH 14/26] Updating the source version to 1.6.2pre --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index a0de7ec1..22e67ce2 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.2rc1 \ No newline at end of file +1.6.2pre \ No newline at end of file From d269e426e0844fa025e8ca5510c56860a9cde784 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 14 Jun 2011 15:05:27 -0700 Subject: [PATCH 15/26] Updating version in release notes script. --- build/release-notes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/release-notes.js b/build/release-notes.js index 57d03789..b112d998 100644 --- a/build/release-notes.js +++ b/build/release-notes.js @@ -9,9 +9,9 @@ var fs = require("fs"), extract = /(.*?)<[^"]+"component">\s*(\S+)/g; var opts = { - version: "1.6.1", - short_version: "1.6.1", - final_version: "1.6.1", + version: "1.6.2 RC 1", + short_version: "1.6.2rc1", + final_version: "1.6.2", categories: [] }; From d59b0f3e27827d189b8b2595142ec6bbc3941dd9 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 14 Jun 2011 15:06:28 -0700 Subject: [PATCH 16/26] Re-updating QUnit, oops. --- test/qunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/qunit b/test/qunit index d97b37ec..d4f23f8a 160000 --- a/test/qunit +++ b/test/qunit @@ -1 +1 @@ -Subproject commit d97b37ec322136406790e75d03333559f38bbecb +Subproject commit d4f23f8a882d13b71768503e2db9fa33ef169ba0 From 124817e6684086ccf74e509309b73d4b4dd89932 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Fri, 17 Jun 2011 17:33:29 -0400 Subject: [PATCH 17/26] Landing pull request 413. Move border/padding checks to after width validation to avoid unnecessary fallbacks. Fixes #9598. More Details: - https://github.com/jquery/jquery/pull/413 - http://bugs.jquery.com/ticket/9300 - http://bugs.jquery.com/ticket/9441 - http://bugs.jquery.com/ticket/9598 --- src/css.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/css.js b/src/css.js index c60bcdde..cb7df9f8 100644 --- a/src/css.js +++ b/src/css.js @@ -315,21 +315,20 @@ function getWH( elem, name, extra ) { var val = name === "width" ? elem.offsetWidth : elem.offsetHeight, which = name === "width" ? cssWidth : cssHeight; - if ( extra !== "margin" && extra !== "border" ) { - jQuery.each( which, function() { - val -= parseFloat( jQuery.css( elem, "border" + this + "Width" ) ) || 0; - if ( !extra ) { - val -= parseFloat( jQuery.css( elem, "padding" + this ) ) || 0; - } - }); - } - if ( val > 0 ) { - if ( extra === "margin" ) { + if ( extra !== "border" ) { jQuery.each( which, function() { - val += parseFloat( jQuery.css( elem, extra + this ) ) || 0; + if ( !extra ) { + val -= parseFloat( jQuery.css( elem, "padding" + this ) ) || 0; + } + if ( extra === "margin" ) { + val += parseFloat( jQuery.css( elem, extra + this ) ) || 0; + } else { + val -= parseFloat( jQuery.css( elem, "border" + this + "Width" ) ) || 0; + } }); } + return val + "px"; } From 96501d38a935187461d45c40f17f8327b2e7cd91 Mon Sep 17 00:00:00 2001 From: timmywil Date: Sun, 19 Jun 2011 18:58:47 -0400 Subject: [PATCH 18/26] Allow similarly named classes (regression from 9499) and switch class retrieval to property when passing class to value functions. Fixes #9617. --- src/attributes.js | 20 +++++++++----------- test/unit/attributes.js | 15 +++++++++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index ce7b3502..1e0e79f4 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -37,12 +37,12 @@ jQuery.fn.extend({ }, addClass: function( value ) { - var classNames, i, l, elem, setClass, c, cl; + var classNames, i, l, elem, + setClass, c, cl; if ( jQuery.isFunction( value ) ) { return this.each(function( j ) { - var self = jQuery( this ); - self.addClass( value.call(this, j, self.attr("class") || "") ); + jQuery( this ).addClass( value.call(this, j, this.className) ); }); } @@ -57,11 +57,11 @@ jQuery.fn.extend({ elem.className = value; } else { - setClass = elem.className; + setClass = " " + elem.className + " "; for ( c = 0, cl = classNames.length; c < cl; c++ ) { - if ( !~setClass.indexOf(classNames[ c ]) ) { - setClass += " " + classNames[ c ]; + if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) { + setClass += classNames[ c ] + " "; } } elem.className = jQuery.trim( setClass ); @@ -78,8 +78,7 @@ jQuery.fn.extend({ if ( jQuery.isFunction( value ) ) { return this.each(function( j ) { - var self = jQuery( this ); - self.removeClass( value.call(this, j, self.attr("class")) ); + jQuery( this ).removeClass( value.call(this, j, this.className) ); }); } @@ -112,9 +111,8 @@ jQuery.fn.extend({ 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( i ) { + jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal ); }); } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 831f729c..4716e5b5 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -762,7 +762,8 @@ test("val(select) after form.reset() (Bug #2551)", function() { }); var testAddClass = function(valueObj) { - expect(7); + expect(9); + var div = jQuery("div"); div.addClass( valueObj("test") ); var pass = true; @@ -791,10 +792,16 @@ var testAddClass = function(valueObj) { div.addClass( valueObj("bar baz") ); equals( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." ); - div.removeAttr("class"); + div.removeClass(); div.addClass( valueObj("foo") ).addClass( valueObj("foo") ) equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." ); - div.removeAttr("class"); + + div.addClass( valueObj("fo") ); + equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." ); + div.removeClass().addClass("wrap2"); + ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes"); + + div.removeClass(); div.addClass( valueObj("bar bar") ); equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." ); }; @@ -959,7 +966,7 @@ test("toggleClass(Function[, boolean])", function() { test("toggleClass(Fucntion[, boolean]) with incoming value", function() { expect(14); - var e = jQuery("#firstp"), old = e.attr("class"); + var e = jQuery("#firstp"), old = e.attr("class") || ""; ok( !e.is(".test"), "Assert class not present" ); e.toggleClass(function(i, val) { From ab1504f14f56944a5a6297c68b323f0af01d5be8 Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 28 Jun 2011 11:46:03 -0400 Subject: [PATCH 19/26] Set timerId to true instead of a number so that intervals set to 1 are not accidentally cleared when stopped. Fixes #9678. - Adding a working test case would not be possible in this case, but all tests pass. --- src/effects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/effects.js b/src/effects.js index 3a4e2663..a7529a0f 100644 --- a/src/effects.js +++ b/src/effects.js @@ -411,7 +411,7 @@ jQuery.fx.prototype = { if ( t() && jQuery.timers.push(t) && !timerId ) { // Use requestAnimationFrame instead of setInterval if available if ( requestAnimationFrame ) { - timerId = 1; + timerId = true; raf = function() { // When timerId gets set to null at any point, this stops if ( timerId ) { From aa6f8c8cd399d50e91dc0a3634395b6ebf54b209 Mon Sep 17 00:00:00 2001 From: John Resig Date: Thu, 30 Jun 2011 14:16:56 -0400 Subject: [PATCH 20/26] Tagging the 1.6.2 release. --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 22e67ce2..308b6faa 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.2pre \ No newline at end of file +1.6.2 \ No newline at end of file From e2ab2ba1d51b47f90fd8022e500ea3df563e7d74 Mon Sep 17 00:00:00 2001 From: John Resig Date: Thu, 30 Jun 2011 14:17:44 -0400 Subject: [PATCH 21/26] Updating the source version to 1.6.3pre --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 308b6faa..e37c079f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.2 \ No newline at end of file +1.6.3pre \ No newline at end of file From 5b92a5f5eccf69d480c11dbd2870f8161ae0441b Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 30 Jun 2011 18:18:44 +0200 Subject: [PATCH 22/26] Replaces typo (status instead of state) as observed in #9585. --- src/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index a16717b0..e4e48dc7 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -727,7 +727,7 @@ jQuery.extend({ transport.send( requestHeaders, done ); } catch (e) { // Propagate exception as error if not done - if ( status < 2 ) { + if ( state < 2 ) { done( -1, e ); // Simply rethrow otherwise } else { From 139135a98aab1c422e5ae05b026535a40d58328f Mon Sep 17 00:00:00 2001 From: jaubourg Date: Fri, 1 Jul 2011 01:51:50 +0200 Subject: [PATCH 23/26] Fixes #9446. Context is properly propagated using pipe. If context was the original deferred, then context is updated to next deferred in the chain. Unit tests added. --- src/deferred.js | 2 +- test/unit/deferred.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/deferred.js b/src/deferred.js index 5cc5fb5b..e543f151 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -122,7 +122,7 @@ jQuery.extend({ if ( returned && jQuery.isFunction( returned.promise ) ) { returned.promise().then( newDefer.resolve, newDefer.reject ); } else { - newDefer[ action ]( returned ); + newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] ); } }); } else { diff --git a/test/unit/deferred.js b/test/unit/deferred.js index 89c9c612..fbe29070 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -275,6 +275,33 @@ test( "jQuery.Deferred.pipe - deferred (fail)", function() { strictEqual( value3, 6, "result of filter ok" ); }); +test( "jQuery.Deferred.pipe - context", function() { + + expect(4); + + var context = {}; + + jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) { + return value * 3; + }).done(function( value ) { + strictEqual( this, context, "custom context correctly propagated" ); + strictEqual( value, 6, "proper value received" ); + }); + + var defer = jQuery.Deferred(), + piped = defer.pipe(function( value ) { + return value * 3; + }); + + defer.resolve( 2 ); + + piped.done(function( value ) { + strictEqual( this.promise(), piped, "default context gets updated to latest defer in the chain" ); + strictEqual( value, 6, "proper value received" ); + }); +}); + + test( "jQuery.when" , function() { expect( 23 ); From e83fcdcb02d676d91d764a58f7e8d2eb1c95de69 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Fri, 1 Jul 2011 02:11:26 +0200 Subject: [PATCH 24/26] Fixes #9682. Removes data from the options for request with no content so that it is not used again in case of a retry. Unit test added. --- src/ajax.js | 2 ++ test/unit/ajax.js | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index e4e48dc7..650f3318 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -644,6 +644,8 @@ jQuery.extend({ // If data is available, append data to url if ( s.data ) { s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data; + // #9682: remove data so that it's not used in an eventual retry + delete s.data; } // Get ifModifiedKey before adding the anti-cache parameter diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 9f084136..33433922 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -321,25 +321,40 @@ test("jQuery.ajax() - responseText on error", function() { test(".ajax() - retry with jQuery.ajax( this )", function() { - expect( 1 ); + expect( 2 ); stop(); - var firstTime = 1; + var firstTime = true, + previousUrl; jQuery.ajax({ url: url("data/errorWithText.php"), error: function() { if ( firstTime ) { - firstTime = 0; + firstTime = false; jQuery.ajax( this ); } else { ok( true , "Test retrying with jQuery.ajax(this) works" ); - start(); + jQuery.ajax({ + url: url("data/errorWithText.php"), + data: { x: 1 }, + beforeSend: function() { + if ( !previousUrl ) { + previousUrl = this.url; + } else { + strictEqual( this.url , previousUrl, "url parameters are not re-appended" ); + start(); + return false; + } + }, + error: function() { + jQuery.ajax( this ); + } + }); } } }); - }); test(".ajax() - headers" , function() { From e6f8951983b8ce1af8986651fd412f9e569504c6 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Fri, 1 Jul 2011 02:18:05 +0200 Subject: [PATCH 25/26] Fixes #9632. Adds res:// protocol to the list of local protocols. --- src/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index 650f3318..087f2feb 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -7,7 +7,7 @@ var r20 = /%20/g, rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, // #7653, #8125, #8152: local protocol detection - rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/, + rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/, rnoContent = /^(?:GET|HEAD)$/, rprotocol = /^\/\//, rquery = /\?/, From bb7d98f018c284a27b286a819238bac5541aad5e Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 7 Jul 2011 12:13:10 +0200 Subject: [PATCH 26/26] input type=datetime-local support for ajax. --- src/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index 087f2feb..355fd7e4 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -5,7 +5,7 @@ var r20 = /%20/g, rCRLF = /\r?\n/g, rhash = /#.*$/, rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL - rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, + rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, // #7653, #8125, #8152: local protocol detection rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/, rnoContent = /^(?:GET|HEAD)$/,