@internetarchive/bookreader 5.0.0-50 → 5.0.0-51

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 5.0.0-51
2
+ - Fix: Bookmark with subfiles was broken
3
+ - Feature: Default 1up mode and options.defaults mode override exiting mode
4
+
1
5
  # 5.0.0-50
2
6
  Fix: Search results display @latonv
3
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/bookreader",
3
- "version": "5.0.0-50",
3
+ "version": "5.0.0-51",
4
4
  "description": "The Internet Archive BookReader.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -137,7 +137,7 @@ class IABookmarks extends LitElement {
137
137
  }
138
138
 
139
139
  setup() {
140
- this.api.identifier = this.bookreader.bookId;
140
+ this.api.identifier = this.getIdentifier();
141
141
  if (this.displayMode === 'login') {
142
142
  return;
143
143
  }
@@ -145,6 +145,19 @@ class IABookmarks extends LitElement {
145
145
  this.setBREventListeners();
146
146
  }
147
147
 
148
+ /**
149
+ * get identifier for current book including sub-files
150
+ *
151
+ * @returns Identifer
152
+ */
153
+ getIdentifier() {
154
+ if (this.bookreader.bookId !== this.bookreader.subPrefix) {
155
+ return `${this.bookreader.bookId}/${this.bookreader.subPrefix}`;
156
+ }
157
+
158
+ return this.bookreader.bookId;
159
+ }
160
+
148
161
  updateDisplay() {
149
162
  if (this.displayMode === 'bookmarks') {
150
163
  this.fetchUserBookmarks();
package/src/BookReader.js CHANGED
@@ -455,16 +455,18 @@ BookReader.prototype.readQueryString = function() {
455
455
  * @return {number} the mode
456
456
  */
457
457
  BookReader.prototype.getInitialMode = function(params) {
458
- // Use params or browser width to set view mode
459
- const windowWidth = $(window).width();
460
458
  let nextMode;
459
+
460
+ // if mobile breakpoint, we always show this.constMode1up mode
461
+ const ifMobileBreakpoint = () => {
462
+ // Use params or browser width to set view mode
463
+ const windowWidth = $(window).width();
464
+ return windowWidth && windowWidth <= this.onePageMinBreakpoint;
465
+ };
461
466
  if ('undefined' != typeof(params.mode)) {
462
467
  nextMode = params.mode;
463
- } else if (this.ui == 'full'
464
- && this.isFullscreenActive
465
- && windowWidth <= this.onePageMinBreakpoint
466
- ) {
467
- // In full mode, we set the default based on width
468
+ } else if ((this.ui == 'full' && this.isFullscreenActive) || ifMobileBreakpoint()) {
469
+ // In full mode OR device width, we set the default based on width
468
470
  nextMode = this.constMode1up;
469
471
  } else {
470
472
  nextMode = this.constMode2up;
@@ -473,6 +475,36 @@ BookReader.prototype.getInitialMode = function(params) {
473
475
  if (!this.canSwitchToMode(nextMode)) {
474
476
  nextMode = this.constMode1up;
475
477
  }
478
+
479
+ // override defaults mode via `options.defaults` metadata
480
+ if (this.options.defaults) {
481
+ nextMode = this.overridesBookMode();
482
+ }
483
+
484
+ return nextMode;
485
+ };
486
+
487
+ /**
488
+ * Overrides book mode using options.defaults param
489
+ * @return {number} the mode
490
+ */
491
+ BookReader.prototype.overridesBookMode = function() {
492
+ let nextMode = 2; // set default 2 (mode/2up)
493
+
494
+ switch (this.options.defaults) {
495
+ case 'mode/1up':
496
+ nextMode = this.constMode1up;
497
+ break;
498
+ case 'mode/2up':
499
+ nextMode = this.constMode2up;
500
+ break;
501
+ case 'mode/thumb':
502
+ nextMode = this.constModeThumb;
503
+ break;
504
+ default:
505
+ break;
506
+ }
507
+
476
508
  return nextMode;
477
509
  };
478
510
 
@@ -279,4 +279,35 @@ describe('nextReduce', () => {
279
279
  expect(nextReduce(2, 'auto', SAMPLE_FACTORS).reduce).toBe(0.5);
280
280
  });
281
281
  });
282
+
283
+ describe('Override book page mode using options.default param', () => {
284
+ test('replace current mode with options.default is set mode/1up', () => {
285
+ br.options.defaults = 'mode/1up';
286
+
287
+ const nextModeNumber = br.overridesBookMode();
288
+ expect(nextModeNumber).toBe(1);
289
+ });
290
+
291
+ test('replace current mode with options.default is set mode/2up', () => {
292
+ br.options.defaults = 'mode/2up';
293
+
294
+ const nextModeNumber = br.overridesBookMode();
295
+ expect(nextModeNumber).toBe(2);
296
+ });
297
+
298
+ test('replace current mode with options.default is set mode/thumb', () => {
299
+ br.options.defaults = 'mode/thumb';
300
+
301
+ const nextModeNumber = br.overridesBookMode();
302
+ expect(nextModeNumber).toBe(3);
303
+ });
304
+
305
+ test('test if options.default is NOT set', () => {
306
+ br.options.defaults = null;
307
+
308
+ // use mode/2up as default when no options.default metadata found
309
+ const nextModeNumber = br.overridesBookMode();
310
+ expect(nextModeNumber).toBe(2);
311
+ });
312
+ });
282
313
  });
File without changes