Changeset 3989
- Timestamp:
- 11/30/07 21:36:49 (8 months ago)
- Location:
- trunk/jquery
- Files:
-
- 3 modified
-
src/fx.js (modified) (3 diffs)
-
test/data/testsuite.css (modified) (1 diff)
-
test/unit/fx.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/fx.js
r3958 r3989 147 147 }, 148 148 149 stop: function( ){149 stop: function(clearQueue, gotoEnd){ 150 150 var timers = jQuery.timers; 151 151 152 return this.each(function(){ 153 for ( var i = 0; i < timers.length; i++ ) 154 if ( timers[i].elem == this ) 155 timers.splice(i--, 1); 156 }).dequeue(); 152 if (clearQueue) 153 this.queue([]); 154 155 this.each(function(){ 156 // go in reverse order so anything added to the queue during the loop is ignored 157 for ( var i = timers.length - 1; i >= 0; i-- ) 158 if ( timers[i].elem == this ) { 159 if (gotoEnd) 160 // force the next step to be the last 161 timers[i](true); 162 timers.splice(i, 1); 163 } 164 }); 165 166 // start the next in the queue if the last step wasn't forced 167 if (!gotoEnd) 168 this.dequeue(); 169 170 return this; 157 171 } 158 172 … … 270 284 271 285 var self = this; 272 function t( ){273 return self.step( );286 function t(gotoEnd){ 287 return self.step(gotoEnd); 274 288 } 275 289 … … 323 337 324 338 // Each step of an animation 325 step: function( ){339 step: function(gotoEnd){ 326 340 var t = (new Date()).getTime(); 327 341 328 if ( t > this.options.duration + this.startTime ) {342 if ( gotoEnd || t > this.options.duration + this.startTime ) { 329 343 this.now = this.end; 330 344 this.pos = this.state = 1; -
trunk/jquery/test/data/testsuite.css
r2515 r3989 11 11 h2.pass { background-color: green; } 12 12 h2.fail { background-color: red; } 13 14 ol#tests > li > strong { cursor:pointer; } 13 15 14 16 div#fx-tests h4 { -
trunk/jquery/test/unit/fx.js
r3839 r3989 55 55 expect(3); 56 56 stop(); 57 reset(); 58 59 var foo = $("#foo")[0];60 var h = foo.style.height;61 62 $ ("#foo").slideUp(1000);57 58 var $foo = $("#nothiddendiv"); 59 var w = 0; 60 $foo.hide().width(200).width(); 61 62 $foo.animate({ width:'show' }, 1000); 63 63 setTimeout(function(){ 64 var n h = foo.style.height;65 ok( n h != h, "An animation occurred " + nh + " " + h);66 $ ("#foo").stop();67 68 n h = foo.style.height;69 ok( n h != h, "Stop didn't reset the animation " + nh + " " + h);64 var nw = $foo.width(); 65 ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); 66 $foo.stop(); 67 68 nw = $foo.width(); 69 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); 70 70 setTimeout(function(){ 71 equals( n h, foo.style.height, "The animation didn't continue" );71 equals( nw, $foo.width(), "The animation didn't continue" ); 72 72 start(); 73 73 }, 100); … … 75 75 }); 76 76 77 test("stop() - several in queue", function() { 78 expect(4); 79 stop(); 80 81 var $foo = $("#nothiddendiv"); 82 var w = 0; 83 $foo.hide().width(200).width(); 84 85 $foo.animate({ width:'show' }, 1000); 86 $foo.animate({ width:'hide' }, 1000); 87 $foo.animate({ width:'show' }, 1000); 88 setTimeout(function(){ 89 equals( $foo.queue().length, 3, "All 3 still in the queue" ); 90 var nw = $foo.width(); 91 ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); 92 $foo.stop(); 93 94 nw = $foo.width(); 95 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); 96 equals( $foo.queue().length, 2, "The next animation continued" ); 97 $foo.stop(true); 98 start(); 99 }, 100); 100 }); 101 102 test("stop(clearQueue)", function() { 103 expect(4); 104 stop(); 105 106 var $foo = $("#nothiddendiv"); 107 var w = 0; 108 $foo.hide().width(200).width(); 109 110 $foo.animate({ width:'show' }, 1000); 111 $foo.animate({ width:'hide' }, 1000); 112 $foo.animate({ width:'show' }, 1000); 113 setTimeout(function(){ 114 var nw = $foo.width(); 115 ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); 116 $foo.stop(true); 117 118 nw = $foo.width(); 119 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); 120 121 equals( $foo.queue().length, 0, "The animation queue was cleared" ); 122 setTimeout(function(){ 123 equals( nw, $foo.width(), "The animation didn't continue" ); 124 start(); 125 }, 100); 126 }, 100); 127 }); 128 129 test("stop(clearQueue, gotoEnd)", function() { 130 expect(3); 131 stop(); 132 133 var $foo = $("#nothiddendiv"); 134 var w = 0; 135 $foo.hide().width(200).width(); 136 137 $foo.animate({ width:'show' }, 1000); 138 $foo.animate({ width:'hide' }, 1000); 139 $foo.animate({ width:'show' }, 1000); 140 $foo.animate({ width:'hide' }, 1000); 141 setTimeout(function(){ 142 var nw = $foo.width(); 143 ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); 144 $foo.stop(false, true); 145 146 nw = $foo.width(); 147 equals( nw, 200, "Stop() reset the animation" ); 148 149 setTimeout(function(){ 150 equals( $foo.queue().length, 3, "The next animation continued" ); 151 $foo.stop(true); 152 start(); 153 }, 100); 154 }, 100); 155 }); 156 77 157 test("toggle()", function() { 78 158 expect(3); 79 159 var x = $("#foo"); 80 ok( x.is(":visible") );160 ok( x.is(":visible"), "is visible" ); 81 161 x.toggle(); 82 ok( x.is(":hidden") );162 ok( x.is(":hidden"), "is hidden" ); 83 163 x.toggle(); 84 ok( x.is(":visible") );164 ok( x.is(":visible"), "is visible again" ); 85 165 }); 86 166