Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit a9d95d2

Browse files
committed
added this.toggle() and this.isPlaying
I just needed some state to indicate if the simulation is running or not. During the initialization phase I setup the play button to the starting state (show the play symbol) since I assume runway-browser does not init to a running sim, furthermore I call toggle(cb) on every click and check the sim state within toggle to start or stop the sim. I call the callback with the playing state (true is running, false is stopped) to take care of updating the UI.
1 parent ee456f7 commit a9d95d2

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

dist/index.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464

6565
<div>
6666
<div class="control">
67-
<div style="display: none">
68-
<!-- #playback is relied on in the codebase, so I just hid it -->
69-
Playback
70-
<input type="checkbox" id="playback" />
71-
</div>
7267
<div class="btn-group" role="group" aria-label="playbackgroup">
7368
<button id="slower" class="btn btn-default">
7469
<span class="glyphicon glyphicon-minus"></span>&nbsp;

lib/web.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,21 @@ class Playback {
313313
jQuery('body > div')
314314
.addClass('paused');
315315

316-
jQuery('#playback').change(() => {
317-
if (jQuery('#playback')[0].checked) {
318-
this.start();
319-
jQuery('#playbutton .play').hide();
320-
jQuery('#playbutton .pause').show();
321-
} else {
322-
this.stop();
323-
jQuery('#playbutton .pause').hide();
324-
jQuery('#playbutton .play').show();
325-
}
316+
jQuery('#playbutton .play').show();
317+
jQuery('#playbutton .pause').hide();
318+
319+
jQuery('#playbutton').click(_ => {
320+
this.toggle(playing => {
321+
if (playing == true) {
322+
jQuery('#playbutton .play').show();
323+
jQuery('#playbutton .pause').hide();
324+
} else {
325+
jQuery('#playbutton .pause').show();
326+
jQuery('#playbutton .play').hide();
327+
}
328+
});
326329
});
327330

328-
jQuery('#playbutton').click(() => jQuery('#playback')[0].click());
329-
330331
jQuery('#details').click(() => {
331332
if (jQuery('#tabs').is(':visible')) {
332333
jQuery('#tabs').hide();
@@ -340,10 +341,10 @@ class Playback {
340341
window.cancelAnimationFrame(this.animationId);
341342
this.animationId = undefined;
342343
pageLoaded.then(() => {
343-
jQuery('#playback')[0].checked = false;
344344
jQuery('body > div')
345345
.addClass('paused')
346346
.removeClass('playback');
347+
this.isPlaying = false;
347348
});
348349
}
349350

@@ -362,17 +363,26 @@ class Playback {
362363
when => this.onAnimationFrame(when));
363364
}
364365

366+
toggle(cb) {
367+
if(this.isPlaying == true) {
368+
this.stop();
369+
} else {
370+
this.start();
371+
}
372+
cb(this.isPlaying);
373+
}
374+
365375
start() {
366376
if (this.animationId !== undefined) {
367377
return;
368378
}
369379
this.animationId = window.requestAnimationFrame(
370380
when => this.onAnimationFrame(when));
371381
pageLoaded.then(() => {
372-
jQuery('#playback')[0].checked = true;
373382
jQuery('body > div')
374383
.addClass('playback')
375384
.removeClass('paused');
385+
this.isPlaying = true;
376386
});
377387
}
378388

0 commit comments

Comments
 (0)