Skip to content

Commit

Permalink
Remove prefix of AutoplayPlugin methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Jan 30, 2025
1 parent 7532d20 commit 113f59e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
26 changes: 13 additions & 13 deletions src/plugins/plugin.autoplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export class AutoplayPlugin extends BookReaderPlugin {
urlParams: true,
}

autoTimer = null;
timer = null;

/** @override */
init() {
if (!this.options.enabled) return;

this.br.bind(EVENTS.stop, () => this.autoStop());
this.br.bind(EVENTS.stop, () => this.stop());

if (this.options.urlParams) {
const urlParams = new URLSearchParams(window.location.search);
Expand All @@ -38,7 +38,7 @@ export class AutoplayPlugin extends BookReaderPlugin {
this.options.flipDelay = parseAnimationSpeed(urlParams.get('flipDelay')) || this.options.flipDelay;
}
if (urlParams.get('autoflip') === '1') {
this.autoToggle();
this.toggle();

Check warning on line 41 in src/plugins/plugin.autoplay.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plugin.autoplay.js#L41

Added line #L41 was not covered by tests
}
}
}
Expand All @@ -50,12 +50,12 @@ export class AutoplayPlugin extends BookReaderPlugin {
const jIcons = this.br.$('.BRicon');

jIcons.filter('.play').on('click', () => {
this.autoToggle();
this.toggle();

Check warning on line 53 in src/plugins/plugin.autoplay.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plugin.autoplay.js#L53

Added line #L53 was not covered by tests
return false;
});

jIcons.filter('.pause').on('click', () => {
this.autoToggle();
this.toggle();

Check warning on line 58 in src/plugins/plugin.autoplay.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plugin.autoplay.js#L58

Added line #L58 was not covered by tests
return false;
});
}
Expand All @@ -66,7 +66,7 @@ export class AutoplayPlugin extends BookReaderPlugin {
* @param {number} overrides.flipSpeed
* @param {number} overrides.flipDelay
*/
autoToggle(overrides = null) {
toggle(overrides = null) {
if (!this.options.enabled) return;

Object.assign(this.options, overrides);
Expand All @@ -78,7 +78,7 @@ export class AutoplayPlugin extends BookReaderPlugin {
this.br.switchMode(this.br.constMode2up);
}

if (null == this.autoTimer) {
if (null == this.timer) {
// $$$ Draw events currently cause layout problems when they occur during animation.
// There is a specific problem when changing from 1-up immediately to autoplay in RTL so
// we workaround for now by not triggering immediate animation in that case.
Expand All @@ -92,7 +92,7 @@ export class AutoplayPlugin extends BookReaderPlugin {

this.br.$('.play').hide();
this.br.$('.pause').show();
this.autoTimer = setInterval(() => {
this.timer = setInterval(() => {
if (this.br.animating) return;

if (Math.max(this.br.twoPage.currentIndexL, this.br.twoPage.currentIndexR) >= this.br.book.getNumLeafs() - 1) {
Expand All @@ -102,21 +102,21 @@ export class AutoplayPlugin extends BookReaderPlugin {
}
}, parseAnimationSpeed(this.options.flipDelay));
} else {
this.autoStop();
this.stop();

Check warning on line 105 in src/plugins/plugin.autoplay.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plugin.autoplay.js#L105

Added line #L105 was not covered by tests
}
}

/**
* Stop autoplay mode, allowing animations to finish
*/
autoStop() {
stop() {
if (!this.options.enabled) return;

if (null != this.autoTimer) {
clearInterval(this.autoTimer);
if (null != this.timer) {
clearInterval(this.timer);
this.br.$('.pause').hide();
this.br.$('.play').show();
this.autoTimer = null;
this.timer = null;

Check warning on line 119 in src/plugins/plugin.autoplay.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plugin.autoplay.js#L116-L119

Added lines #L116 - L119 were not covered by tests
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tts/plugin.tts.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ BookReader.prototype.initNavbar = (function (super_) {
// ttsToggle()
//______________________________________________________________________________
BookReader.prototype.ttsToggle = function () {
this._plugins.autoplay?.autoStop();
this._plugins.autoplay?.stop();
if (this.ttsEngine.playing) {
this.ttsStop();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/url/plugin.url.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ BookReader.prototype.urlStartLocationPolling = function() {
this.trigger(BookReader.eventNames.stop);
if (this.animating) {
// Queue change if animating
this._plugins.autoplay?.autoStop();
this._plugins.autoplay?.stop();

Check warning on line 109 in src/plugins/url/plugin.url.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/url/plugin.url.js#L109

Added line #L109 was not covered by tests
this.animationFinishedCallback = updateParams;
} else {
// update immediately
Expand Down
16 changes: 8 additions & 8 deletions tests/jest/plugins/plugin.autoplay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ afterEach(() => {

describe('Plugin: Menu Toggle', () => {
test('autoplay does not start when BookReaderInitializes', () => {
br._plugins.autoplay.autoToggle = jest.fn();
br._plugins.autoplay.toggle = jest.fn();
br.init();
expect(br._plugins.autoplay.autoToggle).toHaveBeenCalledTimes(0);
expect(br._plugins.autoplay.toggle).toHaveBeenCalledTimes(0);
});
test('autoplay will run without `flipSpeed` parameters', () => {
const initialAutoTimer = br._plugins.autoplay.autoTimer;
const initialTimer = br._plugins.autoplay.timer;
br.next = jest.fn();
br._plugins.autoplay.autoStop = jest.fn();
br._plugins.autoplay.stop = jest.fn();
br.init();
br._plugins.autoplay.autoToggle();
br._plugins.autoplay.toggle();
// internally referenced functions that fire
expect(br.next).toHaveBeenCalledTimes(1);

expect(initialAutoTimer).toBeFalsy();
// autoTimer changes when autoToggle turns on
expect(br._plugins.autoplay.autoTimer).toBeTruthy();
expect(initialTimer).toBeFalsy();
// timer changes when autoplay turns on
expect(br._plugins.autoplay.timer).toBeTruthy();
});
});

0 comments on commit 113f59e

Please sign in to comment.