effects.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  1. if ( jQuery.fx ) {
  2. module("effects", { teardown: moduleTeardown });
  3. test("sanity check", function() {
  4. expect(1);
  5. ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
  6. });
  7. test("show() basic", 2, function() {
  8. var div,
  9. hiddendiv = jQuery("div.hidden");
  10. hiddendiv.hide().show();
  11. equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
  12. div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
  13. equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
  14. // Clean up the detached node
  15. div.remove();
  16. QUnit.expectJqData(hiddendiv, "olddisplay");
  17. });
  18. test("show()", 27, function () {
  19. var div,
  20. hiddendiv = jQuery("div.hidden");
  21. equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
  22. hiddendiv.css("display", "block");
  23. equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
  24. hiddendiv.show();
  25. equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
  26. hiddendiv.css("display","");
  27. var displaysActual = [],
  28. displaysExpected = [];
  29. div = jQuery("#fx-queue div").slice(0, 4);
  30. div.show().each(function() {
  31. notEqual(this.style.display, "none", "don't change any <div> with display block");
  32. });
  33. var speeds = {
  34. "null speed": null,
  35. "undefined speed": undefined,
  36. "false speed": false
  37. };
  38. jQuery.each(speeds, function(name, speed) {
  39. var pass = true;
  40. div.hide().show(speed).each(function() {
  41. if ( this.style.display == "none" ) {
  42. pass = false;
  43. }
  44. });
  45. ok( pass, "Show with " + name);
  46. });
  47. jQuery.each(speeds, function(name, speed) {
  48. var pass = true;
  49. div.hide().show(speed, function() {
  50. pass = false;
  51. });
  52. ok( pass, "Show with " + name + " does not call animate callback" );
  53. });
  54. // Tolerate data from show()/hide()
  55. QUnit.expectJqData(div, "olddisplay");
  56. // #show-tests * is set display: none in CSS
  57. jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
  58. var old = jQuery("#test-table").show().css("display") !== "table";
  59. jQuery("#test-table").remove();
  60. var test = {
  61. "div" : "block",
  62. "p" : "block",
  63. "a" : "inline",
  64. "code" : "inline",
  65. "pre" : "block",
  66. "span" : "inline",
  67. "table" : old ? "block" : "table",
  68. "thead" : old ? "block" : "table-header-group",
  69. "tbody" : old ? "block" : "table-row-group",
  70. "tr" : old ? "block" : "table-row",
  71. "th" : old ? "block" : "table-cell",
  72. "td" : old ? "block" : "table-cell",
  73. "ul" : "block",
  74. "li" : old ? "block" : "list-item"
  75. };
  76. jQuery.each(test, function(selector, expected) {
  77. var elem = jQuery(selector, "#show-tests").show();
  78. equal( elem.css("display"), expected, "Show using correct display type for " + selector );
  79. });
  80. jQuery("#show-tests").remove();
  81. // Make sure that showing or hiding a text node doesn't cause an error
  82. jQuery("<div>test</div> text <span>test</span>").show().remove();
  83. jQuery("<div>test</div> text <span>test</span>").hide().remove();
  84. });
  85. test("show(Number) - other displays", function() {
  86. expect(15);
  87. QUnit.reset();
  88. stop();
  89. // #show-tests * is set display: none in CSS
  90. jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
  91. var old = jQuery("#test-table").show().css("display") !== "table",
  92. num = 0;
  93. jQuery("#test-table").remove();
  94. var test = {
  95. "div" : "block",
  96. "p" : "block",
  97. "a" : "inline",
  98. "code" : "inline",
  99. "pre" : "block",
  100. "span" : "inline",
  101. "table" : old ? "block" : "table",
  102. "thead" : old ? "block" : "table-header-group",
  103. "tbody" : old ? "block" : "table-row-group",
  104. "tr" : old ? "block" : "table-row",
  105. "th" : old ? "block" : "table-cell",
  106. "td" : old ? "block" : "table-cell",
  107. "ul" : "block",
  108. "li" : old ? "block" : "list-item"
  109. };
  110. jQuery.each(test, function(selector, expected) {
  111. var elem = jQuery(selector, "#show-tests").show(1, function() {
  112. equal( elem.css("display"), expected, "Show using correct display type for " + selector );
  113. if ( ++num === 15 ) {
  114. start();
  115. }
  116. });
  117. });
  118. jQuery("#show-tests").remove();
  119. });
  120. // Supports #7397
  121. test("Persist correct display value", function() {
  122. expect(3);
  123. QUnit.reset();
  124. stop();
  125. // #show-tests * is set display: none in CSS
  126. jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
  127. var $span = jQuery("#show-tests span"),
  128. displayNone = $span.css("display"),
  129. display = "", num = 0;
  130. $span.show();
  131. display = $span.css("display");
  132. $span.hide();
  133. $span.fadeIn(100, function() {
  134. equal($span.css("display"), display, "Expecting display: " + display);
  135. $span.fadeOut(100, function () {
  136. equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
  137. $span.fadeIn(100, function() {
  138. equal($span.css("display"), display, "Expecting display: " + display);
  139. start();
  140. });
  141. });
  142. });
  143. QUnit.expectJqData($span, "olddisplay");
  144. });
  145. test("animate(Hash, Object, Function)", function() {
  146. expect(1);
  147. stop();
  148. var hash = {opacity: "show"};
  149. var hashCopy = jQuery.extend({}, hash);
  150. jQuery("#foo").animate(hash, 0, function() {
  151. equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
  152. start();
  153. });
  154. });
  155. test("animate negative height", function() {
  156. expect(1);
  157. stop();
  158. jQuery("#foo").animate({ height: -100 }, 100, function() {
  159. equal( this.offsetHeight, 0, "Verify height." );
  160. start();
  161. });
  162. });
  163. test("animate negative margin", function() {
  164. expect(1);
  165. stop();
  166. jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
  167. equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
  168. start();
  169. });
  170. });
  171. test("animate negative margin with px", function() {
  172. expect(1);
  173. stop();
  174. jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
  175. equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
  176. start();
  177. });
  178. });
  179. test("animate negative padding", function() {
  180. expect(1);
  181. stop();
  182. jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
  183. equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
  184. start();
  185. });
  186. });
  187. test("animate block as inline width/height", function() {
  188. expect(3);
  189. var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
  190. expected = span.css("display");
  191. span.remove();
  192. if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
  193. stop();
  194. jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
  195. equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
  196. equal( this.offsetWidth, 42, "width was animated" );
  197. equal( this.offsetHeight, 42, "height was animated" );
  198. start();
  199. });
  200. // Browser doesn't support inline-block
  201. } else {
  202. ok( true, "Browser doesn't support inline-block" );
  203. ok( true, "Browser doesn't support inline-block" );
  204. ok( true, "Browser doesn't support inline-block" );
  205. }
  206. });
  207. test("animate native inline width/height", function() {
  208. expect(3);
  209. var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
  210. expected = span.css("display");
  211. span.remove();
  212. if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
  213. stop();
  214. jQuery("#foo").css({ display: "", width: "", height: "" })
  215. .append("<span>text</span>")
  216. .children("span")
  217. .animate({ width: 42, height: 42 }, 100, function() {
  218. equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
  219. equal( this.offsetWidth, 42, "width was animated" );
  220. equal( this.offsetHeight, 42, "height was animated" );
  221. start();
  222. });
  223. // Browser doesn't support inline-block
  224. } else {
  225. ok( true, "Browser doesn't support inline-block" );
  226. ok( true, "Browser doesn't support inline-block" );
  227. ok( true, "Browser doesn't support inline-block" );
  228. }
  229. });
  230. test( "animate block width/height", function() {
  231. expect( 3 );
  232. stop();
  233. jQuery("<div>").appendTo("#qunit-fixture").css({
  234. display: "block",
  235. width: 20,
  236. height: 20,
  237. paddingLeft: 60
  238. }).animate({
  239. width: 42,
  240. height: 42
  241. }, {
  242. duration: 100,
  243. step: function() {
  244. if ( jQuery( this ).width() > 42 ) {
  245. ok( false, "width was incorrectly augmented during animation" );
  246. }
  247. },
  248. complete: function() {
  249. equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
  250. equal( jQuery( this ).width(), 42, "width was animated" );
  251. equal( jQuery( this ).height(), 42, "height was animated" );
  252. start();
  253. }
  254. });
  255. });
  256. test("animate table width/height", function() {
  257. expect(1);
  258. stop();
  259. var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
  260. jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
  261. equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
  262. start();
  263. });
  264. });
  265. test("animate table-row width/height", function() {
  266. expect(3);
  267. stop();
  268. var tr = jQuery("#table")
  269. .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
  270. .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
  271. .find("tr");
  272. // IE<8 uses "block" instead of the correct display type
  273. var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
  274. tr.animate({ width: 10, height: 10 }, 100, function() {
  275. equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
  276. equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
  277. equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
  278. start();
  279. });
  280. });
  281. test("animate table-cell width/height", function() {
  282. expect(3);
  283. stop();
  284. var td = jQuery("#table")
  285. .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
  286. .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
  287. .find("td");
  288. // IE<8 uses "block" instead of the correct display type
  289. var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
  290. td.animate({ width: 10, height: 10 }, 100, function() {
  291. equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
  292. equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
  293. equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
  294. start();
  295. });
  296. });
  297. test("animate percentage(%) on width/height", function() {
  298. expect( 2 );
  299. var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
  300. .appendTo("#qunit-fixture").children("div");
  301. stop();
  302. $div.animate({ width: "25%", height: "25%" }, 13, function() {
  303. var $this = jQuery(this);
  304. equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
  305. equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
  306. start();
  307. });
  308. });
  309. test("animate resets overflow-x and overflow-y when finished", function() {
  310. expect(2);
  311. stop();
  312. jQuery("#foo")
  313. .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
  314. .animate({ width: 42, height: 42 }, 100, function() {
  315. equal( this.style.overflowX, "visible", "overflow-x is visible" );
  316. equal( this.style.overflowY, "auto", "overflow-y is auto" );
  317. start();
  318. });
  319. });
  320. /* // This test ends up being flaky depending upon the CPU load
  321. test("animate option (queue === false)", function () {
  322. expect(1);
  323. stop();
  324. var order = [];
  325. var $foo = jQuery("#foo");
  326. $foo.animate({width:"100px"}, 3000, function () {
  327. // should finish after unqueued animation so second
  328. order.push(2);
  329. deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
  330. start();
  331. });
  332. $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
  333. // short duration and out of queue so should finish first
  334. order.push(1);
  335. }});
  336. });
  337. */
  338. asyncTest( "animate option { queue: false }", function() {
  339. expect( 2 );
  340. var foo = jQuery( "#foo" );
  341. foo.animate({
  342. fontSize: "2em"
  343. }, {
  344. queue: false,
  345. duration: 10,
  346. complete: function() {
  347. ok( true, "Animation Completed" );
  348. start();
  349. }
  350. });
  351. equal( foo.queue().length, 0, "Queue is empty" );
  352. });
  353. asyncTest( "animate option { queue: true }", function() {
  354. expect( 2 );
  355. var foo = jQuery( "#foo" );
  356. foo.animate({
  357. fontSize: "2em"
  358. }, {
  359. queue: true,
  360. duration: 10,
  361. complete: function() {
  362. ok( true, "Animation Completed" );
  363. start();
  364. }
  365. });
  366. notEqual( foo.queue().length, 0, "Default queue is not empty" );
  367. });
  368. asyncTest( "animate option { queue: 'name' }", function() {
  369. expect( 5 );
  370. var foo = jQuery( "#foo" ),
  371. origWidth = parseFloat( foo.css("width") ),
  372. order = [];
  373. foo.animate( { width: origWidth + 100 }, {
  374. queue: "name",
  375. duration: 1,
  376. complete: function() {
  377. // second callback function
  378. order.push( 2 );
  379. equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
  380. equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
  381. }
  382. }).queue( "name", function( next ) {
  383. // last callback function
  384. deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
  385. start();
  386. });
  387. setTimeout( function() {
  388. // this is the first callback function that should be called
  389. order.push( 1 );
  390. equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
  391. equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
  392. foo.dequeue( "name" );
  393. }, 100 );
  394. });
  395. test("animate with no properties", function() {
  396. expect(2);
  397. var divs = jQuery("div"), count = 0;
  398. divs.animate({}, function(){
  399. count++;
  400. });
  401. equal( divs.length, count, "Make sure that callback is called for each element in the set." );
  402. stop();
  403. var foo = jQuery("#foo");
  404. foo.animate({});
  405. foo.animate({top: 10}, 100, function(){
  406. ok( true, "Animation was properly dequeued." );
  407. start();
  408. });
  409. });
  410. test("animate duration 0", function() {
  411. expect(11);
  412. stop();
  413. var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
  414. equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
  415. $elems.eq(0).animate( {a:1}, 0, function(){
  416. ok( true, "Animate a simple property." );
  417. counter++;
  418. });
  419. // Failed until [6115]
  420. equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
  421. equal( counter, 1, "One synchronic animations" );
  422. $elems.animate( { a:2 }, 0, function(){
  423. ok( true, "Animate a second simple property." );
  424. counter++;
  425. });
  426. equal( counter, 3, "Multiple synchronic animations" );
  427. $elems.eq(0).animate( {a:3}, 0, function(){
  428. ok( true, "Animate a third simple property." );
  429. counter++;
  430. });
  431. $elems.eq(1).animate( {a:3}, 200, function(){
  432. counter++;
  433. // Failed until [6115]
  434. equal( counter, 5, "One synchronic and one asynchronic" );
  435. start();
  436. });
  437. var $elem = jQuery("<div />");
  438. $elem.show(0, function(){
  439. ok(true, "Show callback with no duration");
  440. });
  441. $elem.hide(0, function(){
  442. ok(true, "Hide callback with no duration");
  443. });
  444. // manually clean up detached elements
  445. $elem.remove();
  446. });
  447. test("animate hyphenated properties", function() {
  448. expect(1);
  449. stop();
  450. jQuery("#foo")
  451. .css("font-size", 10)
  452. .animate({"font-size": 20}, 200, function() {
  453. equal( this.style.fontSize, "20px", "The font-size property was animated." );
  454. start();
  455. });
  456. });
  457. test("animate non-element", function() {
  458. expect(1);
  459. stop();
  460. var obj = { test: 0 };
  461. jQuery(obj).animate({test: 200}, 200, function(){
  462. equal( obj.test, 200, "The custom property should be modified." );
  463. start();
  464. });
  465. });
  466. test("stop()", function() {
  467. expect( 4 );
  468. stop();
  469. var $foo = jQuery("#foo"),
  470. tests = 2,
  471. w = 0;
  472. $foo.hide().css( "width", 200 )
  473. .animate( { "width": "show" }, 1500 );
  474. setTimeout(function() {
  475. var nw = $foo.css("width");
  476. notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
  477. $foo.stop();
  478. nw = $foo.css("width");
  479. notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
  480. setTimeout(function() {
  481. $foo.removeData();
  482. $foo.removeData(undefined, true);
  483. equal( nw, $foo.css("width"), "The animation didn't continue" );
  484. if ( --tests === 0 ) {
  485. start();
  486. }
  487. }, 100);
  488. }, 100);
  489. var $one = jQuery("#fadein");
  490. var $two = jQuery("#show");
  491. $one.fadeTo(100, 0, function() {
  492. $one.stop();
  493. });
  494. setTimeout(function() {
  495. $two.fadeTo(100, 0, function() {
  496. equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
  497. // Reset styles
  498. $one.add( $two ).css("opacity", "");
  499. if ( --tests === 0 ) {
  500. start();
  501. }
  502. });
  503. }, 50);
  504. });
  505. test("stop() - several in queue", function() {
  506. expect( 5 );
  507. var nw, time,
  508. $foo = jQuery( "#foo" ),
  509. w = 0;
  510. // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
  511. $foo.hide().css( "width", 800 );
  512. $foo.animate({ "width": "show" }, 400, "linear");
  513. $foo.animate({ "width": "hide" });
  514. $foo.animate({ "width": "show" });
  515. // could be replaced by something nicer using sinon.
  516. time = jQuery.now();
  517. while( time === jQuery.now() ) {}
  518. jQuery.fx.tick();
  519. equal( $foo.queue().length, 3, "3 in the queue" );
  520. nw = $foo.css( "width" );
  521. notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
  522. $foo.stop();
  523. equal( $foo.queue().length, 2, "2 in the queue" );
  524. nw = $foo.css( "width" );
  525. notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
  526. $foo.stop( true );
  527. equal( $foo.queue().length, 0, "0 in the queue" );
  528. });
  529. test("stop(clearQueue)", function() {
  530. expect(4);
  531. stop();
  532. var $foo = jQuery("#foo");
  533. var w = 0;
  534. $foo.hide().css( "width", 200 ).css("width");
  535. $foo.animate({ "width": "show" }, 1000);
  536. $foo.animate({ "width": "hide" }, 1000);
  537. $foo.animate({ "width": "show" }, 1000);
  538. setTimeout(function(){
  539. var nw = $foo.css("width");
  540. ok( parseFloat( nw ) != w, "An animation occurred " + nw + " " + w + "px");
  541. $foo.stop(true);
  542. nw = $foo.css("width");
  543. ok( parseFloat( nw ) != w, "Stop didn't reset the animation " + nw + " " + w + "px");
  544. equal( $foo.queue().length, 0, "The animation queue was cleared" );
  545. setTimeout(function(){
  546. equal( nw, $foo.css("width"), "The animation didn't continue" );
  547. start();
  548. }, 100);
  549. }, 100);
  550. });
  551. test("stop(clearQueue, gotoEnd)", function() {
  552. expect(1);
  553. stop();
  554. var $foo = jQuery("#foo");
  555. var w = 0;
  556. $foo.hide().css( "width", 200 ).css("width");
  557. $foo.animate({ width: "show" }, 1000);
  558. $foo.animate({ width: "hide" }, 1000);
  559. $foo.animate({ width: "show" }, 1000);
  560. $foo.animate({ width: "hide" }, 1000);
  561. setTimeout(function(){
  562. var nw = $foo.css("width");
  563. ok( parseFloat( nw ) != w, "An animation occurred " + nw + " " + w + "px");
  564. $foo.stop(false, true);
  565. nw = $foo.css("width");
  566. // Disabled, being flaky
  567. //equal( nw, 1, "Stop() reset the animation" );
  568. setTimeout(function(){
  569. // Disabled, being flaky
  570. //equal( $foo.queue().length, 2, "The next animation continued" );
  571. $foo.stop(true);
  572. start();
  573. }, 100);
  574. }, 100);
  575. });
  576. asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
  577. expect( 3 );
  578. var saved,
  579. foo = jQuery("#foo").css({ width: 200, height: 200 });
  580. foo.animate({
  581. width: 400
  582. },{
  583. duration: 500,
  584. complete: function() {
  585. equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
  586. equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
  587. start();
  588. }
  589. });
  590. foo.animate({
  591. height: 400
  592. },{
  593. duration: 1000,
  594. queue: "height"
  595. }).dequeue("height").stop( "height", false, true );
  596. equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
  597. foo.animate({
  598. height: 200
  599. },{
  600. duration: 1000,
  601. queue: "height"
  602. }).dequeue( "height" ).stop( "height", false, false );
  603. saved = parseFloat( foo.css("height") );
  604. });
  605. test("toggle()", function() {
  606. expect(6);
  607. var x = jQuery("#foo");
  608. ok( x.is(":visible"), "is visible" );
  609. x.toggle();
  610. ok( x.is(":hidden"), "is hidden" );
  611. x.toggle();
  612. ok( x.is(":visible"), "is visible again" );
  613. x.toggle(true);
  614. ok( x.is(":visible"), "is visible" );
  615. x.toggle(false);
  616. ok( x.is(":hidden"), "is hidden" );
  617. x.toggle(true);
  618. ok( x.is(":visible"), "is visible again" );
  619. });
  620. test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
  621. var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
  622. color: "#ABC",
  623. border: "5px solid black",
  624. left: "auto",
  625. marginBottom: "-11000px"
  626. })[0];
  627. equal(
  628. ( new jQuery.fx( div, {}, "color" ) ).cur(),
  629. jQuery.css( div, "color" ),
  630. "Return the same value as jQuery.css for complex properties (bug #7912)"
  631. );
  632. strictEqual(
  633. ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
  634. 5,
  635. "Return simple values parsed as Float"
  636. );
  637. // backgroundPosition actually returns 0% 0% in most browser
  638. // this fakes a "" return
  639. // hook now gets called twice because Tween will grab the current
  640. // value as it is being newed
  641. jQuery.cssHooks.backgroundPosition = {
  642. get: function() {
  643. ok( true, "hook used" );
  644. return "";
  645. }
  646. };
  647. strictEqual(
  648. ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
  649. 0,
  650. "Return 0 when jQuery.css returns an empty string"
  651. );
  652. delete jQuery.cssHooks.backgroundPosition;
  653. strictEqual(
  654. ( new jQuery.fx( div, {}, "left" ) ).cur(),
  655. 0,
  656. "Return 0 when jQuery.css returns 'auto'"
  657. );
  658. equal(
  659. ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
  660. -11000,
  661. "support negative values < -10000 (bug #7193)"
  662. );
  663. jQuery( div ).remove();
  664. });
  665. test("Overflow and Display", function() {
  666. expect(4);
  667. stop();
  668. var
  669. testClass = jQuery.makeTest("Overflow and Display")
  670. .addClass("overflow inline"),
  671. testStyle = jQuery.makeTest("Overflow and Display (inline style)")
  672. .css({ overflow: "visible", display: "inline" }),
  673. remaining = 2,
  674. done = function() {
  675. equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
  676. equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
  677. if ( --remaining === 0 ) {
  678. start();
  679. }
  680. };
  681. testClass.add( testStyle )
  682. .addClass("widewidth")
  683. .text("Some sample text.")
  684. .before("text before")
  685. .after("text after")
  686. .animate({ opacity: 0.5 }, "slow", done );
  687. });
  688. jQuery.each({
  689. "CSS Auto": function( elem, prop ) {
  690. jQuery( elem ).addClass( "auto" + prop )
  691. .text( "This is a long string of text." );
  692. return "";
  693. },
  694. "JS Auto": function( elem, prop ) {
  695. jQuery( elem ).css( prop, "" )
  696. .text( "This is a long string of text." );
  697. return "";
  698. },
  699. "CSS 100": function( elem, prop ) {
  700. jQuery( elem ).addClass( "large" + prop );
  701. return "";
  702. },
  703. "JS 100": function( elem, prop ) {
  704. jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
  705. return prop === "opacity" ? 1 : 100;
  706. },
  707. "CSS 50": function( elem, prop ) {
  708. jQuery( elem ).addClass( "med" + prop );
  709. return "";
  710. },
  711. "JS 50": function( elem, prop ) {
  712. jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
  713. return prop === "opacity" ? 0.5 : 50;
  714. },
  715. "CSS 0": function( elem, prop ) {
  716. jQuery( elem ).addClass( "no" + prop );
  717. return "";
  718. },
  719. "JS 0": function( elem, prop ) {
  720. jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
  721. return 0;
  722. }
  723. }, function( fn, f ) {
  724. jQuery.each({
  725. "show": function( elem, prop ) {
  726. jQuery( elem ).hide( ).addClass( "wide" + prop );
  727. return "show";
  728. },
  729. "hide": function( elem, prop ) {
  730. jQuery( elem ).addClass( "wide" + prop );
  731. return "hide";
  732. },
  733. "100": function( elem, prop ) {
  734. jQuery( elem ).addClass( "wide" + prop );
  735. return prop == "opacity" ? 1 : 100;
  736. },
  737. "50": function( elem, prop ) {
  738. return prop == "opacity" ? 0.50 : 50;
  739. },
  740. "0": function( elem, prop ) {
  741. jQuery( elem ).addClass( "noback" );
  742. return 0;
  743. }
  744. }, function( tn, t ) {
  745. test(fn + " to " + tn, function() {
  746. var elem = jQuery.makeTest( fn + " to " + tn );
  747. var t_w = t( elem, "width" );
  748. var f_w = f( elem, "width" );
  749. var t_h = t( elem, "height" );
  750. var f_h = f( elem, "height" );
  751. var t_o = t( elem, "opacity" );
  752. var f_o = f( elem, "opacity" );
  753. if ( f_o === "" ) {
  754. f_o = 1;
  755. }
  756. var num = 0;
  757. // TODO: uncrowd this
  758. if ( t_h == "show" ) {num++;}
  759. if ( t_w == "show" ) {num++;}
  760. if ( t_w == "hide" || t_w == "show" ) {num++;}
  761. if ( t_h == "hide" || t_h == "show" ) {num++;}
  762. if ( t_o == "hide" || t_o == "show" ) {num++;}
  763. if ( t_w == "hide" ) {num++;}
  764. if ( t_o.constructor == Number ) {num += 2;}
  765. if ( t_w.constructor == Number ) {num += 2;}
  766. if ( t_h.constructor == Number ) {num +=2;}
  767. expect( num );
  768. stop();
  769. var anim = { width: t_w, height: t_h, opacity: t_o };
  770. elem.animate(anim, 50);
  771. jQuery.when( elem ).done(function( elem ) {
  772. elem = elem[ 0 ];
  773. if ( t_w == "show" ) {
  774. equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
  775. }
  776. if ( t_w == "hide" || t_w == "show" ) {
  777. 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 );
  778. }
  779. if ( t_h == "hide" || t_h == "show" ) {
  780. 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 );
  781. }
  782. var cur_o = jQuery.style(elem, "opacity");
  783. if ( f_o !== jQuery.css(elem, "opacity") ) {
  784. f_o = f( elem, "opacity" );
  785. }
  786. // The only time an _empty_string_ will be matched is in IE
  787. // otherwise, the correct values will be tested as usual
  788. if ( f_o === "" ) {
  789. f_o = 1;
  790. }
  791. // See above
  792. if ( cur_o === "" ) {
  793. cur_o = 1;
  794. }
  795. if ( t_o == "hide" || t_o == "show" ) {
  796. equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
  797. }
  798. if ( t_w == "hide" ) {
  799. equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
  800. }
  801. if ( t_o.constructor == Number ) {
  802. equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
  803. ok( jQuery.css(elem, "opacity") !== "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
  804. }
  805. if ( t_w.constructor == Number ) {
  806. equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
  807. var cur_w = jQuery.css( elem,"width" );
  808. ok( elem.style.width !== "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
  809. }
  810. if ( t_h.constructor == Number ) {
  811. equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
  812. var cur_h = jQuery.css( elem,"height" );
  813. ok( elem.style.height !== "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
  814. }
  815. if ( t_h == "show" ) {
  816. var old_h = jQuery.css( elem, "height" );
  817. jQuery( elem ).append("<br/>Some more text<br/>and some more...");
  818. if ( /Auto/.test( fn ) ) {
  819. notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
  820. } else {
  821. equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
  822. }
  823. }
  824. // manually remove generated element
  825. jQuery( elem ).remove();
  826. start();
  827. });
  828. });
  829. });
  830. });
  831. asyncTest("Effects chaining", function() {
  832. var remaining = 16,
  833. shrinkwrap = jQuery.support.shrinkWrapBlocks,
  834. props = [ "opacity", "height", "width", "display", "overflow" ],
  835. setup = function( name, selector, hiddenOverflow ) {
  836. var $el = jQuery( selector );
  837. return $el.data( getProps( $el[0], hiddenOverflow ) ).data( "name", name );
  838. },
  839. assert = function() {
  840. var data = jQuery.data( this ),
  841. name = data.name;
  842. delete data.name;
  843. deepEqual( getProps( this ), data, name );
  844. jQuery.removeData( this );
  845. if ( --remaining === 0 ) {
  846. start();
  847. }
  848. },
  849. getProps = function( el, hiddenOverflow ) {
  850. var obj = {};
  851. jQuery.each( props, function( i, prop ) {
  852. obj[ prop ] = prop === "overflow" && hiddenOverflow ? "hidden" : el.style[ prop ] || jQuery.css( el, prop );
  853. });
  854. return obj;
  855. };
  856. expect( remaining );
  857. // We need to pass jQuery.support.shrinkWrapBlocks for all methods that
  858. // set overflow hidden (slide* and show/hide with speed)
  859. setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", assert );
  860. setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", assert );
  861. setup( ".hide().show()", "#show div", shrinkwrap ).hide("fast").show( "fast", assert );
  862. setup( ".show().hide()", "#hide div", shrinkwrap ).show("fast").hide( "fast", assert );
  863. setup( ".show().hide(easing)", "#easehide div", shrinkwrap ).show("fast").hide( "fast", "linear", assert );
  864. setup( ".toggle().toggle() - in", "#togglein div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
  865. setup( ".toggle().toggle() - out", "#toggleout div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
  866. setup( ".toggle().toggle(easing) - out", "#easetoggleout div", shrinkwrap ).toggle("fast").toggle( "fast", "linear", assert );
  867. setup( ".slideDown().slideUp()", "#slidedown div", shrinkwrap ).slideDown("fast").slideUp( "fast", assert );
  868. setup( ".slideUp().slideDown()", "#slideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", assert );
  869. setup( ".slideUp().slideDown(easing)", "#easeslideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", "linear", assert );
  870. setup( ".slideToggle().slideToggle() - in", "#slidetogglein div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
  871. setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
  872. setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", assert );
  873. setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", assert );
  874. setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
  875. });
  876. jQuery.makeTest = function( text ){
  877. var elem = jQuery("<div></div>")
  878. .attr( "id", "test" + jQuery.makeTest.id++ )
  879. .addClass("box");
  880. jQuery("<h4></h4>")
  881. .text( text )
  882. .appendTo("#fx-tests")
  883. .after( elem );
  884. return elem;
  885. };
  886. jQuery.makeTest.id = 1;
  887. test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
  888. expect(4);
  889. stop();
  890. var $checkedtest = jQuery("#checkedtest");
  891. // IE6 was clearing "checked" in jQuery(elem).show("fast");
  892. $checkedtest.hide().show("fast", function() {
  893. ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
  894. ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
  895. ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
  896. ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
  897. start();
  898. });
  899. });
  900. test( "interrupt toggle", function() {
  901. expect( 24 );
  902. stop();
  903. var longDuration = 2000,
  904. shortDuration = 500,
  905. remaining = 0,
  906. $elems = jQuery(".chain-test"),
  907. finish = function() {
  908. if ( !(--remaining) ) {
  909. start();
  910. }
  911. };
  912. jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
  913. var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
  914. // Don't end test until we're done with this element
  915. remaining++;
  916. // Save original property value for comparison
  917. jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
  918. // Expect olddisplay data from our .hide() call below
  919. QUnit.expectJqData( this, "olddisplay" );
  920. });
  921. // Interrupt a hiding toggle
  922. $methodElems[ method ]( longDuration );
  923. setTimeout(function() {
  924. $methodElems.stop().each(function() {
  925. notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
  926. });
  927. // Restore
  928. $methodElems[ method ]( shortDuration, function() {
  929. var id = this.id,
  930. $elem = jQuery( this ),
  931. startVal = $elem.data("startVal");
  932. $elem.removeData("startVal");
  933. equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
  934. // Interrupt a showing toggle
  935. $elem.hide()[ method ]( longDuration );
  936. setTimeout(function() {
  937. $elem.stop();
  938. notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
  939. // Restore
  940. $elem[ method ]( shortDuration, function() {
  941. equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
  942. finish();
  943. });
  944. }, shortDuration );
  945. });
  946. }, shortDuration );
  947. });
  948. });
  949. test("animate with per-property easing", function(){
  950. expect(5);
  951. stop();
  952. var data = { a:0, b:0, c:0 },
  953. _test1_called = false,
  954. _test2_called = false,
  955. _default_test_called = false,
  956. props = {
  957. a: [ 100, "_test1" ],
  958. b: [ 100, "_test2" ],
  959. c: 100
  960. };
  961. jQuery.easing["_test1"] = function(p) {
  962. _test1_called = true;
  963. return p;
  964. };
  965. jQuery.easing["_test2"] = function(p) {
  966. _test2_called = true;
  967. return p;
  968. };
  969. jQuery.easing["_default_test"] = function(p) {
  970. _default_test_called = true;
  971. return p;
  972. };
  973. jQuery(data).animate( props, 400, "_default_test", function(){
  974. start();
  975. ok( _test1_called, "Easing function (_test1) called" );
  976. ok( _test2_called, "Easing function (_test2) called" );
  977. ok( _default_test_called, "Easing function (_default) called" );
  978. equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
  979. equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
  980. });
  981. });
  982. test("animate with CSS shorthand properties", function(){
  983. expect(11);
  984. stop();
  985. var _default_count = 0,
  986. _special_count = 0,
  987. propsBasic = { "padding": "10 20 30" },
  988. propsSpecial = { "padding": [ "1 2 3", "_special" ] };
  989. jQuery.easing._default = function(p) {
  990. if ( p >= 1 ) {
  991. _default_count++;
  992. }
  993. return p;
  994. };
  995. jQuery.easing._special = function(p) {
  996. if ( p >= 1 ) {
  997. _special_count++;
  998. }
  999. return p;
  1000. };
  1001. jQuery("#foo")
  1002. .animate( propsBasic, 200, "_default", function() {
  1003. equal( this.style.paddingTop, "10px", "padding-top was animated" );
  1004. equal( this.style.paddingLeft, "20px", "padding-left was animated" );
  1005. equal( this.style.paddingRight, "20px", "padding-right was animated" );
  1006. equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
  1007. equal( _default_count, 4, "per-animation default easing called for each property" );
  1008. _default_count = 0;
  1009. })
  1010. .animate( propsSpecial, 200, "_default", function() {
  1011. equal( this.style.paddingTop, "1px", "padding-top was animated again" );
  1012. equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
  1013. equal( this.style.paddingRight, "2px", "padding-right was animated again" );
  1014. equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
  1015. equal( _default_count, 0, "per-animation default easing not called" );
  1016. equal( _special_count, 4, "special easing called for each property" );
  1017. jQuery(this).css("padding", "0");
  1018. delete jQuery.easing._default;
  1019. delete jQuery.easing._special;
  1020. start();
  1021. });
  1022. });
  1023. test("hide hidden elements, with animation (bug #7141)", function() {
  1024. expect(3);
  1025. QUnit.reset();
  1026. stop();
  1027. var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
  1028. equal( div.css("display"), "none", "Element is hidden by default" );
  1029. div.hide(1, function () {
  1030. ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
  1031. div.show(1, function () {
  1032. equal( div.css("display"), "block", "Show a double-hidden element" );
  1033. start();
  1034. });
  1035. });
  1036. });
  1037. test("animate unit-less properties (#4966)", 2, function() {
  1038. stop();
  1039. var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
  1040. equal( div.css( "z-index" ), "0", "z-index is 0" );
  1041. div.animate({ zIndex: 2 }, function() {
  1042. equal( div.css( "z-index" ), "2", "z-index is 2" );
  1043. start();
  1044. });
  1045. });
  1046. test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
  1047. expect( 6 );
  1048. stop();
  1049. var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
  1050. .appendTo( "#qunit-fixture" );
  1051. function cssInt( prop ) {
  1052. return parseInt( div.css( prop ), 10 );
  1053. }
  1054. equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
  1055. equal( cssInt( "left" ), 0, "Left is 0" );
  1056. div.animate({
  1057. left: 200,
  1058. marginLeft: 200,
  1059. opacity: 0
  1060. }, 2000);
  1061. setTimeout(function() {
  1062. var ml = cssInt( "marginLeft" ),
  1063. l = cssInt( "left" );
  1064. notEqual( ml, 0, "Margin left is not 0 after partial animate" );
  1065. notEqual( ml, 200, "Margin left is not 200 after partial animate" );
  1066. notEqual( l, 0, "Left is not 0 after partial animate" );
  1067. notEqual( l, 200, "Left is not 200 after partial animate" );
  1068. div.stop().remove();
  1069. start();
  1070. }, 500);
  1071. });
  1072. test("callbacks should fire in correct order (#9100)", function() {
  1073. expect( 1 );
  1074. stop();
  1075. var a = 1,
  1076. cb = 0,
  1077. $lis = jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
  1078. // The test will always pass if no properties are animated or if the duration is 0
  1079. .animate({fontSize: 12}, 13, function() {
  1080. a *= jQuery(this).data("operation") === "*2" ? 2 : a;
  1081. cb++;
  1082. if ( cb === 2 ) {
  1083. equal( a, 4, "test value has been *2 and _then_ ^2");
  1084. start();
  1085. }
  1086. });
  1087. });
  1088. asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
  1089. expect( 2 );
  1090. var foo = jQuery( "#foo" );
  1091. function testException() {
  1092. }
  1093. foo.animate({ height: 1 }, 1, function() {
  1094. throw new testException();
  1095. });
  1096. // this test thoroughly abuses undocumented methods - please feel free to update
  1097. // with any changes internally to these functions.
  1098. // make sure that the standard timer loop will NOT run.
  1099. jQuery.fx.stop();
  1100. setTimeout(function() {
  1101. // the first call to fx.tick should raise the callback exception
  1102. raises( jQuery.fx.tick, testException, "Exception was thrown" );
  1103. // the second call shouldn't
  1104. jQuery.fx.tick();
  1105. ok( true, "Test completed without throwing a second exception" );
  1106. start();
  1107. }, 1);
  1108. });
  1109. test("animate will scale margin properties individually", function() {
  1110. expect( 2 );
  1111. stop();
  1112. var foo = jQuery( "#foo" ).css({
  1113. "margin": 0,
  1114. "marginLeft": 100
  1115. });
  1116. ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
  1117. foo.animate({
  1118. "margin": 200
  1119. }).stop();
  1120. ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
  1121. // clean up for next test
  1122. foo.css({
  1123. "marginLeft": "",
  1124. "marginRight": "",
  1125. "marginTop": "",
  1126. "marginBottom": ""
  1127. });
  1128. start();
  1129. });
  1130. test("Do not append px to 'fill-opacity' #9548", 1, function() {
  1131. var $div = jQuery("<div>").appendTo("#qunit-fixture");
  1132. $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
  1133. equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'");
  1134. $div.remove();
  1135. });
  1136. });
  1137. // Start 1.8 Animation tests
  1138. asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
  1139. var testObject = {
  1140. "foo": 0,
  1141. "bar": 1,
  1142. "width": 100
  1143. },
  1144. testDest = {
  1145. "foo": 1,
  1146. "bar": 0,
  1147. "width": 200
  1148. };
  1149. var animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
  1150. animation.done(function() {
  1151. for ( var prop in testDest ) {
  1152. equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
  1153. }
  1154. animation.done(function() {
  1155. deepEqual( testObject, testDest, "No unexpected properties" );
  1156. start();
  1157. });
  1158. });
  1159. });
  1160. asyncTest( "Animate Option: step: function( percent, tween )", 1, function() {
  1161. var counter = {};
  1162. jQuery( "#foo" ).animate({
  1163. prop1: 1,
  1164. prop2: 2,
  1165. prop3: 3
  1166. }, {
  1167. duration: 1,
  1168. step: function( value, tween ) {
  1169. var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
  1170. // in case this is called multiple times for either, lets store it in
  1171. // 0 or 1 in the array
  1172. calls[ value === 0 ? 0 : 1 ] = value;
  1173. }
  1174. }).queue( function( next ) {
  1175. deepEqual( counter, {
  1176. prop1: [0, 1],
  1177. prop2: [0, 2],
  1178. prop3: [0, 3]
  1179. }, "Step function was called once at 0% and once at 100% for each property");
  1180. next();
  1181. start();
  1182. });
  1183. });
  1184. asyncTest( "Animate callbacks have correct context", 2, function() {
  1185. var foo = jQuery( "#foo" );
  1186. foo.animate({
  1187. height: 10
  1188. }, 10, function() {
  1189. equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
  1190. }).stop( true, true );
  1191. foo.animate({
  1192. height: 100
  1193. }, 10, function() {
  1194. equal( foo[ 0 ], this, "Complete callback `this` is element" );
  1195. start();
  1196. });
  1197. });
  1198. asyncTest( "User supplied callback called after show when fx off (#8892)", 2, function() {
  1199. var foo = jQuery( "#foo" );
  1200. jQuery.fx.off = true;
  1201. foo.hide();
  1202. foo.fadeIn( 500, function() {
  1203. ok( jQuery( this ).is( ":visible" ), "Element is visible in callback" );
  1204. foo.fadeOut( 500, function() {
  1205. ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
  1206. jQuery.fx.off = false;
  1207. start();
  1208. });
  1209. });
  1210. });
  1211. test( "animate should set display for disconnected nodes", function() {
  1212. expect( 18 );
  1213. var i = 0,
  1214. methods = {
  1215. toggle: [ 1 ],
  1216. slideToggle: [],
  1217. fadeIn: [],
  1218. fadeTo: [ "fast", 0.5 ],
  1219. slideDown: [ "fast" ],
  1220. show: [ 1 ],
  1221. animate: [{ width: "show" }]
  1222. },
  1223. $divTest = jQuery("<div>test</div>"),
  1224. // parentNode = null
  1225. $divEmpty = jQuery("<div/>"),
  1226. $divNone = jQuery("<div style='display: none;'/>"),
  1227. $divInline = jQuery("<div style='display: inline;'/>");
  1228. strictEqual( $divTest.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" );
  1229. strictEqual( $divEmpty.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = null" );
  1230. strictEqual( $divNone.show()[ 0 ].style.display, "block", "show() should change display if it already set to none" );
  1231. strictEqual( $divInline.show()[ 0 ].style.display, "inline", "show() should not change display if it already set" );
  1232. QUnit.expectJqData( $divTest[ 0 ], "olddisplay" );
  1233. QUnit.expectJqData( $divEmpty[ 0 ], "olddisplay" );
  1234. QUnit.expectJqData( $divNone[ 0 ], "olddisplay" );
  1235. stop();
  1236. jQuery.each( methods, function( name, opt ) {
  1237. jQuery.each([
  1238. // parentNode = document fragment
  1239. jQuery("<div>test</div>"),
  1240. // parentNode = null
  1241. jQuery("<div/>")
  1242. ], function() {
  1243. var callback = [function () {
  1244. strictEqual( this.style.display, "block", "set display to block with " + name );
  1245. QUnit.expectJqData( this, "olddisplay" );
  1246. if ( ++i === 14 ) {
  1247. start();
  1248. }
  1249. }];
  1250. jQuery.fn[ name ].apply( this, opt.concat( callback ) );
  1251. });
  1252. });
  1253. });
  1254. asyncTest("Animation callback should not show animated element as animated (#7157)", 1, function() {
  1255. var foo = jQuery( "#foo" );
  1256. foo.animate({
  1257. opacity: 0
  1258. }, 100, function() {
  1259. ok( !foo.is(":animated"), "The element is not animated" );
  1260. start();
  1261. });
  1262. });
  1263. asyncTest( "hide called on element within hidden parent should set display to none (#10045)", 3, function() {
  1264. var hidden = jQuery(".hidden"),
  1265. elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>");
  1266. hidden.append( elems );
  1267. jQuery.when(
  1268. elems.eq( 0 ).hide(),
  1269. elems.eq( 1 ).hide( 0 ),
  1270. elems.eq( 2 ).hide( 1 )
  1271. ).done(function() {
  1272. strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
  1273. strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
  1274. strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
  1275. elems.remove();
  1276. start();
  1277. });
  1278. });
  1279. asyncTest( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() {
  1280. var foo = jQuery("#foo"),
  1281. i = 0,
  1282. elems = jQuery();
  1283. for ( ; i < 5; i++ ) {
  1284. elems = elems.add("<div style='width:0;height:0;'></div>");
  1285. }
  1286. foo.append( elems );
  1287. jQuery.when(
  1288. elems.eq( 0 ).hide(),
  1289. elems.eq( 1 ).hide( jQuery.noop ),
  1290. elems.eq( 2 ).hide( 1 ),
  1291. elems.eq( 3 ).fadeOut(),
  1292. elems.eq( 4 ).slideUp()
  1293. ).done(function() {
  1294. strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
  1295. strictEqual( elems.get( 1 ).style.display, "none",
  1296. "hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
  1297. strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element width height and width = 0 should set display to none" );
  1298. strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
  1299. strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
  1300. start();
  1301. });
  1302. });
  1303. asyncTest( "Handle queue:false promises", 10, function() {
  1304. var foo = jQuery( "#foo" ).clone().andSelf(),
  1305. step = 1;
  1306. foo.animate({
  1307. top: 1
  1308. }, {
  1309. duration: 10,
  1310. queue: false,
  1311. complete: function() {
  1312. ok( step++ <= 2, "Step one or two" );
  1313. }
  1314. }).animate({
  1315. bottom: 1
  1316. }, {
  1317. duration: 10,
  1318. complete: function() {
  1319. ok( step > 2 && step < 5, "Step three or four" );
  1320. step++;
  1321. }
  1322. });
  1323. foo.promise().done( function() {
  1324. equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
  1325. foo.animate({
  1326. top: 10
  1327. }, {
  1328. duration: 10,
  1329. complete: function() {
  1330. ok( step > 5 && step < 8, "Step six or seven" );
  1331. step++;
  1332. }
  1333. }).animate({
  1334. bottom: 10
  1335. }, {
  1336. duration: 10,
  1337. queue: false,
  1338. complete: function() {
  1339. ok( step > 7 && step < 10, "Step eight or nine" );
  1340. step++;
  1341. }
  1342. }).promise().done( function() {
  1343. equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
  1344. start();
  1345. });
  1346. });
  1347. });
  1348. asyncTest( "multiple unqueued and promise", 4, function() {
  1349. var foo = jQuery( "#foo" ),
  1350. step = 1;
  1351. foo.animate({
  1352. marginLeft: 300
  1353. }, {
  1354. duration: 500,
  1355. queue: false,
  1356. complete: function() {
  1357. strictEqual( step++, 2, "Step 2" );
  1358. }
  1359. }).animate({
  1360. top: 100
  1361. }, {
  1362. duration: 1000,
  1363. queue: false,
  1364. complete: function() {
  1365. strictEqual( step++, 3, "Step 3" );
  1366. }
  1367. }).animate({}, {
  1368. duration: 2000,
  1369. queue: false,
  1370. complete: function() {
  1371. // no properties is a non-op and finishes immediately
  1372. strictEqual( step++, 1, "Step 1" );
  1373. }
  1374. }).promise().done( function() {
  1375. strictEqual( step++, 4, "Step 4" );
  1376. start();
  1377. });
  1378. });
  1379. asyncTest( "animate does not change start value for non-px animation (#7109)", 1, function() {
  1380. var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
  1381. child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
  1382. actual = parseFloat( child.css( "width" ) ),
  1383. computed = [];
  1384. child.animate({ width: "0%" }, {
  1385. duration: 1,
  1386. step: function() {
  1387. computed.push( parseFloat( child.css( "width" ) ) );
  1388. }
  1389. }).queue( function( next ) {
  1390. var ratio = computed[ 0 ] / actual;
  1391. ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
  1392. next();
  1393. parent.remove();
  1394. start();
  1395. });
  1396. });
  1397. asyncTest( "non-px animation handles non-numeric start (#11971)", 2, function() {
  1398. var foo = jQuery("#foo"),
  1399. initial = foo.css("backgroundPositionX");
  1400. if ( !initial ) {
  1401. expect(1);
  1402. ok( true, "Style property not understood" );
  1403. start();
  1404. return;
  1405. }
  1406. foo.animate({ backgroundPositionX: "42%" }, {
  1407. duration: 1,
  1408. progress: function( anim, percent ) {
  1409. if ( percent ) {
  1410. return;
  1411. }
  1412. if ( parseFloat( initial ) ) {
  1413. equal( jQuery.style( this, "backgroundPositionX" ), initial, "Numeric start preserved" );
  1414. } else {
  1415. equal( jQuery.style( this, "backgroundPositionX" ), "0%", "Non-numeric start zeroed" );
  1416. }
  1417. },
  1418. done: function() {
  1419. equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
  1420. start();
  1421. }
  1422. });
  1423. });
  1424. asyncTest("Animation callbacks (#11797)", 15, function() {
  1425. var targets = jQuery("#foo").children(),
  1426. done = false,
  1427. expectedProgress = 0;
  1428. targets.eq( 0 ).animate( {}, {
  1429. duration: 1,
  1430. start: function() {
  1431. ok( true, "empty: start" );
  1432. },
  1433. progress: function( anim, percent ) {
  1434. equal( percent, 0, "empty: progress 0" );
  1435. },
  1436. done: function() {
  1437. ok( true, "empty: done" );
  1438. },
  1439. fail: function() {
  1440. ok( false, "empty: fail" );
  1441. },
  1442. always: function() {
  1443. ok( true, "empty: always" );
  1444. done = true;
  1445. }
  1446. });
  1447. ok( done, "empty: done immediately" );
  1448. done = false;
  1449. targets.eq( 1 ).animate({
  1450. opacity: 0
  1451. }, {
  1452. duration: 1,
  1453. start: function() {
  1454. ok( true, "stopped: start" );
  1455. },
  1456. progress: function( anim, percent ) {
  1457. equal( percent, 0, "stopped: progress 0" );
  1458. },
  1459. done: function() {
  1460. ok( false, "stopped: done" );
  1461. },
  1462. fail: function() {
  1463. ok( true, "stopped: fail" );
  1464. },
  1465. always: function() {
  1466. ok( true, "stopped: always" );
  1467. done = true;
  1468. }
  1469. }).stop();
  1470. ok( done, "stopped: stopped immediately" );
  1471. targets.eq( 2 ).animate({
  1472. opacity: 0
  1473. }, {
  1474. duration: 1,
  1475. start: function() {
  1476. ok( true, "async: start" );
  1477. },
  1478. progress: function( anim, percent ) {
  1479. // occasionally the progress handler is called twice in first frame.... *shrug*
  1480. if ( percent === 0 && expectedProgress === 1 ) {
  1481. return;
  1482. }
  1483. equal( percent, expectedProgress, "async: progress " + expectedProgress );
  1484. // once at 0, once at 1
  1485. expectedProgress++;
  1486. },
  1487. done: function() {
  1488. ok( true, "async: done" );
  1489. },
  1490. fail: function() {
  1491. ok( false, "async: fail" );
  1492. },
  1493. always: function() {
  1494. ok( true, "async: always" );
  1495. start();
  1496. }
  1497. });
  1498. });
  1499. test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() {
  1500. jQuery.each( [ "height", "width" ], function( _, prop ) {
  1501. jQuery.each( [ 100, 0 ], function( _, value ) {
  1502. var div = jQuery("<div>").css( "overflow", "auto" ),
  1503. props = {};
  1504. props[ prop ] = value;
  1505. div.animate( props, 1 );
  1506. equal( div.css( "overflow" ), "hidden",
  1507. "overflow: hidden set when animating " + prop + " to " + value );
  1508. div.stop();
  1509. if ( jQuery.support.shrinkWrapBlocks ) {
  1510. ok( true, "cannot restore overflow, shrinkWrapBlocks" );
  1511. } else {
  1512. equal( div.css( "overflow" ), "auto",
  1513. "overflow: auto restored after animating " + prop + " to " + value );
  1514. }
  1515. });
  1516. });
  1517. });
  1518. test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
  1519. var lastVal, current,
  1520. tmp = jQuery({
  1521. test: 0
  1522. });
  1523. expect( 3 );
  1524. tmp.animate({
  1525. test: 100
  1526. }, {
  1527. step: function( p, fx ) {
  1528. ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
  1529. lastVal = fx.now;
  1530. }
  1531. });
  1532. current = jQuery.now();
  1533. // intentionally empty, we want to spin wheels until the time changes.
  1534. while ( current === jQuery.now() ) { }
  1535. // now that we have a new time, run another tick
  1536. jQuery.fx.tick();
  1537. current = jQuery.now();
  1538. // intentionally empty, we want to spin wheels until the time changes.
  1539. while ( current === jQuery.now() ) { }
  1540. jQuery.fx.tick();
  1541. tmp.stop();
  1542. });
  1543. test( "Animations with 0 duration don't ease (#12273)", 1, function() {
  1544. jQuery.easing.test = function() {
  1545. ok( false, "Called easing" );
  1546. };
  1547. jQuery( "#foo" ).animate({
  1548. height: 100
  1549. }, {
  1550. duration: 0,
  1551. easing: "test",
  1552. complete: function() {
  1553. equal( jQuery( this ).height(), 100, "Height is 100" );
  1554. }
  1555. });
  1556. delete jQuery.easing.test;
  1557. });
  1558. jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
  1559. // this test would look a lot better if we were using something to override
  1560. // the default timers
  1561. var duration = 1500;
  1562. asyncTest( "toggle state tests: " + method + " (#8685)", function() {
  1563. function secondToggle() {
  1564. var stopped = parseFloat( element.css( check ) );
  1565. tested = false;
  1566. element[ method ]({
  1567. duration: duration,
  1568. step: function( p, fx ) {
  1569. if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
  1570. tested = true;
  1571. equal( fx.start, stopped, check + " starts at " + stopped + " where it stopped" );
  1572. equal( fx.end, original, check + " ending value is " + original );
  1573. element.stop();
  1574. }
  1575. },
  1576. always: start
  1577. });
  1578. }
  1579. var tested,
  1580. original,
  1581. check = method === "slideToggle" ? "height" : "opacity",
  1582. element = jQuery("#foo").height( 200 );
  1583. expect( 4 );
  1584. element[ method ]({
  1585. duration: duration,
  1586. easing: "linear",
  1587. step: function( p, fx ) {
  1588. if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
  1589. tested = true;
  1590. original = fx.start;
  1591. ok( fx.start !== 0, check + " is starting at " + original + " on first toggle (non-zero)" );
  1592. equal( fx.end, 0, check + " is ending at 0 on first toggle" );
  1593. element.stop();
  1594. }
  1595. },
  1596. always: secondToggle
  1597. });
  1598. });
  1599. });
  1600. test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
  1601. var oldStart = jQuery.fx.start,
  1602. oldStop = jQuery.fx.stop,
  1603. foo = jQuery({ foo: 0 });
  1604. expect( 3 );
  1605. jQuery.fx.start = function() {
  1606. ok( true, "start called" );
  1607. };
  1608. jQuery.fx.stop = function() {
  1609. ok( true, "stop called" );
  1610. };
  1611. // calls start
  1612. foo.animate({ foo: 1 }, { queue: false });
  1613. // calls start
  1614. foo.animate({ foo: 2 }, { queue: false });
  1615. foo.stop();
  1616. // calls stop
  1617. jQuery.fx.tick();
  1618. // cleanup
  1619. jQuery.fx.start = oldStart;
  1620. jQuery.fx.stop = oldStop;
  1621. });
  1622. test( ".finish() completes all queued animations", function() {
  1623. var animations = {
  1624. top: 100,
  1625. left: 100,
  1626. height: 100,
  1627. width: 100
  1628. },
  1629. div = jQuery("<div>");
  1630. expect( 11 );
  1631. jQuery.each( animations, function( prop, value ) {
  1632. var anim = {};
  1633. anim[ prop ] = value;
  1634. // the delay shouldn't matter at all!
  1635. div.css( prop, 1 ).animate( anim, function() {
  1636. ok( true, "Called animation callback for " + prop );
  1637. }).delay( 100 );
  1638. });
  1639. equal( div.queue().length, 8, "8 animations in the queue" );
  1640. div.finish();
  1641. jQuery.each( animations, function( prop, value ) {
  1642. equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
  1643. });
  1644. equal( div.queue().length, 0, "empty queue when done" );
  1645. equal( div.is(":animated"), false, ":animated doesn't match" );
  1646. // cleanup
  1647. div.remove();
  1648. // leaves a "shadow timer" which does nothing around, need to force a tick
  1649. jQuery.fx.tick();
  1650. });
  1651. test( ".finish( false ) - unqueued animations", function() {
  1652. var animations = {
  1653. top: 100,
  1654. left: 100,
  1655. height: 100,
  1656. width: 100
  1657. },
  1658. div = jQuery("<div>");
  1659. expect( 10 );
  1660. jQuery.each( animations, function( prop, value ) {
  1661. var anim = {};
  1662. anim[ prop ] = value;
  1663. div.css( prop, 1 ).animate( anim, {
  1664. queue: false,
  1665. complete: function() {
  1666. ok( true, "Called animation callback for " + prop );
  1667. }
  1668. });
  1669. });
  1670. equal( div.queue().length, 0, "0 animations in the queue" );
  1671. div.finish( false );
  1672. jQuery.each( animations, function( prop, value ) {
  1673. equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
  1674. });
  1675. equal( div.is(":animated"), false, ":animated doesn't match" );
  1676. // cleanup
  1677. div.remove();
  1678. // leaves a "shadow timer" which does nothing around, need to force a tick
  1679. jQuery.fx.tick();
  1680. });
  1681. test( ".finish( \"custom\" ) - custom queue animations", function() {
  1682. var animations = {
  1683. top: 100,
  1684. left: 100,
  1685. height: 100,
  1686. width: 100
  1687. },
  1688. div = jQuery("<div>");
  1689. expect( 11 );
  1690. jQuery.each( animations, function( prop, value ) {
  1691. var anim = {};
  1692. anim[ prop ] = value;
  1693. div.css( prop, 1 ).animate( anim, {
  1694. queue: "custom",
  1695. complete: function() {
  1696. ok( true, "Called animation callback for " + prop );
  1697. }
  1698. });
  1699. });
  1700. equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
  1701. // start the first animation
  1702. div.dequeue( "custom" );
  1703. equal( div.is(":animated"), true, ":animated matches" );
  1704. div.finish( "custom" );
  1705. jQuery.each( animations, function( prop, value ) {
  1706. equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
  1707. });
  1708. equal( div.is(":animated"), false, ":animated doesn't match" );
  1709. // cleanup
  1710. div.remove();
  1711. // leaves a "shadow timer" which does nothing around, need to force a tick
  1712. jQuery.fx.tick();
  1713. });
  1714. test( ".finish() calls finish of custom queue functions", function() {
  1715. function queueTester( next ) {
  1716. }
  1717. var div = jQuery( "<div>" );
  1718. expect( 3 );
  1719. queueTester.finish = function() {
  1720. ok( true, "Finish called on custom queue function" );
  1721. };
  1722. div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
  1723. div.remove();
  1724. });
  1725. } // if ( jQuery.fx )