Skip to content

Commit 262d7cc

Browse files
committed
mojs-player: add backward precision steps evaluation
1 parent caa1061 commit 262d7cc

File tree

5 files changed

+80
-38
lines changed

5 files changed

+80
-38
lines changed

build/mojs-player.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
:: MojsPlayer :: Player controls for [mojs](mojs.io). Intended to help you to craft `mojs` animation sequences.
33
Oleg Solomka @LegoMushroom 2016 MIT
4-
0.43.9
4+
0.43.10
55
*/
66

77
(function webpackUniversalModuleDefinition(root, factory) {
@@ -177,7 +177,7 @@ return /******/ (function(modules) { // webpackBootstrap
177177
this._defaults.precision = 0.1;
178178
this._defaults.name = 'mojs-player';
179179

180-
this.revision = '0.43.9';
180+
this.revision = '0.43.10';
181181

182182
var str = this._fallbackTo(this._o.name, this._defaults.name);
183183
str += str === this._defaults.name ? '' : '__' + this._defaults.name;
@@ -481,7 +481,7 @@ return /******/ (function(modules) { // webpackBootstrap
481481

482482
if (p >= rightBound) {
483483

484-
this._reset();
484+
this._reset(rightBound === 1);
485485
// if ( rightBound === 1 ) { this._reset(); }
486486
// else { this._sysTween.pause(); }
487487

@@ -514,13 +514,29 @@ return /******/ (function(modules) { // webpackBootstrap
514514
};
515515
/*
516516
Method to reset sysTween and timeline.
517+
@param {Boolean} If should not set progress to 0.
517518
@private
518519
*/
519520

520521

521-
MojsPlayer.prototype._reset = function _reset() {
522+
MojsPlayer.prototype._reset = function _reset(isPause) {
522523
this._sysTween.reset();
523-
this.timeline.stop();
524+
525+
if (!isPause) {
526+
// this.timeline.pause();
527+
var p = this._props,
528+
progress = p.progress;
529+
530+
var start = progress,
531+
leftBound = p.isBounds ? p.leftBound : 0;
532+
533+
while (start - p.precision >= leftBound) {
534+
start -= p.precision;
535+
this.timeline.setProgress(start);
536+
}
537+
}
538+
539+
this.timeline.reset();
524540
};
525541
/*
526542
Method to set play button state.
@@ -592,15 +608,13 @@ return /******/ (function(modules) { // webpackBootstrap
592608

593609

594610
MojsPlayer.prototype._onStop = function _onStop() {
595-
this._props.isPlaying = false;
611+
var p = this._props;
612+
p.isPlaying = false;
596613

597-
// go to start of the timeline with icremental precision step
598-
var start = this._props.progress;
599-
while (start - this._props.precision > 0) {
600-
start -= this._props.precision;
601-
this._sysTween.setProgress(start);
602-
}
603-
this._sysTween.setProgress(0);
614+
var leftBound = p.isBounds ? p.leftBound : 0;
615+
// set sysTween progress twice because it could be _reset already
616+
this._sysTween.setProgress(leftBound + 0.01);
617+
this._sysTween.setProgress(leftBound);
604618

605619
this._reset();
606620
};

build/mojs-player.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/mojs-player.babel.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class MojsPlayer extends Module {
308308

309309
if ( p >= rightBound ) {
310310

311-
this._reset();
311+
this._reset( rightBound === 1 );
312312
// if ( rightBound === 1 ) { this._reset(); }
313313
// else { this._sysTween.pause(); }
314314

@@ -334,11 +334,27 @@ class MojsPlayer extends Module {
334334
}
335335
/*
336336
Method to reset sysTween and timeline.
337+
@param {Boolean} If should not set progress to 0.
337338
@private
338339
*/
339-
_reset () {
340+
_reset (isPause) {
340341
this._sysTween.reset();
341-
this.timeline.stop();
342+
343+
if ( !isPause ) {
344+
// this.timeline.pause();
345+
const p = this._props,
346+
progress = p.progress;
347+
348+
let start = progress,
349+
leftBound = ( p.isBounds ) ? p.leftBound : 0;
350+
351+
while ( (start - p.precision) >= leftBound ) {
352+
start -= p.precision;
353+
this.timeline.setProgress( start );
354+
}
355+
}
356+
357+
this.timeline.reset();
342358
}
343359
/*
344360
Method to set play button state.
@@ -394,15 +410,13 @@ class MojsPlayer extends Module {
394410
@private
395411
*/
396412
_onStop ( ) {
397-
this._props.isPlaying = false;
413+
const p = this._props;
414+
p.isPlaying = false;
398415

399-
// go to start of the timeline with icremental precision step
400-
let start = this._props.progress;
401-
while ( start - this._props.precision > 0 ) {
402-
start -= this._props.precision;
403-
this._sysTween.setProgress( start );
404-
}
405-
this._sysTween.setProgress( 0 );
416+
const leftBound = ( p.isBounds ) ? p.leftBound : 0;
417+
// set sysTween progress twice because it could be _reset already
418+
this._sysTween.setProgress( leftBound + 0.01 );
419+
this._sysTween.setProgress( leftBound );
406420

407421
this._reset();
408422
}

lib/mojs-player.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ var MojsPlayer = function (_Module) {
418418

419419
if (p >= rightBound) {
420420

421-
this._reset();
421+
this._reset(rightBound === 1);
422422
// if ( rightBound === 1 ) { this._reset(); }
423423
// else { this._sysTween.pause(); }
424424

@@ -451,13 +451,29 @@ var MojsPlayer = function (_Module) {
451451
};
452452
/*
453453
Method to reset sysTween and timeline.
454+
@param {Boolean} If should not set progress to 0.
454455
@private
455456
*/
456457

457458

458-
MojsPlayer.prototype._reset = function _reset() {
459+
MojsPlayer.prototype._reset = function _reset(isPause) {
459460
this._sysTween.reset();
460-
this.timeline.stop();
461+
462+
if (!isPause) {
463+
// this.timeline.pause();
464+
var p = this._props,
465+
progress = p.progress;
466+
467+
var start = progress,
468+
leftBound = p.isBounds ? p.leftBound : 0;
469+
470+
while (start - p.precision >= leftBound) {
471+
start -= p.precision;
472+
this.timeline.setProgress(start);
473+
}
474+
}
475+
476+
this.timeline.reset();
461477
};
462478
/*
463479
Method to set play button state.
@@ -529,15 +545,13 @@ var MojsPlayer = function (_Module) {
529545

530546

531547
MojsPlayer.prototype._onStop = function _onStop() {
532-
this._props.isPlaying = false;
548+
var p = this._props;
549+
p.isPlaying = false;
533550

534-
// go to start of the timeline with icremental precision step
535-
var start = this._props.progress;
536-
while (start - this._props.precision > 0) {
537-
start -= this._props.precision;
538-
this._sysTween.setProgress(start);
539-
}
540-
this._sysTween.setProgress(0);
551+
var leftBound = p.isBounds ? p.leftBound : 0;
552+
// set sysTween progress twice because it could be _reset already
553+
this._sysTween.setProgress(leftBound + 0.01);
554+
this._sysTween.setProgress(leftBound);
541555

542556
this._reset();
543557
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mojs-player",
33
"description": "Player controls for mojs playback",
4-
"version": "0.43.10",
4+
"version": "0.43.11",
55
"license": "MIT",
66
"private": false,
77
"scripts": { },

0 commit comments

Comments
 (0)