diff --git a/src/plugins/plugin.autoplay.js b/src/plugins/plugin.autoplay.js index 2a2bbf29a..ae9242c50 100644 --- a/src/plugins/plugin.autoplay.js +++ b/src/plugins/plugin.autoplay.js @@ -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); @@ -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(); } } } @@ -50,12 +50,12 @@ export class AutoplayPlugin extends BookReaderPlugin { const jIcons = this.br.$('.BRicon'); jIcons.filter('.play').on('click', () => { - this.autoToggle(); + this.toggle(); return false; }); jIcons.filter('.pause').on('click', () => { - this.autoToggle(); + this.toggle(); return false; }); } @@ -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); @@ -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. @@ -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) { @@ -102,21 +102,21 @@ export class AutoplayPlugin extends BookReaderPlugin { } }, parseAnimationSpeed(this.options.flipDelay)); } else { - this.autoStop(); + this.stop(); } } /** * 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; } } } diff --git a/src/plugins/tts/plugin.tts.js b/src/plugins/tts/plugin.tts.js index 2496a19c9..7de17d750 100644 --- a/src/plugins/tts/plugin.tts.js +++ b/src/plugins/tts/plugin.tts.js @@ -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 { diff --git a/src/plugins/url/plugin.url.js b/src/plugins/url/plugin.url.js index 7f1f74025..2e5cf424a 100644 --- a/src/plugins/url/plugin.url.js +++ b/src/plugins/url/plugin.url.js @@ -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(); this.animationFinishedCallback = updateParams; } else { // update immediately diff --git a/tests/jest/plugins/plugin.autoplay.test.js b/tests/jest/plugins/plugin.autoplay.test.js index e422ebbd1..86f71db18 100644 --- a/tests/jest/plugins/plugin.autoplay.test.js +++ b/tests/jest/plugins/plugin.autoplay.test.js @@ -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(); }); });