Skip to content

Commit

Permalink
Remove prefix in ResumePlugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Jan 31, 2025
1 parent 8c8a515 commit 8bc0107
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/BookReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/plugin.resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/jest/BookReader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/jest/plugins/plugin.resume.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 8bc0107

Please sign in to comment.