Best JavaScript code snippet using wpt
animation.js
Source:animation.js
1suite('animation', function() {2 setup(function() {3 webAnimations1.timeline._animations = [];4 });5 test('zero duration animation works', function() {6 tick(90);7 var a = document.body.animate([], 0);8 tick(100);9 assert.equal(a.startTime, 100);10 assert.equal(a.currentTime, 0);11 });12 test('playing works as expected', function() {13 tick(90);14 var a = document.body.animate([], 2000);15 tick(100);16 assert.equal(a.startTime, 100);17 assert.equal(a.currentTime, 0);18 tick(300);19 assert.equal(a.startTime, 100);20 assert.equal(a.currentTime, 200);21 });22 test('pause at start of play', function() {23 tick(90);24 var a = document.body.animate([], 2000);25 a.pause();26 tick(100);27 assert.equal(a.currentTime, 0);28 tick(300);29 a.play();30 assert.equal(a.currentTime, 0);31 tick(310);32 assert.equal(a.currentTime, 0);33 assert.equal(a.startTime, 310);34 var a = document.body.animate([], 2000);35 a.startTime = -690;36 a.pause();37 assert.equal(a.currentTime, null);38 tick(700);39 a.play();40 tick(701);41 assert.equal(a.currentTime, 1000);42 tick(800);43 assert.equal(a.currentTime, 1099);44 assert.equal(a.startTime, -299);45 });46 test('pausing works as expected', function() {47 tick(190);48 var a = document.body.animate([], 3000);49 tick(200);50 tick(1500);51 assert.equal(a.startTime, 200);52 assert.equal(a.currentTime, 1300);53 a.pause();54 assert.equal(a.startTime, null);55 assert.equal(a.currentTime, null);56 tick(2500);57 assert.equal(a.startTime, null);58 assert.equal(a.currentTime, 1300);59 a.play();60 tick(2510);61 assert.equal(a.startTime, 1210);62 assert.equal(a.currentTime, 1300);63 tick(3500);64 assert.equal(a.startTime, 1210);65 assert.equal(a.currentTime, 2290);66 });67 test('reversing works as expected', function() {68 tick(290);69 var a = document.body.animate([], 1000);70 tick(300);71 assert.equal(a.startTime, 300);72 assert.equal(a.currentTime, 0);73 tick(600);74 assert.equal(a.startTime, 300);75 assert.equal(a.currentTime, 300);76 assert.equal(a.playbackRate, 1);77 a.reverse();78 tick(600);79 assert.equal(a.startTime, 900);80 assert.equal(a.currentTime, 300);81 assert.equal(a.playbackRate, -1);82 tick(700);83 assert.equal(a.startTime, 900);84 assert.equal(a.currentTime, 200);85 });86 test('reversing after pausing', function() {87 tick(90);88 var a = document.body.animate([], 1000);89 tick(100);90 tick(600);91 a.reverse();92 tick(601);93 tick(700);94 assert.equal(a.startTime, 1101);95 assert.equal(a.currentTime, 401);96 });97 test('reversing after finishing works as expected', function() {98 tick(90);99 var a = document.body.animate([], 1000);100 tick(100);101 tick(1200);102 assert.equal(a.playState, 'finished');103 assert.equal(a.startTime, 100);104 assert.equal(a.currentTime, 1000);105 tick(1500);106 assert.equal(a.currentTime, 1000);107 assert.equal(isTicking(), false);108 a.reverse();109 assert.equal(a._startTime, null);110 assert.equal(a.currentTime, 1000);111 tick(1600);112 assert.equal(a.startTime, 2600);113 assert.equal(a.currentTime, 1000);114 });115 test('playing after finishing works as expected', function() {116 tick(90);117 var a = document.body.animate([], 1000);118 tick(100);119 tick(1200);120 assert.equal(a.playState, 'finished');121 assert.equal(a.startTime, 100);122 assert.equal(a.currentTime, 1000);123 tick(1500);124 assert.equal(a.currentTime, 1000);125 assert.equal(isTicking(), false);126 a.play();127 assert.equal(a.startTime, null);128 assert.equal(a.currentTime, 0);129 tick(1600);130 assert.equal(a.startTime, 1600);131 assert.equal(a.currentTime, 0);132 });133 test('limiting works as expected', function() {134 tick(390);135 var a = document.body.animate([], 1000);136 tick(400);137 assert.equal(a.startTime, 400);138 assert.equal(a.currentTime, 0);139 tick(900);140 assert.equal(a.startTime, 400);141 assert.equal(a.currentTime, 500);142 tick(1400);143 assert.equal(a.startTime, 400);144 assert.equal(a.currentTime, 1000);145 tick(1500);146 assert.equal(a.startTime, 400);147 assert.equal(a.currentTime, 1000);148 a.reverse();149 assert.equal(a.playbackRate, -1);150 assert.equal(a.currentTime, 1000);151 assert.equal(a._startTime, null);152 tick(2000);153 assert.equal(a.currentTime, 1000);154 assert.equal(a.startTime, 3000);155 tick(2200);156 assert.equal(a.currentTime, 800);157 assert.equal(a.startTime, 3000);158 tick(3200);159 assert.equal(a.currentTime, 0);160 assert.equal(a.startTime, 3000);161 tick(3500);162 assert.equal(a.currentTime, 0);163 assert.equal(a.startTime, 3000);164 });165 test('play after limit works as expected', function() {166 tick(490);167 var a = document.body.animate([], 2000);168 tick(500);169 tick(2600);170 assert.equal(a.currentTime, 2000);171 assert.equal(a.startTime, 500);172 assert.equal(a.playState, 'finished');173 assert.equal(a.playbackRate, 1);174 setTicking(true);175 a.play();176 tick(2700);177 assert.equal(a.startTime, 2700);178 assert.equal(a.currentTime, 0);179 assert.notEqual(a.playState, 'finished');180 assert.equal(a.playbackRate, 1);181 });182 test('play after limit works as expected (reversed)', function() {183 tick(590);184 var a = document.body.animate([], 3000);185 tick(600);186 tick(700);187 a.reverse();188 tick(701);189 tick(900);190 assert.equal(a.startTime, 801);191 assert.equal(a.currentTime, 0);192 assert.equal(a.playState, 'finished');193 assert.equal(a.playbackRate, -1);194 setTicking(true);195 a.play();196 tick(1000);197 assert.equal(a.startTime, 4000);198 assert.equal(a.currentTime, 3000);199 assert.notEqual(a.playState, 'finished');200 assert.equal(a.playbackRate, -1);201 });202 test('seeking works as expected', function() {203 tick(690);204 var a = document.body.animate([], 2000);205 tick(700);206 tick(900);207 assert.equal(a.currentTime, 200);208 a.currentTime = 600;209 assert.equal(a.currentTime, 600);210 assert.equal(a.startTime, 300);211 a.reverse();212 tick(1000);213 assert.equal(a.startTime, 1600);214 a.currentTime = 300;215 assert.equal(a.currentTime, 300);216 assert.equal(a.startTime, 1300);217 });218 test('seeking while paused works as expected', function() {219 tick(790);220 var a = document.body.animate([], 1000);221 tick(800);222 tick(1000);223 a.pause();224 assert.equal(a.currentTime, null);225 assert.equal(a.startTime, null);226 assert.equal(a._paused, true);227 a.currentTime = 500;228 assert.equal(a.startTime, null);229 assert.equal(a._paused, true);230 });231 test('setting start time while paused is ignored', function() {232 tick(900);233 var a = document.body.animate([], 1234);234 a.pause();235 assert.equal(a.startTime, null);236 assert.equal(a.currentTime, null);237 a.startTime = 2232;238 assert.equal(a.startTime, null);239 assert.equal(a.currentTime, null);240 });241 test('setting playbackRate sets startTime to null unless the playbackRate is not changing, ' +242 'preserves the current time', function() {243 tick(0);244 var a = document.body.animate([], 1000);245 tick(1);246 tick(11);247 assert.equal(a.currentTime, 10);248 a.playbackRate = 2;249 assert.equal(a.playbackRate, 2);250 assert.equal(a.currentTime, 10);251 assert.equal(a.startTime, null);252 tick(12);253 assert.equal(a.currentTime, 10);254 assert.equal(a.startTime, 7);255 tick(22);256 assert.equal(a.currentTime, 30);257 assert.equal(a.startTime, 7);258 a.playbackRate = -1;259 assert.equal(a.playbackRate, -1);260 assert.equal(a.currentTime, 30);261 assert.equal(a.startTime, null);262 tick(23);263 assert.equal(a.currentTime, 30);264 assert.equal(a.startTime, 53);265 tick(33);266 assert.equal(a.currentTime, 20);267 assert.equal(a.startTime, 53);268 a.playbackRate = -1;269 assert.equal(a.playbackRate, -1);270 assert.equal(a.currentTime, 20);271 assert.equal(a.startTime, 53);272 tick(43);273 assert.equal(a.currentTime, 10);274 assert.equal(a.startTime, 53);275 }276 );277 test('setting playbackRate puts animation back into effect if it is not finished', function() {278 tick(0);279 var a = document.body.animate([], 1000);280 assert.equal(a.playbackRate, 1);281 tick(1);282 tick(1002);283 assert.equal(a.currentTime, 1000);284 a.playbackRate = -1;285 assert.equal(a.playbackRate, -1);286 assert.equal(a.currentTime, 1000);287 tick(1003);288 assert.equal(a.currentTime, 1000);289 tick(1503);290 assert.equal(a.currentTime, 500);291 });292 test('setting playbackRate does not put animation back into effect if it is finished', function() {293 tick(0);294 var a = document.body.animate([], 1000);295 assert.equal(a.playbackRate, 1);296 tick(1);297 tick(1002);298 assert.equal(a.currentTime, 1000);299 assert.equal(a.startTime, 1);300 a.playbackRate = 0.5;301 assert.equal(a.playbackRate, 0.5);302 assert.equal(a.currentTime, 1000);303 assert.equal(a.startTime, null);304 tick(1003);305 assert.equal(a.currentTime, 1000);306 assert.equal(a.startTime, -997);307 tick(1503);308 assert.equal(a.currentTime, 1000);309 assert.equal(a.startTime, -997);310 });311 test('finishing works as expected', function() {312 tick(1000);313 var a = document.body.animate([], 2000);314 a.finish();315 assert.equal(a.startTime, 0);316 assert.equal(a.currentTime, 2000);317 a.reverse();318 a.finish();319 assert.equal(a.currentTime, 0);320 assert.equal(a.startTime, 2000);321 tick(2000);322 });323 test('cancelling clears all effects', function() {324 tick(0);325 var target = document.createElement('div');326 document.documentElement.appendChild(target);327 var animation = target.animate([{marginLeft: '50px'}, {marginLeft: '50px'}], 1000);328 tick(10);329 tick(110);330 assert.equal(getComputedStyle(target).marginLeft, '50px');331 animation.cancel();332 tick(110);333 assert.equal(getComputedStyle(target).marginLeft, '0px');334 assert.deepEqual(webAnimations1.timeline._animations, []);335 tick(120);336 assert.equal(getComputedStyle(target).marginLeft, '0px');337 assert.deepEqual(webAnimations1.timeline._animations, []);338 document.documentElement.removeChild(target);339 });340 test('cancelling a newly created animation clears all effects', function() {341 tick(0);342 var target = document.createElement('div');343 document.documentElement.appendChild(target);344 var animation = target.animate([{marginLeft: '50px'}, {marginLeft: '50px'}], 1000);345 assert.equal(getComputedStyle(target).marginLeft, '50px');346 animation.cancel();347 assert.equal(getComputedStyle(target).marginLeft, '0px');348 document.documentElement.removeChild(target);349 });350 test('startTime is set on first tick if timeline hasn\'t started', function() {351 webAnimations1.timeline.currentTime = undefined;352 var a = document.body.animate([], 1000);353 tick(0);354 tick(100);355 assert.equal(a.startTime, 0);356 });357 test('animations which are finished and not filling get discarded', function() {358 tick(90);359 var nofill = document.body.animate([], 100);360 var fill = document.body.animate([], {duration: 100, fill: 'forwards'});361 assert.deepEqual(webAnimations1.timeline._animations, [nofill._animation || nofill, fill._animation || fill]);362 tick(100);363 assert.deepEqual(webAnimations1.timeline._animations, [nofill._animation || nofill, fill._animation || fill]);364 tick(400);365 assert.deepEqual(webAnimations1.timeline._animations, [fill._animation || fill]);366 });367 test('discarded animations get re-added on modification', function() {368 tick(90);369 var animation = document.body.animate([], 100);370 tick(100);371 tick(400);372 assert.deepEqual(webAnimations1.timeline._animations, []);373 animation.currentTime = 0;374 assert.deepEqual(webAnimations1.timeline._animations, [animation._animation || animation]);375 });376 test('animations in the before phase are not discarded', function() {377 tick(100);378 var animation = document.body.animate([], 100);379 animation.currentTime = -50;380 tick(110);381 assert.deepEqual(webAnimations1.timeline._animations, [animation._animation || animation]);382 });383 test('animations that go out of effect should not clear the effect of animations that are in effect', function() {384 var target = document.createElement('div');385 document.body.appendChild(target);386 tick(0);387 var animationBehind = target.animate([{marginLeft: '200px'}, {marginLeft: '200px'}], 200);388 var animationInfront = target.animate([{marginLeft: '100px'}, {marginLeft: '100px'}], 100);389 tick(50);390 assert.equal(getComputedStyle(target).marginLeft, '100px', 't = 50');391 tick(150);392 assert.equal(getComputedStyle(target).marginLeft, '200px', 't = 150');393 tick(250);394 assert.equal(getComputedStyle(target).marginLeft, '0px', 't = 250');395 document.body.removeChild(target);396 });397 test('animation modifications should update CSS effects immediately', function() {398 var target = document.createElement('div');399 document.body.appendChild(target);400 tick(0);401 var animationBehind = target.animate([{width: '1234px'}, {width: '1234px'}], {duration: 1, fill: 'both'});402 var animationInfront = target.animate([{width: '0px'}, {width: '100px'}], 100);403 assert.equal(getComputedStyle(target).width, '0px');404 animationInfront.currentTime = 50;405 assert.equal(getComputedStyle(target).width, '50px');406 animationInfront.currentTime = 100;407 assert.equal(getComputedStyle(target).width, '1234px');408 animationInfront.play();409 assert.equal(getComputedStyle(target).width, '0px');410 animationInfront.startTime = -50;411 assert.equal(getComputedStyle(target).width, '50px');412 document.body.removeChild(target);413 });414 test('KeyframeEffect that hasn\'t been played has playState \'idle\'', function() {415 var effect = new webAnimations1KeyframeEffect(document.body, [], 1000);416 var a = new webAnimations1Animation(effect);417 assert.equal(a.playState, 'idle');418 });419 test('playState works for a simple effect', function() {420 var a = document.body.animate([], 1000);421 tick(0);422 assert.equal(a.playState, 'running');423 tick(100);424 assert.equal(a.playState, 'running');425 a.pause();426 assert.equal(a.playState, 'pending');427 tick(101);428 assert.equal(a.playState, 'paused');429 a.play();430 assert.equal(a.playState, 'pending');431 tick(102);432 assert.equal(a.playState, 'running');433 tick(1002);434 assert.equal(a.playState, 'finished');435 });436 test('Play after cancel', function() {437 var a = document.body.animate([], 1000);438 assert.equal(a.playState, 'pending');439 tick(0);440 a.cancel();441 assert.equal(a.playState, 'idle');442 assert.equal(a.currentTime, null);443 assert.equal(a.startTime, null);444 tick(1);445 assert.equal(a.playState, 'idle');446 assert.equal(a.currentTime, null);447 assert.equal(a.startTime, null);448 a.play();449 assert.equal(a.playState, 'pending');450 assert.equal(a.currentTime, 0);451 assert.equal(a.startTime, null);452 tick(10);453 assert.equal(a.playState, 'running');454 assert.equal(a.currentTime, 0);455 assert.equal(a.startTime, 10);456 });457 test('Reverse after cancel', function() {458 var a = document.body.animate([], 300);459 tick(0);460 a.cancel();461 assert.equal(a.playState, 'idle');462 assert.equal(a.currentTime, null);463 assert.equal(a.startTime, null);464 tick(1);465 a.reverse();466 assert.equal(a.playState, 'pending');467 assert.equal(a.currentTime, 300);468 assert.equal(a.startTime, null);469 tick(100);470 assert.equal(a.playState, 'running');471 assert.equal(a.currentTime, 300);472 assert.equal(a.startTime, 400);473 tick(300);474 assert.equal(a.playState, 'running');475 assert.equal(a.currentTime, 100);476 assert.equal(a.startTime, 400);477 tick(400);478 assert.equal(a.playState, 'finished');479 assert.equal(a.currentTime, 0);480 assert.equal(a.startTime, 400);481 });482 test('Finish after cancel', function() {483 var a = document.body.animate([], 300);484 tick(0);485 a.cancel();486 assert.equal(a.playState, 'idle');487 assert.equal(a.currentTime, null);488 assert.equal(a.startTime, null);489 tick(1);490 a.finish();491 assert.equal(a.playState, 'idle');492 assert.equal(a.currentTime, null);493 assert.equal(a.startTime, null);494 tick(2);495 assert.equal(a.playState, 'idle');496 assert.equal(a.currentTime, null);497 assert.equal(a.startTime, null);498 });499 test('Pause after cancel', function() {500 var a = document.body.animate([], 300);501 tick(0);502 a.cancel();503 assert.equal(a.playState, 'idle');504 assert.equal(a.currentTime, null);505 assert.equal(a.startTime, null);506 tick(1);507 a.pause();508 assert.equal(a.playState, 'paused');509 assert.equal(a.currentTime, 0);510 assert.equal(a.startTime, null);511 });512 test('Animations ignore NaN times', function() {513 var a = document.body.animate([], 300);514 a.startTime = 100;515 tick(110);516 assert.equal(a.currentTime, 10);517 a.startTime = NaN;518 assert.equal(a.startTime, 100);519 a.currentTime = undefined;520 assert.equal(a.currentTime, 10);521 });522 test('play() should not set a start time', function() {523 var a = document.body.animate([], 1000);524 a.cancel();525 assert.equal(a.startTime, null);526 assert.equal(a.playState, 'idle');527 a.play();528 assert.equal(a.startTime, null);529 assert.equal(a.playState, 'pending');530 });531 test('reverse() should not set a start time', function() {532 var a = document.body.animate([], 1000);533 a.cancel();534 assert.equal(a.startTime, null);535 assert.equal(a.playState, 'idle');536 a.reverse();537 assert.equal(a.startTime, null);538 assert.equal(a.playState, 'pending');539 });540 test('Animations have optional ID', function() {541 tick(100);542 var a = document.body.animate([], { duration: 1000 });543 assert.equal(a.id, '');544 a = document.body.animate([], { duration: 1000, id: 'anim-id' });545 assert.equal(a.id, 'anim-id');546 });...
ClockSpec.js
Source:ClockSpec.js
1/*global defineSuite*/2defineSuite([3 'Core/Clock',4 'Core/ClockRange',5 'Core/ClockStep',6 'Core/JulianDate',7 'Specs/pollToPromise'8 ], function(9 Clock,10 ClockRange,11 ClockStep,12 JulianDate,13 pollToPromise) {14 "use strict";15 /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn*/16 it('constructor sets default parameters', function() {17 var clock = new Clock();18 expect(clock.stopTime).toEqual(JulianDate.addDays(clock.startTime, 1, new JulianDate()));19 expect(clock.startTime).toEqual(clock.currentTime);20 expect(clock.clockStep).toEqual(ClockStep.SYSTEM_CLOCK_MULTIPLIER);21 expect(clock.clockRange).toEqual(ClockRange.UNBOUNDED);22 expect(clock.multiplier).toEqual(1.0);23 });24 it('constructor sets provided parameters correctly', function() {25 var start = new JulianDate(12);26 var stop = new JulianDate(112);27 var currentTime = new JulianDate(13);28 var step = ClockStep.TICK_DEPENDENT;29 var range = ClockRange.LOOP_STOP;30 var multiplier = 1.5;31 var clock = new Clock({32 currentTime : currentTime,33 clockStep : step,34 multiplier : multiplier,35 startTime : start,36 stopTime : stop,37 clockRange : range38 });39 expect(clock.startTime).toEqual(start);40 expect(clock.stopTime).toEqual(stop);41 expect(clock.currentTime).toEqual(currentTime);42 expect(clock.clockStep).toEqual(step);43 expect(clock.clockRange).toEqual(range);44 expect(clock.multiplier).toEqual(multiplier);45 });46 it('constructor works with no currentTime parameter', function() {47 var start = new JulianDate(12);48 var stop = new JulianDate(112);49 var currentTime = new JulianDate(12);50 var step = ClockStep.TICK_DEPENDENT;51 var range = ClockRange.LOOP_STOP;52 var multiplier = 1.5;53 var clock = new Clock({54 clockStep : step,55 multiplier : multiplier,56 startTime : start,57 stopTime : stop,58 clockRange : range59 });60 expect(clock.startTime).toEqual(start);61 expect(clock.stopTime).toEqual(stop);62 expect(clock.currentTime).toEqual(currentTime);63 expect(clock.clockStep).toEqual(step);64 expect(clock.clockRange).toEqual(range);65 expect(clock.multiplier).toEqual(multiplier);66 });67 it('constructor works with no startTime parameter', function() {68 var stop = new JulianDate(112);69 var currentTime = new JulianDate(13);70 var step = ClockStep.TICK_DEPENDENT;71 var range = ClockRange.LOOP_STOP;72 var multiplier = 1.5;73 var clock = new Clock({74 currentTime : currentTime,75 clockStep : step,76 multiplier : multiplier,77 stopTime : stop,78 clockRange : range79 });80 expect(clock.startTime).toEqual(clock.currentTime);81 expect(clock.stopTime).toEqual(stop);82 expect(clock.currentTime).toEqual(currentTime);83 expect(clock.clockStep).toEqual(step);84 expect(clock.clockRange).toEqual(range);85 expect(clock.multiplier).toEqual(multiplier);86 });87 it('constructor works with no start or stop time', function() {88 var start = new JulianDate(12);89 var stop = new JulianDate(13);90 var currentTime = new JulianDate(12);91 var step = ClockStep.TICK_DEPENDENT;92 var range = ClockRange.LOOP_STOP;93 var multiplier = 1.5;94 var clock = new Clock({95 currentTime : currentTime,96 clockStep : step,97 multiplier : multiplier,98 clockRange : range99 });100 expect(clock.startTime).toEqual(start);101 expect(clock.stopTime).toEqual(stop);102 expect(clock.currentTime).toEqual(currentTime);103 expect(clock.clockStep).toEqual(step);104 expect(clock.clockRange).toEqual(range);105 expect(clock.multiplier).toEqual(multiplier);106 });107 it('constructor works with no start or current time', function() {108 var start = new JulianDate(12);109 var stop = new JulianDate(13);110 var currentTime = new JulianDate(12);111 var step = ClockStep.TICK_DEPENDENT;112 var range = ClockRange.LOOP_STOP;113 var multiplier = 1.5;114 var clock = new Clock({115 clockStep : step,116 multiplier : multiplier,117 stopTime : stop,118 clockRange : range119 });120 expect(clock.startTime).toEqual(start);121 expect(clock.stopTime).toEqual(stop);122 expect(clock.currentTime).toEqual(currentTime);123 expect(clock.clockStep).toEqual(step);124 expect(clock.clockRange).toEqual(range);125 expect(clock.multiplier).toEqual(multiplier);126 });127 it('constructor works with no current or stop time', function() {128 var start = new JulianDate(12);129 var stop = new JulianDate(13);130 var currentTime = new JulianDate(12);131 var step = ClockStep.TICK_DEPENDENT;132 var range = ClockRange.LOOP_STOP;133 var multiplier = 1.5;134 var clock = new Clock({135 clockStep : step,136 multiplier : multiplier,137 startTime : start,138 clockRange : range139 });140 expect(clock.startTime).toEqual(start);141 expect(clock.stopTime).toEqual(stop);142 expect(clock.currentTime).toEqual(currentTime);143 expect(clock.clockStep).toEqual(step);144 expect(clock.clockRange).toEqual(range);145 expect(clock.multiplier).toEqual(multiplier);146 });147 it('constructor works with no stopTime parameter', function() {148 var start = new JulianDate(12);149 var stop = new JulianDate(13);150 var currentTime = new JulianDate(12);151 var step = ClockStep.TICK_DEPENDENT;152 var range = ClockRange.LOOP_STOP;153 var multiplier = 1.5;154 var clock = new Clock({155 currentTime : currentTime,156 clockStep : step,157 multiplier : multiplier,158 startTime : start,159 clockRange : range160 });161 expect(clock.startTime).toEqual(start);162 expect(clock.stopTime).toEqual(stop);163 expect(clock.currentTime).toEqual(currentTime);164 expect(clock.clockStep).toEqual(step);165 expect(clock.clockRange).toEqual(range);166 expect(clock.multiplier).toEqual(multiplier);167 });168 it('Tick dependant clock step works animating forward.', function() {169 var start = new JulianDate(0);170 var stop = new JulianDate(1);171 var currentTime = new JulianDate(0.5);172 var step = ClockStep.TICK_DEPENDENT;173 var range = ClockRange.LOOP_STOP;174 var multiplier = 1.5;175 var clock = new Clock({176 currentTime : currentTime,177 clockStep : step,178 multiplier : multiplier,179 startTime : start,180 stopTime : stop,181 clockRange : range182 });183 expect(clock.currentTime).toEqual(currentTime);184 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());185 expect(currentTime).toEqual(clock.tick());186 expect(clock.currentTime).toEqual(currentTime);187 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());188 expect(currentTime).toEqual(clock.tick());189 expect(clock.currentTime).toEqual(currentTime);190 });191 it('Tick dependant clock step works animating backwards.', function() {192 var start = new JulianDate(0);193 var stop = new JulianDate(1);194 var currentTime = new JulianDate(0.5);195 var step = ClockStep.TICK_DEPENDENT;196 var range = ClockRange.LOOP_STOP;197 var multiplier = -1.5;198 var clock = new Clock({199 currentTime : currentTime,200 clockStep : step,201 multiplier : multiplier,202 startTime : start,203 stopTime : stop,204 clockRange : range205 });206 expect(clock.currentTime).toEqual(currentTime);207 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());208 expect(currentTime).toEqual(clock.tick());209 expect(clock.currentTime).toEqual(currentTime);210 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());211 expect(currentTime).toEqual(clock.tick());212 expect(clock.currentTime).toEqual(currentTime);213 });214 it('Tick dependant clock step works unbounded animating forward.', function() {215 var start = new JulianDate(0);216 var stop = new JulianDate(1);217 var currentTime = new JulianDate(1);218 var step = ClockStep.TICK_DEPENDENT;219 var range = ClockRange.UNBOUNDED;220 var multiplier = 1.5;221 var clock = new Clock({222 currentTime : currentTime,223 clockStep : step,224 multiplier : multiplier,225 startTime : start,226 stopTime : stop,227 clockRange : range228 });229 expect(clock.currentTime).toEqual(currentTime);230 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());231 expect(currentTime).toEqual(clock.tick());232 expect(clock.currentTime).toEqual(currentTime);233 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());234 expect(currentTime).toEqual(clock.tick());235 expect(clock.currentTime).toEqual(currentTime);236 });237 it('Tick dependant clock step works unbounded animating backwards.', function() {238 var start = new JulianDate(0);239 var stop = new JulianDate(1);240 var currentTime = new JulianDate(0);241 var step = ClockStep.TICK_DEPENDENT;242 var range = ClockRange.UNBOUNDED;243 var multiplier = -1.5;244 var clock = new Clock({245 currentTime : currentTime,246 clockStep : step,247 multiplier : multiplier,248 startTime : start,249 stopTime : stop,250 clockRange : range251 });252 expect(clock.currentTime).toEqual(currentTime);253 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());254 expect(currentTime).toEqual(clock.tick());255 expect(clock.currentTime).toEqual(currentTime);256 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());257 expect(currentTime).toEqual(clock.tick());258 expect(clock.currentTime).toEqual(currentTime);259 });260 it('Tick dependant clock loops animating forward.', function() {261 var start = new JulianDate(0);262 var stop = new JulianDate(1);263 var currentTime = new JulianDate(1);264 var step = ClockStep.TICK_DEPENDENT;265 var range = ClockRange.LOOP_STOP;266 var multiplier = 1.5;267 var clock = new Clock({268 currentTime : currentTime,269 clockStep : step,270 multiplier : multiplier,271 startTime : start,272 stopTime : stop,273 clockRange : range274 });275 expect(clock.currentTime).toEqual(currentTime);276 currentTime = JulianDate.addSeconds(start, multiplier, new JulianDate());277 expect(currentTime).toEqual(clock.tick());278 expect(clock.currentTime).toEqual(currentTime);279 currentTime = JulianDate.addSeconds(currentTime, multiplier, new JulianDate());280 expect(currentTime).toEqual(clock.tick());281 expect(clock.currentTime).toEqual(currentTime);282 });283 it('Tick dependant clock step stops at start when animating backwards with ClockRange.LOOP_STOP.', function() {284 var start = new JulianDate(0);285 var stop = new JulianDate(1);286 var currentTime = new JulianDate(0);287 var step = ClockStep.TICK_DEPENDENT;288 var range = ClockRange.LOOP_STOP;289 var multiplier = -100.0;290 var clock = new Clock({291 currentTime : currentTime,292 clockStep : step,293 multiplier : multiplier,294 startTime : start,295 stopTime : stop,296 clockRange : range297 });298 expect(clock.currentTime).toEqual(currentTime);299 expect(start).toEqual(clock.tick());300 expect(start).toEqual(clock.currentTime);301 });302 it('Tick dependant clock step stops at end when animating forwards.', function() {303 var start = new JulianDate(0);304 var stop = new JulianDate(1);305 var currentTime = new JulianDate(1);306 var step = ClockStep.TICK_DEPENDENT;307 var range = ClockRange.CLAMPED;308 var multiplier = 100.0;309 var clock = new Clock({310 currentTime : currentTime,311 clockStep : step,312 multiplier : multiplier,313 startTime : start,314 stopTime : stop,315 clockRange : range316 });317 expect(clock.currentTime).toEqual(currentTime);318 expect(stop).toEqual(clock.tick());319 expect(stop).toEqual(clock.currentTime);320 });321 it('Ticks in real-time.', function() {322 //We can't numerically validate the real-time clock, but we323 //can at least make sure the code executes.324 var clock = new Clock({325 clockStep : ClockStep.SYSTEM_CLOCK326 });327 var time1 = JulianDate.clone(clock.tick());328 return pollToPromise(function() {329 var time2 = clock.tick();330 return JulianDate.greaterThan(time2, time1);331 });332 });333 it('Tick dependant clock step stops at start animating backwards.', function() {334 var start = new JulianDate(0);335 var stop = new JulianDate(1);336 var currentTime = new JulianDate(0);337 var step = ClockStep.TICK_DEPENDENT;338 var range = ClockRange.CLAMPED;339 var multiplier = -100.0;340 var clock = new Clock({341 currentTime : currentTime,342 clockStep : step,343 multiplier : multiplier,344 startTime : start,345 stopTime : stop,346 clockRange : range347 });348 expect(clock.currentTime).toEqual(currentTime);349 expect(start).toEqual(clock.tick());350 expect(start).toEqual(clock.currentTime);351 });352 it('throws if start time is after stop time.', function() {353 var start = new JulianDate(1);354 var stop = new JulianDate(0);355 expect(function() {356 return new Clock({357 startTime : start,358 stopTime : stop359 });360 }).toThrowDeveloperError();361 });362 it('system clock multiplier clock step works fine', function() {363 var clock = new Clock({364 clockStep : ClockStep.SYSTEM_CLOCK_MULTIPLIER365 });366 var time1 = JulianDate.clone(clock.tick());367 return pollToPromise(function() {368 var time2 = clock.tick();369 return JulianDate.greaterThan(time2, time1);370 });371 });372 it('clock does not advance if shouldAnimate is false and advances if true', function() {373 var clock = new Clock();374 var time1;375 var time2;376 clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;377 var currentTime = clock.currentTime;378 clock.shouldAnimate = false;379 expect(currentTime).toEqual(clock.tick());380 expect(clock.currentTime).toEqual(currentTime);381 clock.shouldAnimate = true;382 time1 = JulianDate.clone(clock.tick());383 return pollToPromise(function() {384 time2 = clock.tick();385 return JulianDate.greaterThan(time2, time1);386 }).then(function() {387 clock.clockStep = ClockStep.SYSTEM_CLOCK;388 currentTime = clock.currentTime;389 clock.shouldAnimate = false;390 expect(currentTime).toEqual(clock.tick());391 expect(clock.currentTime).toEqual(currentTime);392 clock.shouldAnimate = true;393 time1 = JulianDate.clone(clock.tick());394 return pollToPromise(function() {395 time2 = clock.tick();396 return JulianDate.greaterThan(time2, time1);397 }).then(function() {398 clock.clockStep = ClockStep.TICK_DEPENDENT;399 currentTime = JulianDate.clone(clock.currentTime);400 clock.shouldAnimate = false;401 expect(currentTime).toEqual(clock.tick());402 expect(clock.currentTime).toEqual(currentTime);403 clock.shouldAnimate = true;404 expect(JulianDate.greaterThan(clock.tick(), currentTime)).toEqual(true);405 });406 });407 });...
player.js
Source:player.js
1suite('player', function() {2 setup(function() {3 webAnimationsMinifill.timeline._players = [];4 });5 test('zero duration animation works', function() {6 tick(90);7 var p = document.body.animate([], 0);8 tick(100);9 assert.equal(p.startTime, 100);10 assert.equal(p.currentTime, 0);11 });12 test('playing works as expected', function() {13 tick(90);14 var p = document.body.animate([], 2000);15 tick(100);16 assert.equal(p.startTime, 100);17 assert.equal(p.currentTime, 0);18 tick(300);19 assert.equal(p.startTime, 100);20 assert.equal(p.currentTime, 200);21 });22 test('pause at start of play', function() {23 tick(90);24 var p = document.body.animate([], 2000);25 p.pause();26 tick(100);27 assert.equal(p.currentTime, 0);28 tick(300);29 p.play();30 assert.equal(p.currentTime, 0);31 tick(310);32 assert.equal(p.currentTime, 0);33 assert.equal(p.startTime, 310);34 var p = document.body.animate([], 2000);35 p.startTime = -690;36 p.pause();37 assert.equal(p.currentTime, null);38 tick(700);39 p.play();40 tick(701);41 assert.equal(p.currentTime, 1000);42 tick(800);43 assert.equal(p.currentTime, 1099);44 assert.equal(p.startTime, -299);45 });46 test('pausing works as expected', function() {47 tick(190);48 var p = document.body.animate([], 3000);49 tick(200);50 tick(1500);51 assert.equal(p.startTime, 200);52 assert.equal(p.currentTime, 1300);53 p.pause();54 assert.equal(p.startTime, null);55 assert.equal(p.currentTime, null);56 tick(2500);57 assert.equal(p.startTime, null);58 assert.equal(p.currentTime, 1300);59 p.play();60 tick(2510);61 assert.equal(p.startTime, 1210);62 assert.equal(p.currentTime, 1300);63 tick(3500);64 assert.equal(p.startTime, 1210);65 assert.equal(p.currentTime, 2290);66 });67 test('reversing works as expected', function() {68 tick(290);69 var p = document.body.animate([], 1000);70 tick(300);71 assert.equal(p.startTime, 300);72 assert.equal(p.currentTime, 0);73 tick(600);74 assert.equal(p.startTime, 300);75 assert.equal(p.currentTime, 300);76 assert.equal(p.playbackRate, 1);77 p.reverse();78 tick(600);79 assert.equal(p.startTime, 900);80 assert.equal(p.currentTime, 300);81 assert.equal(p.playbackRate, -1);82 tick(700);83 assert.equal(p.startTime, 900);84 assert.equal(p.currentTime, 200);85 });86 test('reversing after pausing', function() {87 tick(90);88 var p = document.body.animate([], 1000);89 tick(100);90 tick(600);91 p.reverse();92 tick(601);93 tick(700);94 assert.equal(p.startTime, 1101);95 assert.equal(p.currentTime, 401);96 });97 test('reversing after finishing works as expected', function() {98 tick(90);99 var p = document.body.animate([], 1000);100 tick(100);101 tick(1200);102 assert.equal(p.finished, true);103 assert.equal(p.startTime, 100);104 assert.equal(p.currentTime, 1000);105 tick(1500);106 assert.equal(p.currentTime, 1000);107 assert.equal(isTicking(), false);108 p.reverse();109 assert.equal(p._startTime, null);110 assert.equal(p.currentTime, 1000);111 tick(1600);112 assert.equal(p.startTime, 2600);113 assert.equal(p.currentTime, 1000);114 });115 test('playing after finishing works as expected', function() {116 tick(90);117 var p = document.body.animate([], 1000);118 tick(100);119 tick(1200);120 assert.equal(p.finished, true);121 assert.equal(p.startTime, 100);122 assert.equal(p.currentTime, 1000);123 tick(1500);124 assert.equal(p.currentTime, 1000);125 assert.equal(isTicking(), false);126 p.play();127 assert.equal(p.startTime, null);128 assert.equal(p.currentTime, 0);129 tick(1600);130 assert.equal(p.startTime, 1600);131 assert.equal(p.currentTime, 0);132 });133 test('limiting works as expected', function() {134 tick(390);135 var p = document.body.animate([], 1000);136 tick(400);137 assert.equal(p.startTime, 400);138 assert.equal(p.currentTime, 0);139 tick(900);140 assert.equal(p.startTime, 400);141 assert.equal(p.currentTime, 500);142 tick(1400);143 assert.equal(p.startTime, 400);144 assert.equal(p.currentTime, 1000);145 tick(1500);146 assert.equal(p.startTime, 400);147 assert.equal(p.currentTime, 1000);148 p.reverse();149 assert.equal(p.playbackRate, -1);150 assert.equal(p.currentTime, 1000);151 assert.equal(p._startTime, null);152 tick(2000);153 assert.equal(p.currentTime, 1000);154 assert.equal(p.startTime, 3000);155 tick(2200);156 assert.equal(p.currentTime, 800);157 assert.equal(p.startTime, 3000);158 tick(3200);159 assert.equal(p.currentTime, 0);160 assert.equal(p.startTime, 3000);161 tick(3500);162 assert.equal(p.currentTime, 0);163 assert.equal(p.startTime, 3000);164 });165 test('play after limit works as expected', function() {166 tick(490);167 var p = document.body.animate([], 2000);168 tick(500);169 tick(2600);170 assert.equal(p.currentTime, 2000);171 assert.equal(p.startTime, 500);172 assert.equal(p.finished, true);173 assert.equal(p.playbackRate, 1);174 setTicking(true);175 p.play();176 tick(2700);177 assert.equal(p.startTime, 2700);178 assert.equal(p.currentTime, 0);179 assert.equal(p.finished, false);180 assert.equal(p.playbackRate, 1);181 });182 test('play after limit works as expected (reversed)', function() {183 tick(590);184 var p = document.body.animate([], 3000);185 tick(600);186 tick(700);187 p.reverse();188 tick(701);189 tick(900);190 assert.equal(p.startTime, 801);191 assert.equal(p.currentTime, 0);192 assert.equal(p.finished, true);193 assert.equal(p.playbackRate, -1);194 setTicking(true);195 p.play();196 tick(1000);197 assert.equal(p.startTime, 4000);198 assert.equal(p.currentTime, 3000);199 assert.equal(p.finished, false);200 assert.equal(p.playbackRate, -1);201 });202 test('seeking works as expected', function() {203 tick(690);204 var p = document.body.animate([], 2000);205 tick(700);206 tick(900);207 assert.equal(p.currentTime, 200);208 p.currentTime = 600;209 assert.equal(p.currentTime, 600);210 assert.equal(p.startTime, 300);211 p.reverse();212 tick(1000);213 assert.equal(p.startTime, 1600);214 p.currentTime = 300;215 assert.equal(p.currentTime, 300);216 assert.equal(p.startTime, 1300);217 });218 test('seeking while paused works as expected', function() {219 tick(790);220 var p = document.body.animate([], 1000);221 tick(800);222 tick(1000);223 p.pause();224 assert.equal(p.currentTime, null);225 assert.equal(p.startTime, null);226 assert.equal(p.paused, true);227 p.currentTime = 500;228 assert.equal(p.startTime, null);229 assert.equal(p.paused, true);230 });231 test('setting start time while paused is ignored', function() {232 tick(900);233 var p = document.body.animate([], 1234);234 p.pause();235 assert.equal(p.startTime, null);236 assert.equal(p.currentTime, null);237 p.startTime = 2232;238 assert.equal(p.startTime, null);239 assert.equal(p.currentTime, null);240 });241 test('finishing works as expected', function() {242 tick(1000);243 var p = document.body.animate([], 2000);244 p.finish();245 assert.equal(p.startTime, 0);246 assert.equal(p.currentTime, 2000);247 p.reverse();248 p.finish();249 assert.equal(p.currentTime, 0);250 assert.equal(p.startTime, 2000);251 tick(2000);252 });253 test('cancelling clears all effects', function() {254 tick(0);255 var target = document.createElement('div');256 document.documentElement.appendChild(target);257 var player = target.animate([{marginLeft: '50px'}, {marginLeft: '50px'}], 1000);258 tick(10);259 tick(110);260 assert.equal(getComputedStyle(target).marginLeft, '50px');261 player.cancel();262 // getComputedStyle forces a tick.263 assert.equal(getComputedStyle(target).marginLeft, '0px');264 assert.deepEqual(webAnimationsMinifill.timeline._players, []);265 tick(120);266 assert.equal(getComputedStyle(target).marginLeft, '0px');267 assert.deepEqual(webAnimationsMinifill.timeline._players, []);268 document.documentElement.removeChild(target);269 });270 test('startTime is set on first tick if timeline hasn\'t started', function() {271 webAnimationsMinifill.timeline.currentTime = undefined;272 var p = document.body.animate([], 1000);273 tick(0);274 tick(100);275 assert.equal(p.startTime, 0);276 });277 test('players which are finished and not filling get discarded', function() {278 tick(90);279 var nofill = document.body.animate([], 100);280 var fill = document.body.animate([], {duration: 100, fill: 'forwards'});281 assert.deepEqual(webAnimationsMinifill.timeline._players, [nofill._player || nofill, fill._player || fill]);282 tick(100);283 assert.deepEqual(webAnimationsMinifill.timeline._players, [nofill._player || nofill, fill._player || fill]);284 tick(400);285 assert.deepEqual(webAnimationsMinifill.timeline._players, [fill._player || fill]);286 });287 test('discarded players get re-added on modification', function() {288 tick(90);289 var player = document.body.animate([], 100);290 tick(100);291 tick(400);292 assert.deepEqual(webAnimationsMinifill.timeline._players, []);293 player.currentTime = 0;294 assert.deepEqual(webAnimationsMinifill.timeline._players, [player._player || player]);295 });296 test('players in the before phase are not discarded', function() {297 tick(100);298 var player = document.body.animate([], 100);299 player.currentTime = -50;300 tick(110);301 assert.deepEqual(webAnimationsMinifill.timeline._players, [player._player || player]);302 });303 test('players that go out of effect should not clear the effect of players that are in effect', function() {304 var target = document.createElement('div');305 document.body.appendChild(target);306 tick(0);307 var playerBehind = target.animate([{marginLeft: '200px'}, {marginLeft: '200px'}], 200);308 var playerInfront = target.animate([{marginLeft: '100px'}, {marginLeft: '100px'}], 100);309 tick(50);310 assert.equal(getComputedStyle(target).marginLeft, '100px', 't = 50');311 tick(150);312 assert.equal(getComputedStyle(target).marginLeft, '200px', 't = 150');313 tick(250);314 assert.equal(getComputedStyle(target).marginLeft, '0px', 't = 250');315 document.body.removeChild(target);316 });317 test('player modifications should update CSS effects immediately', function() {318 var target = document.createElement('div');319 document.body.appendChild(target);320 tick(0);321 var playerBehind = target.animate([{width: '1234px'}, {width: '1234px'}], {duration: 1, fill: 'both'});322 var playerInfront = target.animate([{width: '0px'}, {width: '100px'}], 100);323 assert.equal(getComputedStyle(target).width, '0px');324 playerInfront.currentTime = 50;325 assert.equal(getComputedStyle(target).width, '50px');326 playerInfront.currentTime = 100;327 assert.equal(getComputedStyle(target).width, '1234px');328 playerInfront.play();329 assert.equal(getComputedStyle(target).width, '0px');330 playerInfront.startTime = -50;331 assert.equal(getComputedStyle(target).width, '50px');332 document.body.removeChild(target);333 });334 test('Player that hasn\'t been played has playState \'idle\'', function() {335 var source = new minifillAnimation(document.body, [], 1000);336 var p = new Player(source);337 assert.equal(p.playState, 'idle');338 });339 test('playState works for a simple animation', function() {340 var p = document.body.animate([], 1000);341 tick(0);342 assert.equal(p.playState, 'running');343 tick(100);344 assert.equal(p.playState, 'running');345 p.pause();346 assert.equal(p.playState, 'pending');347 tick(101);348 assert.equal(p.playState, 'paused');349 p.play();350 assert.equal(p.playState, 'pending');351 tick(102);352 assert.equal(p.playState, 'running');353 tick(1002);354 assert.equal(p.playState, 'finished');355 });356 test('Play after cancel', function() {357 var p = document.body.animate([], 1000);358 assert.equal(p.playState, 'pending');359 tick(0);360 p.cancel();361 assert.equal(p.playState, 'idle');362 assert.equal(p.currentTime, null);363 assert.equal(p.startTime, null);364 tick(1);365 assert.equal(p.playState, 'idle');366 assert.equal(p.currentTime, null);367 assert.equal(p.startTime, null);368 p.play();369 assert.equal(p.playState, 'pending');370 assert.equal(p.currentTime, 0);371 assert.equal(p.startTime, null);372 tick(10);373 assert.equal(p.playState, 'running');374 assert.equal(p.currentTime, 0);375 assert.equal(p.startTime, 10);376 });377 test('Reverse after cancel', function() {378 var p = document.body.animate([], 300);379 tick(0);380 p.cancel();381 assert.equal(p.playState, 'idle');382 assert.equal(p.currentTime, null);383 assert.equal(p.startTime, null);384 tick(1);385 p.reverse();386 assert.equal(p.playState, 'pending');387 assert.equal(p.currentTime, 300);388 assert.equal(p.startTime, null);389 tick(100);390 assert.equal(p.playState, 'running');391 assert.equal(p.currentTime, 300);392 assert.equal(p.startTime, 400);393 tick(300);394 assert.equal(p.playState, 'running');395 assert.equal(p.currentTime, 100);396 assert.equal(p.startTime, 400);397 tick(400);398 assert.equal(p.playState, 'finished');399 assert.equal(p.currentTime, 0);400 assert.equal(p.startTime, 400);401 });402 test('Finish after cancel', function() {403 var p = document.body.animate([], 300);404 tick(0);405 p.cancel();406 assert.equal(p.playState, 'idle');407 assert.equal(p.currentTime, null);408 assert.equal(p.startTime, null);409 tick(1);410 p.finish();411 assert.equal(p.playState, 'idle');412 assert.equal(p.currentTime, null);413 assert.equal(p.startTime, null);414 tick(2);415 assert.equal(p.playState, 'idle');416 assert.equal(p.currentTime, null);417 assert.equal(p.startTime, null);418 });419 test('Pause after cancel', function() {420 var p = document.body.animate([], 300);421 tick(0);422 p.cancel();423 assert.equal(p.playState, 'idle');424 assert.equal(p.currentTime, null);425 assert.equal(p.startTime, null);426 tick(1);427 p.pause();428 assert.equal(p.playState, 'idle');429 assert.equal(p.currentTime, null);430 assert.equal(p.startTime, null);431 });432 test('Players ignore NaN times', function() {433 var p = document.body.animate([], 300);434 p.startTime = 100;435 tick(110);436 assert.equal(p.currentTime, 10);437 p.startTime = NaN;438 assert.equal(p.startTime, 100);439 p.currentTime = undefined;440 assert.equal(p.currentTime, 10);441 });442 test('play() should not set a start time', function() {443 var p = document.body.animate([], 1000);444 p.cancel();445 assert.equal(p.startTime, null);446 assert.equal(p.playState, 'idle');447 p.play();448 assert.equal(p.startTime, null);449 assert.equal(p.playState, 'pending');450 });451 test('reverse() should not set a start time', function() {452 var p = document.body.animate([], 1000);453 p.cancel();454 assert.equal(p.startTime, null);455 assert.equal(p.playState, 'idle');456 p.reverse();457 assert.equal(p.startTime, null);458 assert.equal(p.playState, 'pending');459 });...
Clock.js
Source:Clock.js
1/*global define*/2define([3 './ClockRange',4 './ClockStep',5 './defaultValue',6 './defined',7 './DeveloperError',8 './Event',9 './getTimestamp',10 './JulianDate'11 ], function(12 ClockRange,13 ClockStep,14 defaultValue,15 defined,16 DeveloperError,17 Event,18 getTimestamp,19 JulianDate) {20 "use strict";21 /**22 * A simple clock for keeping track of simulated time.23 *24 * @alias Clock25 * @constructor26 *27 * @param {Object} options Object with the following properties:28 * @param {JulianDate} [options.startTime] The start time of the clock.29 * @param {JulianDate} [options.stopTime] The stop time of the clock.30 * @param {JulianDate} [options.currentTime] The current time.31 * @param {Number} [options.multiplier=1.0] Determines how much time advances when tick is called, negative values allow for advancing backwards.32 * @param {ClockStep} [options.clockStep=ClockStep.SYSTEM_CLOCK_MULTIPLIER] Determines if calls to <code>tick</code> are frame dependent or system clock dependent.33 * @param {ClockRange} [options.clockRange=ClockRange.UNBOUNDED] Determines how the clock should behave when <code>startTime</code> or <code>stopTime</code> is reached.34 * @param {Boolean} [options.canAnimate=true] Indicates whether tick can advance time. This could be false if data is being buffered, for example. The clock will only tick when both <code>canAnimate</code> and <code>shouldAnimate</code> are true.35 * @param {Boolean} [options.shouldAnimate=true] Indicates whether tick should attempt to advance time. The clock will only tick when both <code>canAnimate</code> and <code>shouldAnimate</code> are true.36 *37 * @exception {DeveloperError} startTime must come before stopTime.38 *39 * @see ClockStep40 * @see ClockRange41 * @see JulianDate42 *43 * @example44 * // Create a clock that loops on Christmas day 2013 and runs in real-time.45 * var clock = new Cesium.Clock({46 * startTime : Cesium.JulianDate.fromIso8601("2013-12-25"),47 * currentTime : Cesium.JulianDate.fromIso8601("2013-12-25"),48 * stopTime : Cesium.JulianDate.fromIso8601("2013-12-26"),49 * clockRange : Cesium.ClockRange.LOOP_STOP,50 * clockStep : Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER51 * });52 */53 var Clock = function(options) {54 options = defaultValue(options, defaultValue.EMPTY_OBJECT);55 var startTime = options.startTime;56 var startTimeUndefined = !defined(startTime);57 var stopTime = options.stopTime;58 var stopTimeUndefined = !defined(stopTime);59 var currentTime = options.currentTime;60 var currentTimeUndefined = !defined(currentTime);61 if (startTimeUndefined && stopTimeUndefined && currentTimeUndefined) {62 currentTime = JulianDate.now();63 startTime = JulianDate.clone(currentTime);64 stopTime = JulianDate.addDays(currentTime, 1.0, new JulianDate());65 } else if (startTimeUndefined && stopTimeUndefined) {66 startTime = JulianDate.clone(currentTime);67 stopTime = JulianDate.addDays(currentTime, 1.0, new JulianDate());68 } else if (startTimeUndefined && currentTimeUndefined) {69 startTime = JulianDate.addDays(stopTime, -1.0, new JulianDate());70 currentTime = JulianDate.clone(startTime);71 } else if (currentTimeUndefined && stopTimeUndefined) {72 currentTime = JulianDate.clone(startTime);73 stopTime = JulianDate.addDays(startTime, 1.0, new JulianDate());74 } else if (currentTimeUndefined) {75 currentTime = JulianDate.clone(startTime);76 } else if (stopTimeUndefined) {77 stopTime = JulianDate.addDays(currentTime, 1.0, new JulianDate());78 } else if (startTimeUndefined) {79 startTime = JulianDate.clone(currentTime);80 }81 //>>includeStart('debug', pragmas.debug);82 if (JulianDate.greaterThan(startTime, stopTime)) {83 throw new DeveloperError('startTime must come before stopTime.');84 }85 //>>includeEnd('debug');86 /**87 * The start time of the clock.88 * @type {JulianDate}89 */90 this.startTime = startTime;91 /**92 * The stop time of the clock.93 * @type {JulianDate}94 */95 this.stopTime = stopTime;96 /**97 * The current time.98 * @type {JulianDate}99 */100 this.currentTime = currentTime;101 /**102 * Determines how much time advances when tick is called, negative values allow for advancing backwards.103 * If <code>clockStep</code> is set to ClockStep.TICK_DEPENDENT this is the number of seconds to advance.104 * If <code>clockStep</code> is set to ClockStep.SYSTEM_CLOCK_MULTIPLIER this value is multiplied by the105 * elapsed system time since the last call to tick.106 * @type {Number}107 * @default 1.0108 */109 this.multiplier = defaultValue(options.multiplier, 1.0);110 /**111 * Determines if calls to <code>tick</code> are frame dependent or system clock dependent.112 * @type ClockStep113 * @default {@link ClockStep.SYSTEM_CLOCK_MULTIPLIER}114 */115 this.clockStep = defaultValue(options.clockStep, ClockStep.SYSTEM_CLOCK_MULTIPLIER);116 /**117 * Determines how the clock should behave when <code>startTime</code> or <code>stopTime</code> is reached.118 * @type {ClockRange}119 * @default {@link ClockRange.UNBOUNDED}120 */121 this.clockRange = defaultValue(options.clockRange, ClockRange.UNBOUNDED);122 /**123 * Indicates whether tick can advance time. This could be false if data is being buffered,124 * for example. The clock will only tick when both <code>canAnimate</code> and <code>shouldAnimate</code> are true.125 * @type {Boolean}126 * @default true127 */128 this.canAnimate = defaultValue(options.canAnimate, true);129 /**130 * Indicates whether tick should attempt to advance time.131 * The clock will only tick when both <code>canAnimate</code> and <code>shouldAnimate</code> are true.132 * @type {Boolean}133 * @default true134 */135 this.shouldAnimate = defaultValue(options.shouldAnimate, true);136 /**137 * An {@link Event} that is fired whenever <code>tick</code>.138 */139 this.onTick = new Event();140 this._lastSystemTime = getTimestamp();141 };142 /**143 * Advances the clock from the currentTime based on the current configuration options.144 * tick should be called every frame, regardless of whether animation is taking place145 * or not. To control animation, use the <code>shouldAnimate</code> property.146 *147 * @returns {JulianDate} The new value of the <code>currentTime</code> property.148 */149 Clock.prototype.tick = function() {150 var currentSystemTime = getTimestamp();151 var currentTime = JulianDate.clone(this.currentTime);152 var startTime = this.startTime;153 var stopTime = this.stopTime;154 var multiplier = this.multiplier;155 if (this.canAnimate && this.shouldAnimate) {156 if (this.clockStep === ClockStep.SYSTEM_CLOCK) {157 currentTime = JulianDate.now(currentTime);158 } else {159 if (this.clockStep === ClockStep.TICK_DEPENDENT) {160 currentTime = JulianDate.addSeconds(currentTime, multiplier, currentTime);161 } else {162 var milliseconds = currentSystemTime - this._lastSystemTime;163 currentTime = JulianDate.addSeconds(currentTime, multiplier * (milliseconds / 1000.0), currentTime);164 }165 if (this.clockRange === ClockRange.CLAMPED) {166 if (JulianDate.lessThan(currentTime, startTime)) {167 currentTime = JulianDate.clone(startTime, currentTime);168 } else if (JulianDate.greaterThan(currentTime, stopTime)) {169 currentTime = JulianDate.clone(stopTime, currentTime);170 }171 } else if (this.clockRange === ClockRange.LOOP_STOP) {172 if (JulianDate.lessThan(currentTime, startTime)) {173 currentTime = JulianDate.clone(startTime, currentTime);174 }175 while (JulianDate.greaterThan(currentTime, stopTime)) {176 currentTime = JulianDate.addSeconds(startTime, JulianDate.secondsDifference(currentTime, stopTime), currentTime);177 }178 }179 }180 }181 this.currentTime = currentTime;182 this._lastSystemTime = currentSystemTime;183 this.onTick.raiseEvent(this);184 return currentTime;185 };186 return Clock;...
index.js
Source:index.js
1var goku = new Audio('sounds/0.mp3')2var zerotwo = new Audio('sounds/1.mp3')3var kaguya = new Audio('sounds/2.mp3')4var yumeko = new Audio('sounds/3.mp3')5var hori = new Audio('sounds/4.mp3')6var marin = new Audio('sounds/5.mp3')7var mai = new Audio('sounds/6.mp3')8var jinx = new Audio('sounds/7.mp3')9document.addEventListener("keypress", function(e) {10 makesound(e.key)11 animationyep(e.key)12})13var numdrum = document.querySelectorAll(".drum").length14for (var i = 0; i < numdrum; i++) {15 document.querySelectorAll(".drum")[i].addEventListener("click", function() {16 var btninner = this.innerHTML17 makesound(btninner)18 animationyep(btninner)19 })20}21function makesound(key) {22 switch (key) {23 case "w":24 goku.pause()25 zerotwo.pause()26 kaguya.pause()27 yumeko.pause()28 hori.pause()29 marin.pause()30 mai.pause()31 jinx.pause()32 goku.currentTime = 033 zerotwo.currentTime = 034 kaguya.currentTime = 035 yumeko.currentTime = 036 hori.currentTime = 037 marin.currentTime = 038 mai.currentTime = 039 jinx.currentTime = 040 goku.play()41 42 break43 44 case "a":45 goku.pause()46 zerotwo.pause()47 kaguya.pause()48 yumeko.pause()49 hori.pause()50 marin.pause()51 mai.pause()52 jinx.pause()53 goku.currentTime = 054 zerotwo.currentTime = 055 kaguya.currentTime = 056 yumeko.currentTime = 057 hori.currentTime = 058 marin.currentTime = 059 mai.currentTime = 060 jinx.currentTime = 061 62 zerotwo.play()63 break64 case "s":65 goku.pause()66 zerotwo.pause()67 kaguya.pause()68 yumeko.pause()69 hori.pause()70 marin.pause()71 mai.pause()72 jinx.pause()73 goku.currentTime = 074 zerotwo.currentTime = 075 kaguya.currentTime = 076 yumeko.currentTime = 077 hori.currentTime = 078 marin.currentTime = 079 mai.currentTime = 080 jinx.currentTime = 081 82 kaguya.play()83 break84 case "d":85 goku.pause()86 zerotwo.pause()87 kaguya.pause()88 yumeko.pause()89 hori.pause()90 marin.pause()91 mai.pause()92 jinx.pause()93 goku.currentTime = 094 zerotwo.currentTime = 095 kaguya.currentTime = 096 yumeko.currentTime = 097 hori.currentTime = 098 marin.currentTime = 099 mai.currentTime = 0100 jinx.currentTime = 0101 102 yumeko.play()103 break104 case "i":105 goku.pause()106 zerotwo.pause()107 kaguya.pause()108 yumeko.pause()109 hori.pause()110 marin.pause()111 mai.pause()112 jinx.pause()113 goku.currentTime = 0114 zerotwo.currentTime = 0115 kaguya.currentTime = 0116 yumeko.currentTime = 0117 hori.currentTime = 0118 marin.currentTime = 0119 mai.currentTime = 0120 jinx.currentTime = 0121 122 hori.play()123 break124 case "j":125 goku.pause()126 zerotwo.pause()127 kaguya.pause()128 yumeko.pause()129 hori.pause()130 marin.pause()131 mai.pause()132 jinx.pause()133 goku.currentTime = 0134 zerotwo.currentTime = 0135 kaguya.currentTime = 0136 yumeko.currentTime = 0137 hori.currentTime = 0138 marin.currentTime = 0139 mai.currentTime = 0140 jinx.currentTime = 0141 142 marin.play()143 break144 case "k":145 goku.pause()146 zerotwo.pause()147 kaguya.pause()148 yumeko.pause()149 hori.pause()150 marin.pause()151 mai.pause()152 jinx.pause()153 goku.currentTime = 0154 zerotwo.currentTime = 0155 kaguya.currentTime = 0156 yumeko.currentTime = 0157 hori.currentTime = 0158 marin.currentTime = 0159 mai.currentTime = 0160 jinx.currentTime = 0161 162 mai.play()163 break164 case "l":165 goku.pause()166 zerotwo.pause()167 kaguya.pause()168 yumeko.pause()169 hori.pause()170 marin.pause()171 mai.pause()172 jinx.pause()173 goku.currentTime = 0174 zerotwo.currentTime = 0175 kaguya.currentTime = 0176 yumeko.currentTime = 0177 hori.currentTime = 0178 marin.currentTime = 0179 mai.currentTime = 0180 jinx.currentTime = 0181 182 jinx.play()183 break184 185 default:186 goku.pause()187 zerotwo.pause()188 kaguya.pause()189 yumeko.pause()190 hori.pause()191 marin.pause()192 mai.pause()193 jinx.pause()194 goku.currentTime = 0195 zerotwo.currentTime = 0196 kaguya.currentTime = 0197 yumeko.currentTime = 0198 hori.currentTime = 0199 marin.currentTime = 0200 mai.currentTime = 0201 jinx.currentTime = 0202 203 break204 205 }206}207function animationyep(btninner) {208 var actbtn = document.querySelector("." + btninner)209 actbtn.classList.add("pressed")210 setTimeout(function() {211 actbtn.classList.remove("pressed")212 }, 500)...
Transition.js
Source:Transition.js
1var Transition = (function (Math) {2 "use strict";3 function linearTweening(currentTime, startValue, changeInValue, duration) {4 return changeInValue * currentTime / duration + startValue;5 }6 function exponentialEasingInAndOut(currentTime, startValue, changeInValue, duration) {7 if (currentTime == 0)8 return startValue;9 if (currentTime == duration)10 return startValue + changeInValue;11 if ((currentTime /= duration / 2) < 1)12 return changeInValue / 2 * Math.pow(2, 10 * (currentTime - 1)) + startValue;13 return changeInValue / 2 * (-Math.pow(2, -10 * --currentTime) + 2) + startValue;14 }15 function elasticEasingInAndOut(currentTime, startValue, changeInValue, duration) {16 if (currentTime == 0)17 return startValue;18 if ((currentTime /= duration) == 1)19 return startValue + changeInValue;20 var period = duration * .3, s = changeInValue < Math.abs(changeInValue) ? period / 4 :21 period / (2 * Math.PI) * Math.asin(changeInValue / changeInValue);22 return changeInValue * Math.pow(2, -10 * currentTime) *23 Math.sin((currentTime * duration - s) * (2 * Math.PI) / period) + changeInValue + startValue;24 }25 function elasticEasingOut(currentTime, startValue, changeInValue, duration) {26 if (currentTime == 0) {27 return startValue;28 }29 if ((currentTime /= duration) == 1) {30 return startValue + changeInValue;31 }32 var period = duration * .3;33 var s;34 if (changeInValue < Math.abs(changeInValue)) {35 s = period / 4;36 } else {37 s = period / (2 * Math.PI) * Math.asin(changeInValue / changeInValue);38 }39 return changeInValue * Math.pow(2, -10 * currentTime) *40 Math.sin((currentTime * duration - s) * (2 * Math.PI) / period) + changeInValue + startValue;41 }42 function quadraticEasingInAndOut(currentTime, startValue, changeInValue, duration) {43 if ((currentTime /= duration / 2) < 1) {44 return changeInValue / 2 * currentTime * currentTime + startValue;45 }46 return -changeInValue / 2 * ((--currentTime) * (currentTime - 2) - 1) + startValue;47 }48 function exponentialEasingIn(currentTime, startValue, changeInValue, duration) {49 if (currentTime != 0) {50 return changeInValue * Math.pow(2, 10 * (currentTime / duration - 1)) + startValue;51 }52 return startValue;53 }54 function exponentialEasingOut(currentTime, startValue, changeInValue, duration) {55 if (currentTime == duration) {56 return startValue + changeInValue;57 } else {58 return changeInValue * (-Math.pow(2, -10 * currentTime / duration) + 1) + startValue;59 }60 }61 function quadraticEasingIn(currentTime, startValue, changeInValue, duration) {62 return changeInValue * (currentTime /= duration) * currentTime + startValue;63 }64 function quadraticEasingOut(currentTime, startValue, changeInValue, duration) {65 return -changeInValue * (currentTime /= duration) * (currentTime - 2) + startValue;66 }67 // not working :( ... don't copy random shit from the fucking internet68 function quinticEasingOutAndIn(currentTime, startValue, changeInValue, duration) {69 currentTime /= duration / 2;70 return changeInValue / 2 * (--currentTime * currentTime * currentTime * currentTime * currentTime + 1) +71 startValue;72 }73 function sinusoidalEasingOutAndIn(currentTime, startValue, changeInValue, duration) {74 if ((currentTime /= duration / 2) < 1) return changeInValue / 2 * (Math.sin(Math.PI * currentTime / 2) ) +75 startValue;76 return -changeInValue / 2 * (Math.cos(Math.PI * --currentTime / 2) - 2) + startValue;77 }78 function sinusoidalEasingIn(currentTime, startValue, changeInValue, duration) {79 return -changeInValue / 2 * (Math.cos(Math.PI * currentTime / duration) - 1) + startValue;80 }81 function sinusoidalEasingOut(currentTime, startValue, changeInValue, duration) {82 return changeInValue * Math.sin(currentTime / duration * (Math.PI / 2)) + startValue;83 }84 // sinusoidal easing in/out - accelerating until halfway, then decelerating85 function sinusoidalEasingInAndOut(currentTime, startValue, changeInValue, duration) {86 return -changeInValue / 2 * (Math.cos(Math.PI * currentTime / duration) - 1) + startValue;87 }88 function bouncingEasingOut(currentTime, startValue, changeInValue, duration) {89 if ((currentTime /= duration) < (1 / 2.75)) {90 return changeInValue * (7.5625 * currentTime * currentTime) + startValue;91 } else if (currentTime < (2 / 2.75)) {92 return changeInValue * (7.5625 * (currentTime -= (1.5 / 2.75)) * currentTime + .75) + startValue;93 } else if (currentTime < (2.5 / 2.75)) {94 return changeInValue * (7.5625 * (currentTime -= (2.25 / 2.75)) * currentTime + .9375) + startValue;95 } else {96 return changeInValue * (7.5625 * (currentTime -= (2.625 / 2.75)) * currentTime + .984375) + startValue;97 }98 }99 return {100 LINEAR: linearTweening,101 EASE_OUT_BOUNCE: bouncingEasingOut,102 EASE_OUT_ELASTIC: elasticEasingOut,103 EASE_IN_OUT_ELASTIC: elasticEasingInAndOut,104 EASE_IN_EXPO: exponentialEasingIn,105 EASE_OUT_EXPO: exponentialEasingOut,106 EASE_IN_OUT_EXPO: exponentialEasingInAndOut,107 EASE_IN_QUAD: quadraticEasingIn,108 EASE_OUT_QUAD: quadraticEasingOut,109 EASE_IN_OUT_QUAD: quadraticEasingInAndOut,110 EASE_OUT_IN_QUINT: quinticEasingOutAndIn,111 EASE_IN_SIN: sinusoidalEasingIn,112 EASE_OUT_SIN: sinusoidalEasingOut,113 EASE_OUT_IN_SIN: sinusoidalEasingOutAndIn,114 EASE_IN_OUT_SIN: sinusoidalEasingInAndOut115 };...
script.js
Source:script.js
1moment(Date);2$("#todaysDate").text(moment().format('dddd MMMM Do YYYY, h:mm a'));3var currentTime = moment();4// the following line of code changes the current time to the most recent hour, i.e. 9:30 is read as 9:005currentTime = currentTime.startOf("hour");6//the following line of code adds 9 to "start of day" so that the day starts at 9am (start of work day)7var before = moment().startOf("day").add(9, "hours");8//the following code is for the time blocks, one for each hour from 9am-5pm. 9var timeSlot1 = before.add(0, "h");10timeSlot1 = timeSlot1.format('hh:mm A');11$(".block1").text(timeSlot1);12var timeSlot2 = before.add(1, "h");13timeSlot2 = timeSlot2.format('hh:mm A');14$(".block2").text(timeSlot2);15var timeSlot3 = before.add(1, "h");16 timeSlot3 = timeSlot3.format('hh:mm A');17$(".block3").text(timeSlot3);18var timeSlot4 = before.add(1, "h");19 timeSlot4 = timeSlot4.format('hh:mm A');20$(".block4").text(timeSlot4);21var timeSlot5 = before.add(1, "h");22 timeSlot5 = timeSlot5.format('hh:mm A');23$(".block5").text(timeSlot5);24var timeSlot6 = before.add(1, "h");25 timeSlot6 = timeSlot6.format('hh:mm A');26$(".block6").text(timeSlot6);27var timeSlot7 = before.add(1, "h");28 timeSlot7 = timeSlot7.format('hh:mm A')29$(".block7").text(timeSlot7);30var timeSlot8 = before.add(1, "h");31 timeSlot8 = timeSlot8.format('hh:mm A');32$(".block8").text(timeSlot8);33var timeSlot9 = before.add(1, "h");34 timeSlot9 = timeSlot9.format('hh:mm A');35$(".block9").text(timeSlot9); 36//the following function compares the "hour" in the above time slots to the current time. A class of past, present, or future is given to 'var currentTime'.37// just like above where we added 9 hours to make 9am the start of the day, we are adding hours to the various time slots. 38//".form" is named based on the actual time. for example, "timeSlot8" is for the 4pm hour, and ".form4" is used.39function timeTest() {40 timeSlot1 = moment().startOf('day').add(9, "hours");41 currentTime = currentTime.startOf("hour");42 if (currentTime.isAfter(timeSlot1)) {43 $(".form9").addClass("past");44 }else if (currentTime.isBefore(timeSlot1)) {45 $(".form9").addClass("future");46 }else if (currentTime.isSame(timeSlot1)) {47 $(".form9").addClass("present");48 };49 timeSlot2 = moment().startOf('day').add(10, "hours");50currentTime = currentTime.startOf("hour");51if (currentTime.isAfter(timeSlot2)) {52 $(".form10").addClass("past");53}54else if (currentTime.isBefore(timeSlot2)) {55 $(".form10").addClass("future");56}57else if (currentTime.isSame(timeSlot2)) {58 $(".form10").addClass("present");59};60timeSlot3 = moment().startOf('day').add(11, "hours");61currentTime = currentTime.startOf("hour");62if (currentTime.isAfter(timeSlot3)) {63$(".form11").addClass("past");64}65else if (currentTime.isBefore(timeSlot3)) {66$(".form11").addClass("future");67}68else if (currentTime.isSame(timeSlot3)) {69$(".form11").addClass("present");70};71timeSlot4 = moment().startOf('day').add(12, "hours");72currentTime = currentTime.startOf("hour");73if (currentTime.isAfter(timeSlot4)) {74$(".form12").addClass("past");75}76else if (currentTime.isBefore(timeSlot4)) {77$(".form12").addClass("future");78}79else if (currentTime.isSame(timeSlot4)) {80$(".form12").addClass("present");81};82timeSlot5 = moment().startOf('day').add(13, "hours");83currentTime = currentTime.startOf("hour");84if (currentTime.isAfter(timeSlot5)) {85$(".form1").addClass("past");86}87else if (currentTime.isBefore(timeSlot5)) {88$(".form1").addClass("future");89}90else if (currentTime.isSame(timeSlot5)) {91$(".form1").addClass("present");92};93timeSlot6 = moment().startOf('day').add(14, "hours");94currentTime = currentTime.startOf("hour");95if (currentTime.isAfter(timeSlot6)) {96$(".form2").addClass("past");97}98else if (currentTime.isBefore(timeSlot6)) {99$(".form2").addClass("future");100}101else if (currentTime.isSame(timeSlot6)) {102$(".form2").addClass("present");103};104timeSlot7 = moment().startOf('day').add(15, "hours");105currentTime = currentTime.startOf("hour");106if (currentTime.isAfter(timeSlot7)) {107$(".form3").addClass("past");108}109else if (currentTime.isBefore(timeSlot7)) {110$(".form3").addClass("future");111}112else if (currentTime.isSame(timeSlot7)) {113$(".form3").addClass("present");114};115timeSlot8 = moment().startOf('day').add(16, "hours");116currentTime = currentTime.startOf("hour");117if (currentTime.isAfter(timeSlot8)) {118$(".form4").addClass("past");119}120else if (currentTime.isBefore(timeSlot8)) {121$(".form4").addClass("future");122}123else if (currentTime.isSame(timeSlot8)) {124$(".form4").addClass("present");125};126timeSlot9 = moment().startOf('day').add(16, "hours");127currentTime = currentTime.startOf("hour");128if (currentTime.isAfter(timeSlot9)) {129 $(".form5").addClass("past");130 }131 else if (currentTime.isBefore(timeSlot9)) {132 $(".form5").addClass("future");133 }134 else if (currentTime.isSame(timeSlot9)) {135 $(".form5").addClass("present");136 };137}138timeTest();139//the following for loop cycles through the input area to get item from local storage.140var x = [9, 10, 11, 12, 1, 2, 3, 4, 5];141for (var i = 0; i < x.length; i++) {142 var localHour = localStorage.getItem(x[i]);143 $(".form" + x[i]).val(localHour);144} 145// the following code saves input to local storage when the ".saveBtn" is clicked146 $(".saveBtn").click(function() {147 event.preventDefault();148 var form = $(this).siblings(".form-control").val();149 var list =$(this).parent().data("hour");150 localStorage.setItem(list, form);151 });...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.log(err);4 console.log(data);5 wpt.getTestStatus(data.data.testId, function(err, data) {6 if (err) return console.log(err);7 console.log(data);8 });9});10{ [Error: getaddrinfo ENOTFOUND www.webpagetest.org www.webpagetest.org:80]11 port: 80 }
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3if (err)4console.log(err);5console.log(data);6});7wpt.getTestResults(data.data.testId, function(err, data) {8if (err)9console.log(err);10console.log(data);11});12wpt.getLocations(function(err, data) {13if (err)14console.log(err);15console.log(data);16});17wpt.getBrowsers(function(err, data) {18if (err)19console.log(err);20console.log(data);21});22wpt.getTesters(function(err, data) {23if (err)24console.log(err);25console.log(data);26});27wpt.getLocations(function(err, data) {28if (err)29console.log(err);30console.log(data);31});32wpt.getTesters(function(err, data) {33if (err)34console.log(err);35console.log(data);36});37wpt.getTesters(function(err, data) {38if (err)39console.log(err);40console.log(data);41});42wpt.getTesters(function(err, data) {43if (err)44console.log(err);45console.log(data);46});47wpt.getTesters(function(err, data) {48if (err)49console.log(err);50console.log(data);51});52wpt.getTesters(function(err, data) {53if (err)54console.log(err);55console.log(data);56});57wpt.getTesters(function(err, data) {58if (err)59console.log(err);60console.log(data);61});
Using AI Code Generation
1var time = wpt.currentTime();2console.log(time);3var time = wpt.currentTime();4console.log(time);5var time = wpt.currentTime();6console.log(time);7var time = wpt.currentTime();8console.log(time);9var time = wpt.currentTime();10console.log(time);11var time = wpt.currentTime();12console.log(time);13var time = wpt.currentTime();14console.log(time);15var time = wpt.currentTime();16console.log(time);17var time = wpt.currentTime();18console.log(time);19var time = wpt.currentTime();20console.log(time);21var time = wpt.currentTime();22console.log(time);23var time = wpt.currentTime();24console.log(time);25var time = wpt.currentTime();26console.log(time);27var time = wpt.currentTime();28console.log(time);29var time = wpt.currentTime();30console.log(time);31var time = wpt.currentTime();32console.log(time);33var time = wpt.currentTime();34console.log(time);35var time = wpt.currentTime();36console.log(time);37var time = wpt.currentTime();38console.log(time);39var time = wpt.currentTime();40console.log(time);
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3wpt.runTest(url, function(err, data) {4 if (err) return console.error(err);5 wpt.getTestResults(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log(data.data.median.firstView.TTFB);8 });9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');12wpt.runTest(url, function(err, data) {13 if (err) return console.error(err);14 wpt.getTestResults(data.data.testId, function(err, data) {15 if (err) return console.error(err);16 console.log(data.data.median.firstView.TTFB);17 });18});
Using AI Code Generation
1var wpt = require('wpt');2wpt.getTestStatus('1234567890', function(err, status) {3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test Status: ' + status.status);7 }8});9var wpt = require('wpt');10wpt.getTestStatus('1234567890', function(err, status) {11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log('Test Status: ' + status.status);15 }16});17var wpt = require('wpt');18wpt.getTestStatus('1234567890', function(err, status) {19 if (err) {20 console.log('Error: ' + err);21 } else {22 console.log('Test Status: ' + status.status);23 }24});25var wpt = require('wpt');26wpt.getTestStatus('1234567890', function(err, status) {27 if (err) {28 console.log('Error: ' + err);29 } else {30 console.log('Test Status: ' + status.status);31 }32});33var wpt = require('wpt');34wpt.getTestStatus('1234567890', function(err, status) {35 if (err) {36 console.log('Error: ' + err);37 } else {38 console.log('Test Status: ' + status.status);39 }40});41var wpt = require('wpt');42wpt.getTestStatus('1234567890', function(err, status) {43 if (err) {44 console.log('Error: ' + err);45 } else {46 console.log('Test Status: ' + status.status);47 }48});49var wpt = require('wpt');50wpt.getTestStatus('1234567890', function(err, status) {51 if (err) {52 console.log('Error: ' + err);53 } else {54 console.log('Test Status: ' + status.status);55 }56});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestStatus('131105_8A_1Y', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var WebPageTest = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.getTestStatus('131105_8A_1Y', function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19npm ERR! at Error (native)20npm ERR! { [Error: EPERM: operation not permitted, open
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!