From 8bc0107d7c6bdc4c75eb3948cd04f88172dd4e7c Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Fri, 31 Jan 2025 01:26:41 -0500 Subject: [PATCH] Remove prefix in ResumePlugin options --- src/BookReader.js | 2 +- src/plugins/plugin.resume.js | 12 ++++++------ tests/jest/BookReader.test.js | 4 ++-- tests/jest/plugins/plugin.resume.test.js | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/BookReader.js b/src/BookReader.js index 30ca97251..c6ce826f4 100644 --- a/src/BookReader.js +++ b/src/BookReader.js @@ -401,7 +401,7 @@ BookReader.prototype.initParams = function() { } // Check for Resume plugin - if (this.options.enablePageResume) { + if (this._plugins.resume?.options.enabled) { // Check cookies const val = this._plugins.resume.getResumeValue(); if (val !== null) { diff --git a/src/plugins/plugin.resume.js b/src/plugins/plugin.resume.js index ccc5cf031..bb1b261f3 100644 --- a/src/plugins/plugin.resume.js +++ b/src/plugins/plugin.resume.js @@ -12,14 +12,14 @@ BookReader.docCookies = docCookies; */ export class ResumePlugin extends BookReaderPlugin { options = { - enablePageResume: true, + enabled: true, /** @type {string|null} eg '/', '/details/id' */ - resumeCookiePath: null, + cookiePath: null, } /** @override */ init() { - if (this.options.enablePageResume) { + if (this.options.enabled) { this.br.bind(EVENTS.fragmentChange, () => { const params = this.br.paramsFromCurrent(); this.updateResumeValue(params.index); @@ -60,9 +60,9 @@ export class ResumePlugin extends BookReaderPlugin { */ updateResumeValue(index, cookieName) { const ttl = new Date(+new Date + 12096e5); // 2 weeks - // For multiple files in item, leave resumeCookiePath blank - // It's likely we can remove resumeCookiePath using getCookiePath() - const path = this.options.resumeCookiePath + // For multiple files in item, leave cookiePath blank + // It's likely we can remove cookiePath using getCookiePath() + const path = this.options.cookiePath || this.getCookiePath(window.location.pathname); BookReader.docCookies.setItem(cookieName || 'br-resume', index, ttl, path, null, false); } diff --git a/tests/jest/BookReader.test.js b/tests/jest/BookReader.test.js index 4dfee7562..cf050aae7 100644 --- a/tests/jest/BookReader.test.js +++ b/tests/jest/BookReader.test.js @@ -47,7 +47,7 @@ test('checks cookie when initParams called', () => { test('does not check cookie when initParams called', () => { br._plugins.resume.getResumeValue = jest.fn(() => null); br.urlReadFragment = jest.fn(() => ''); - br.options.enablePageResume = false; + br.options.plugins.resume.enabled = false; const params = br.initParams(); expect(br._plugins.resume.getResumeValue).toHaveBeenCalledTimes(0); @@ -59,7 +59,7 @@ test('does not check cookie when initParams called', () => { test('gets index from fragment when both fragment and cookie when InitParams called', () => { br._plugins.resume.getResumeValue = jest.fn(() => 15); br.urlReadFragment = jest.fn(() => 'page/n4'); - br.options.enablePageResume = true; + br.options.plugins.resume.enabled = true; const params = br.initParams(); expect(br._plugins.resume.getResumeValue).toHaveBeenCalledTimes(1); diff --git a/tests/jest/plugins/plugin.resume.test.js b/tests/jest/plugins/plugin.resume.test.js index a036de4e0..47102d27e 100644 --- a/tests/jest/plugins/plugin.resume.test.js +++ b/tests/jest/plugins/plugin.resume.test.js @@ -36,7 +36,7 @@ describe('updateResumeValue', () => { test('handles cookieName=null', () => { const p = new ResumePlugin(null); - p.setup({ resumeCookiePath: '/details/goody' }); + p.setup({ cookiePath: '/details/goody' }); const setItemSpy = sinon.spy(docCookies, 'setItem'); p.updateResumeValue(16); @@ -45,7 +45,7 @@ describe('updateResumeValue', () => { expect(setItemSpy.args[0][3]).toEqual('/details/goody'); }); - test('handles resumeCookiePath not set', () => { + test('handles cookiePath not set', () => { const setItemSpy = sinon.spy(docCookies, 'setItem'); // Save function const saveFn = br._plugins.resume.getCookiePath;