@internetarchive/bookreader 5.0.0-92 → 5.0.0-94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BookReader/BookReader.css +2 -1
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +14 -14
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/images/hypothesis.ico +0 -0
- package/BookReader/jquery-3.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +2 -2
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.experiments.js +3 -0
- package/BookReader/plugins/plugin.experiments.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.experiments.js.map +1 -0
- package/BookReader/plugins/plugin.iframe.js +1 -1
- package/BookReader/plugins/plugin.iiif.js +1 -1
- package/BookReader/plugins/plugin.iiif.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReaderDemo/IADemoBr.js +1 -24
- package/BookReaderDemo/demo-internetarchive.html +1 -0
- package/CHANGELOG.md +14 -0
- package/package.json +8 -4
- package/scripts/postversion.js +3 -2
- package/scripts/preversion.js +3 -1
- package/scripts/version.js +4 -3
- package/src/BookNavigator/book-navigator.js +38 -12
- package/src/BookNavigator/downloads/downloads-provider.js +2 -2
- package/src/BookNavigator/search/search-provider.js +5 -5
- package/src/BookNavigator/search/search-results.js +1 -1
- package/src/BookNavigator/sharing.js +2 -2
- package/src/BookNavigator/viewable-files.js +2 -2
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +3 -3
- package/src/BookNavigator/visual-adjustments/visual-adjustments.js +2 -2
- package/src/BookReader/BookModel.js +13 -3
- package/src/BookReader/ImageCache.js +2 -2
- package/src/BookReader/Mode1Up.js +2 -0
- package/src/BookReader/Mode1UpLit.js +5 -5
- package/src/BookReader/Mode2Up.js +2 -0
- package/src/BookReader/Mode2UpLit.js +5 -5
- package/src/BookReader/ModeCoordinateSpace.js +1 -1
- package/src/BookReader/ModeThumb.js +2 -0
- package/src/BookReader/PageContainer.js +4 -1
- package/src/BookReader/Toolbar/Toolbar.js +1 -1
- package/src/BookReader/options.js +5 -0
- package/src/BookReader/utils/HTMLDimensionsCacher.js +1 -1
- package/src/BookReader/utils.js +13 -0
- package/src/BookReader.js +57 -31
- package/src/assets/images/hypothesis.ico +0 -0
- package/src/css/_TextSelection.scss +3 -1
- package/src/plugins/plugin.autoplay.js +3 -3
- package/src/plugins/plugin.chapters.js +2 -2
- package/src/plugins/plugin.experiments.js +294 -0
- package/src/plugins/plugin.iiif.js +1 -1
- package/src/plugins/plugin.text_selection.js +112 -1
- package/src/plugins/search/plugin.search.js +2 -2
- package/src/plugins/search/view.js +5 -5
- package/src/plugins/tts/plugin.tts.js +3 -3
- package/src/plugins/url/plugin.url.js +2 -2
- package/tests/e2e/autoplay.test.js +1 -1
- package/tests/e2e/base.test.js +4 -4
- package/tests/e2e/helpers/base.js +2 -2
- package/tests/e2e/models/BookReader.js +1 -1
- package/tests/e2e/rightToLeft.test.js +4 -4
- package/tests/e2e/viewmode.test.js +2 -2
- package/tests/jest/BookNavigator/book-navigator.test.js +0 -13
- package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +1 -1
- package/tests/jest/BookNavigator/downloads/downloads.test.js +1 -1
- package/tests/jest/BookNavigator/search/search-provider.test.js +5 -5
- package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +1 -1
- package/tests/jest/BookReader/Mode2Up.test.js +1 -1
- package/tests/jest/BookReader/ModeCoordinateSpace.test.js +1 -1
- package/tests/jest/BookReader/PageContainer.test.js +14 -3
- package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +1 -1
- package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +1 -1
- package/tests/jest/BookReader/utils/SelectionObserver.test.js +1 -1
- package/tests/jest/BookReader.test.js +10 -10
- package/tests/jest/plugins/plugin.autoplay.test.js +6 -6
- package/tests/jest/plugins/plugin.chapters.test.js +2 -2
- package/tests/jest/plugins/plugin.resume.test.js +13 -13
- package/tests/jest/plugins/plugin.text_selection.test.js +155 -24
- package/tests/jest/plugins/search/plugin.search.test.js +7 -7
- package/tests/jest/plugins/search/plugin.search.view.test.js +8 -8
- package/tests/jest/plugins/search/utils.js +1 -1
- package/tests/jest/plugins/tts/PageChunkIterator.test.js +2 -2
- package/tests/jest/plugins/url/UrlPlugin.test.js +1 -1
- package/webpack.config.js +8 -3
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
- /package/{.testcaferc.js → .testcaferc.cjs} +0 -0
- /package/{babel.config.js → babel.config.cjs} +0 -0
@@ -38,6 +38,8 @@ export class TextSelectionPlugin extends BookReaderPlugin {
|
|
38
38
|
singlePageDjvuXmlUrl: null,
|
39
39
|
/** Whether to fetch the XML as a jsonp */
|
40
40
|
jsonp: false,
|
41
|
+
/** Mox words tha can be selected when the text layer is protected */
|
42
|
+
maxProtectedWords: 200,
|
41
43
|
}
|
42
44
|
|
43
45
|
/**@type {PromiseLike<JQuery<HTMLElement>|undefined>} */
|
@@ -75,7 +77,7 @@ export class TextSelectionPlugin extends BookReaderPlugin {
|
|
75
77
|
new SelectionObserver('.BRtextLayer', (selectEvent) => {
|
76
78
|
// Track how often selection is used
|
77
79
|
if (selectEvent == 'started') {
|
78
|
-
this.br.
|
80
|
+
this.br.plugins.archiveAnalytics?.sendEvent('BookReader', 'SelectStart');
|
79
81
|
|
80
82
|
// Set a class on the page to avoid hiding it when zooming/etc
|
81
83
|
this.br.refs.$br.find('.BRpagecontainer--hasSelection').removeClass('BRpagecontainer--hasSelection');
|
@@ -84,6 +86,7 @@ export class TextSelectionPlugin extends BookReaderPlugin {
|
|
84
86
|
}).attach();
|
85
87
|
|
86
88
|
if (this.br.protected) {
|
89
|
+
document.addEventListener('selectionchange', this._limitSelection);
|
87
90
|
// Prevent right clicking when selected text
|
88
91
|
$(document.body).on('contextmenu dragstart copy', (e) => {
|
89
92
|
const selection = document.getSelection();
|
@@ -100,6 +103,41 @@ export class TextSelectionPlugin extends BookReaderPlugin {
|
|
100
103
|
}
|
101
104
|
}
|
102
105
|
|
106
|
+
_limitSelection = () => {
|
107
|
+
const selection = window.getSelection();
|
108
|
+
if (!selection.rangeCount) return;
|
109
|
+
|
110
|
+
const range = selection.getRangeAt(0);
|
111
|
+
|
112
|
+
// Check if range.startContainer is inside the sub-tree of .BRContainer
|
113
|
+
const startInBr = !!range.startContainer.parentElement.closest('.BRcontainer');
|
114
|
+
const endInBr = !!range.endContainer.parentElement.closest('.BRcontainer');
|
115
|
+
if (!startInBr && !endInBr) return;
|
116
|
+
if (!startInBr || !endInBr) {
|
117
|
+
// weird case, just clear the selection
|
118
|
+
selection.removeAllRanges();
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
|
122
|
+
// Find the last allowed word in the selection
|
123
|
+
const lastAllowedWord = genAt(
|
124
|
+
genFilter(
|
125
|
+
walkBetweenNodes(range.startContainer, range.endContainer),
|
126
|
+
(node) => node.classList?.contains('BRwordElement'),
|
127
|
+
),
|
128
|
+
this.options.maxProtectedWords - 1,
|
129
|
+
);
|
130
|
+
|
131
|
+
if (!lastAllowedWord || range.endContainer.parentNode == lastAllowedWord) return;
|
132
|
+
|
133
|
+
const newRange = document.createRange();
|
134
|
+
newRange.setStart(range.startContainer, range.startOffset);
|
135
|
+
newRange.setEnd(lastAllowedWord.firstChild, lastAllowedWord.textContent.length);
|
136
|
+
|
137
|
+
selection.removeAllRanges();
|
138
|
+
selection.addRange(newRange);
|
139
|
+
};
|
140
|
+
|
103
141
|
/**
|
104
142
|
* @override
|
105
143
|
* @param {PageContainer} pageContainer
|
@@ -511,6 +549,33 @@ function augmentLine(line) {
|
|
511
549
|
};
|
512
550
|
}
|
513
551
|
|
552
|
+
/**
|
553
|
+
* @template T
|
554
|
+
* Get the i-th element of an iterable
|
555
|
+
* @param {Iterable<T>} iterable
|
556
|
+
* @param {number} index
|
557
|
+
*/
|
558
|
+
export function genAt(iterable, index) {
|
559
|
+
let i = 0;
|
560
|
+
for (const x of iterable) {
|
561
|
+
if (i == index) return x;
|
562
|
+
i++;
|
563
|
+
}
|
564
|
+
return undefined;
|
565
|
+
}
|
566
|
+
|
567
|
+
/**
|
568
|
+
* @template T
|
569
|
+
* Generator version of filter
|
570
|
+
* @param {Iterable<T>} iterable
|
571
|
+
* @param {function(T): boolean} fn
|
572
|
+
*/
|
573
|
+
export function* genFilter(iterable, fn) {
|
574
|
+
for (const x of iterable) {
|
575
|
+
if (fn(x)) yield x;
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
514
579
|
/**
|
515
580
|
* @template TFrom, TTo
|
516
581
|
* Generator version of map
|
@@ -647,3 +712,49 @@ class Rect {
|
|
647
712
|
get top() { return this.y; }
|
648
713
|
get left() { return this.x; }
|
649
714
|
}
|
715
|
+
|
716
|
+
/**
|
717
|
+
* Depth traverse the DOM tree starting at `start`, and ending at `end`.
|
718
|
+
* @param {Node} start
|
719
|
+
* @param {Node} end
|
720
|
+
* @returns {Generator<Node>}
|
721
|
+
*/
|
722
|
+
export function* walkBetweenNodes(start, end) {
|
723
|
+
let done = false;
|
724
|
+
|
725
|
+
/**
|
726
|
+
* @param {Node} node
|
727
|
+
*/
|
728
|
+
function* walk(node, {children = true, parents = true, siblings = true} = {}) {
|
729
|
+
if (node === end) {
|
730
|
+
done = true;
|
731
|
+
yield node;
|
732
|
+
return;
|
733
|
+
}
|
734
|
+
|
735
|
+
// yield self
|
736
|
+
yield node;
|
737
|
+
|
738
|
+
// First iterate children (depth-first traversal)
|
739
|
+
if (children && node.firstChild) {
|
740
|
+
yield* walk(node.firstChild, {children: true, parents: false, siblings: true});
|
741
|
+
if (done) return;
|
742
|
+
}
|
743
|
+
|
744
|
+
// Then iterate siblings
|
745
|
+
if (siblings) {
|
746
|
+
for (let sib = node.nextSibling; sib; sib = sib.nextSibling) {
|
747
|
+
yield* walk(sib, {children: true, parents: false, siblings: false});
|
748
|
+
if (done) return;
|
749
|
+
}
|
750
|
+
}
|
751
|
+
|
752
|
+
// Finally, move up the tree
|
753
|
+
if (parents && node.parentNode) {
|
754
|
+
yield* walk(node.parentNode, {children: false, parents: true, siblings: true});
|
755
|
+
if (done) return;
|
756
|
+
}
|
757
|
+
}
|
758
|
+
|
759
|
+
yield* walk(start);
|
760
|
+
}
|
@@ -341,8 +341,8 @@ export class SearchPlugin extends BookReaderPlugin {
|
|
341
341
|
let makeUnviewableAtEnd = false;
|
342
342
|
if (!page.isViewable) {
|
343
343
|
const resp = await fetch('/services/bookreader/request_page?' + new URLSearchParams({
|
344
|
-
id: this.options.bookId,
|
345
|
-
subprefix: this.options.subPrefix,
|
344
|
+
id: this.br.options.bookId,
|
345
|
+
subprefix: this.br.options.subPrefix,
|
346
346
|
leafNum: page.leafNum,
|
347
347
|
})).then(r => r.json());
|
348
348
|
|
@@ -44,7 +44,7 @@ class SearchView {
|
|
44
44
|
}
|
45
45
|
|
46
46
|
clearSearchFieldAndResults(dispatchEventWhenComplete = true) {
|
47
|
-
this.br.
|
47
|
+
this.br.plugins.search.removeSearchResults();
|
48
48
|
this.removeResultPins();
|
49
49
|
this.emptyMatches();
|
50
50
|
this.setQuery('');
|
@@ -218,7 +218,7 @@ class SearchView {
|
|
218
218
|
<form class="BRbooksearch desktop">
|
219
219
|
<input type="search" name="query" class="BRsearchInput" value="" placeholder="Search inside"/>
|
220
220
|
<button type="submit" class="BRsearchSubmit">
|
221
|
-
<img src="${this.br.imagesBaseURL}icon_search_button.svg" />
|
221
|
+
<img src="${this.br.options.imagesBaseURL}icon_search_button.svg" />
|
222
222
|
</button>
|
223
223
|
</form>
|
224
224
|
`;
|
@@ -273,7 +273,7 @@ class SearchView {
|
|
273
273
|
$(event.target).addClass('front');
|
274
274
|
})
|
275
275
|
.on("mouseleave", (event) => $(event.target).removeClass('front'))
|
276
|
-
.on("click", () => { this.br.
|
276
|
+
.on("click", () => { this.br.plugins.search.jumpToMatch(match.matchIndex); });
|
277
277
|
});
|
278
278
|
}
|
279
279
|
|
@@ -379,11 +379,11 @@ class SearchView {
|
|
379
379
|
|
380
380
|
handleSearchStarted() {
|
381
381
|
this.emptyMatches();
|
382
|
-
this.br.
|
382
|
+
this.br.plugins.search.removeSearchHilites();
|
383
383
|
this.removeResultPins();
|
384
384
|
this.toggleSearchPending(true);
|
385
385
|
this.teardownSearchNavigation();
|
386
|
-
this.setQuery(this.br.
|
386
|
+
this.setQuery(this.br.plugins.search.searchTerm);
|
387
387
|
}
|
388
388
|
|
389
389
|
/**
|
@@ -199,7 +199,7 @@ export class TtsPlugin extends BookReaderPlugin {
|
|
199
199
|
}
|
200
200
|
|
201
201
|
toggle() {
|
202
|
-
this.br.
|
202
|
+
this.br.plugins.autoplay?.stop();
|
203
203
|
if (this.ttsEngine.playing) {
|
204
204
|
this.stop();
|
205
205
|
} else {
|
@@ -338,11 +338,11 @@ export class TtsPlugin extends BookReaderPlugin {
|
|
338
338
|
* @param {number} [value]
|
339
339
|
*/
|
340
340
|
sendAnalyticsEvent(action, value) {
|
341
|
-
if (this.br.
|
341
|
+
if (this.br.plugins.archiveAnalytics) {
|
342
342
|
const extraValues = {};
|
343
343
|
const mediaLanguage = this.ttsEngine.opts.bookLanguage;
|
344
344
|
if (mediaLanguage) extraValues.mediaLanguage = mediaLanguage;
|
345
|
-
this.br.
|
345
|
+
this.br.plugins.archiveAnalytics.sendEvent('BRReadAloud', action, value, extraValues);
|
346
346
|
}
|
347
347
|
}
|
348
348
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* global BookReader */
|
2
2
|
|
3
|
-
import { UrlPlugin } from "./UrlPlugin";
|
3
|
+
import { UrlPlugin } from "./UrlPlugin.js";
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Plugin for URL management in BookReader
|
@@ -106,7 +106,7 @@ BookReader.prototype.urlStartLocationPolling = function() {
|
|
106
106
|
this.trigger(BookReader.eventNames.stop);
|
107
107
|
if (this.animating) {
|
108
108
|
// Queue change if animating
|
109
|
-
this.
|
109
|
+
this.plugins.autoplay?.stop();
|
110
110
|
this.animationFinishedCallback = updateParams;
|
111
111
|
} else {
|
112
112
|
// update immediately
|
package/tests/e2e/base.test.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { runBaseTests } from './helpers/base';
|
2
|
-
import BookReader from './models/BookReader';
|
3
|
-
import { runSearchTests } from './helpers/search';
|
4
|
-
import params from './helpers/params';
|
1
|
+
import { runBaseTests } from './helpers/base.js';
|
2
|
+
import BookReader from './models/BookReader.js';
|
3
|
+
import { runSearchTests } from './helpers/search.js';
|
4
|
+
import params from './helpers/params.js';
|
5
5
|
|
6
6
|
const ocaids = params.ocaids || [
|
7
7
|
'theworksofplato01platiala',
|
@@ -78,8 +78,8 @@ export function runBaseTests (br) {
|
|
78
78
|
|
79
79
|
// Check if uses plugin.resume.js
|
80
80
|
const usesResume = ClientFunction(() => {
|
81
|
-
const hasResumePlugin = typeof(br.
|
82
|
-
const hasResumeValue = hasResumePlugin ? br.
|
81
|
+
const hasResumePlugin = typeof(br.plugins.resume) !== "undefined";
|
82
|
+
const hasResumeValue = hasResumePlugin ? br.plugins.resume.getResumeValue() : false;
|
83
83
|
return hasResumeValue;
|
84
84
|
});
|
85
85
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { runBaseTests } from './helpers/base';
|
2
|
-
import { runRightToLeftTests } from './helpers/rightToLeft';
|
3
|
-
import params from './helpers/params';
|
1
|
+
import { runBaseTests } from './helpers/base.js';
|
2
|
+
import { runRightToLeftTests } from './helpers/rightToLeft.js';
|
3
|
+
import params from './helpers/params.js';
|
4
4
|
|
5
|
-
import BookReader from './models/BookReader';
|
5
|
+
import BookReader from './models/BookReader.js';
|
6
6
|
|
7
7
|
const ocaids = params.ocaids || [
|
8
8
|
'gendaitankashu00meijuoft', // Right to Left book
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Selector } from 'testcafe';
|
2
|
-
import BookReader from './models/BookReader';
|
3
|
-
import params from './helpers/params';
|
2
|
+
import BookReader from './models/BookReader.js';
|
3
|
+
import params from './helpers/params.js';
|
4
4
|
|
5
5
|
const ocaids = params.ocaids || ['goody'];
|
6
6
|
|
@@ -323,19 +323,6 @@ describe('<book-navigator>', () => {
|
|
323
323
|
});
|
324
324
|
});
|
325
325
|
|
326
|
-
describe('Shortcuts', () => {
|
327
|
-
test('has specific order of menu shortcuts to show', () => {
|
328
|
-
const el = fixtureSync(container());
|
329
|
-
expect(el.shortcutOrder).toEqual([
|
330
|
-
'fullscreen',
|
331
|
-
'volumes',
|
332
|
-
'chapters',
|
333
|
-
'search',
|
334
|
-
'bookmarks',
|
335
|
-
]);
|
336
|
-
});
|
337
|
-
});
|
338
|
-
|
339
326
|
describe('Behaviors for specific menus', () => {
|
340
327
|
describe('Search menu - ref: plugin.search.js', () => {
|
341
328
|
test('Event: listens for `BookReader:ToggleSearchMenu to open search side panel', async () => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
|
2
2
|
import sinon from 'sinon';
|
3
|
-
import DownloadsProvider from '@/src/BookNavigator/downloads/downloads-provider';
|
3
|
+
import DownloadsProvider from '@/src/BookNavigator/downloads/downloads-provider.js';
|
4
4
|
|
5
5
|
const downloadableTypes = [
|
6
6
|
["PDF", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.pdf"],
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
|
2
2
|
import sinon from 'sinon';
|
3
|
-
import searchProvider from '@/src/BookNavigator/search/search-provider';
|
3
|
+
import searchProvider from '@/src/BookNavigator/search/search-provider.js';
|
4
4
|
|
5
5
|
afterEach(() => {
|
6
6
|
sinon.restore();
|
@@ -88,7 +88,7 @@ describe('Search Provider', () => {
|
|
88
88
|
onProviderChange: sinon.fake(),
|
89
89
|
bookreader: {
|
90
90
|
leafNumToIndex: sinon.fake(),
|
91
|
-
|
91
|
+
plugins: {
|
92
92
|
search: {
|
93
93
|
jumpToMatch: sinon.fake(),
|
94
94
|
},
|
@@ -104,7 +104,7 @@ describe('Search Provider', () => {
|
|
104
104
|
{ detail: searchResultStub }),
|
105
105
|
);
|
106
106
|
|
107
|
-
expect(provider.bookreader.
|
107
|
+
expect(provider.bookreader.plugins.search.jumpToMatch.callCount).toEqual(1);
|
108
108
|
});
|
109
109
|
test('update url when search is cancelled or input cleared', async() => {
|
110
110
|
const urlPluginMock = {
|
@@ -115,7 +115,7 @@ describe('Search Provider', () => {
|
|
115
115
|
onProviderChange: sinon.fake(),
|
116
116
|
bookreader: {
|
117
117
|
leafNumToIndex: sinon.fake(),
|
118
|
-
|
118
|
+
plugins: {
|
119
119
|
search: {
|
120
120
|
jumpToMatch: sinon.fake(),
|
121
121
|
},
|
@@ -153,7 +153,7 @@ describe('Search Provider', () => {
|
|
153
153
|
onProviderChange: sinon.fake(),
|
154
154
|
bookreader: {
|
155
155
|
leafNumToIndex: sinon.fake(),
|
156
|
-
|
156
|
+
plugins: {
|
157
157
|
search: {
|
158
158
|
jumpToMatch: sinon.fake(),
|
159
159
|
},
|
@@ -3,7 +3,7 @@ import sinon from 'sinon';
|
|
3
3
|
import { Mode2Up } from '@/src/BookReader/Mode2Up.js';
|
4
4
|
import BookReader from '@/src/BookReader.js';
|
5
5
|
import { BookModel } from '@/src/BookReader/BookModel.js';
|
6
|
-
import { afterEventLoop } from '../utils';
|
6
|
+
import { afterEventLoop } from '../utils.js';
|
7
7
|
/** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
8
8
|
|
9
9
|
beforeAll(() => {
|
@@ -52,15 +52,26 @@ describe('constructor', () => {
|
|
52
52
|
});
|
53
53
|
|
54
54
|
test('non-empty page', () => {
|
55
|
-
const
|
55
|
+
const page = {
|
56
|
+
index: 7,
|
57
|
+
getPageNum: () => '8',
|
58
|
+
};
|
59
|
+
const pc = new PageContainer(page, {isProtected: false});
|
56
60
|
expect(pc.$container.hasClass('BRemptypage')).toBe(false);
|
57
61
|
expect(pc.$container.hasClass('pagediv7')).toBe(true);
|
58
62
|
});
|
59
63
|
|
60
|
-
test('adds
|
61
|
-
const
|
64
|
+
test('adds attributes', () => {
|
65
|
+
const page = {
|
66
|
+
index: 7,
|
67
|
+
pageSide: 'R',
|
68
|
+
getPageNum: () => '8',
|
69
|
+
};
|
70
|
+
const pc = new PageContainer(page, {isProtected: false});
|
62
71
|
expect(pc.$container.hasClass('BRemptypage')).toBe(false);
|
63
72
|
expect(pc.$container.attr('data-side')).toBe('R');
|
73
|
+
expect(pc.$container.attr('data-index')).toBe('7');
|
74
|
+
expect(pc.$container.attr('data-page-num')).toBe('8');
|
64
75
|
});
|
65
76
|
});
|
66
77
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-check
|
2
2
|
import sinon from 'sinon';
|
3
|
-
import { HTMLDimensionsCacher } from '@/src/BookReader/utils/HTMLDimensionsCacher';
|
3
|
+
import { HTMLDimensionsCacher } from '@/src/BookReader/utils/HTMLDimensionsCacher.js';
|
4
4
|
|
5
5
|
describe('HTMLDimensionsCacher', () => {
|
6
6
|
test('Does not read from element directly', () => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-check
|
2
2
|
import sinon from 'sinon';
|
3
|
-
import { ScrollClassAdder } from '@/src/BookReader/utils/ScrollClassAdder';
|
3
|
+
import { ScrollClassAdder } from '@/src/BookReader/utils/ScrollClassAdder.js';
|
4
4
|
|
5
5
|
describe('ScrollClassAdder', () => {
|
6
6
|
test('Does not attach during construction', () => {
|
@@ -39,35 +39,35 @@ test('has registered fullscreen toggle event', () => {
|
|
39
39
|
});
|
40
40
|
|
41
41
|
test('checks cookie when initParams called', () => {
|
42
|
-
br.
|
42
|
+
br.plugins.resume.getResumeValue = jest.fn(() => 15);
|
43
43
|
br.urlReadFragment = jest.fn(() => '');
|
44
44
|
|
45
45
|
const params = br.initParams();
|
46
|
-
expect(br.
|
46
|
+
expect(br.plugins.resume.getResumeValue).toHaveBeenCalledTimes(1);
|
47
47
|
expect(params.init).toBe(true);
|
48
48
|
expect(params.index).toBe(15);
|
49
49
|
expect(params.fragmentChange).toBe(true);
|
50
50
|
});
|
51
51
|
|
52
52
|
test('does not check cookie when initParams called', () => {
|
53
|
-
br.
|
53
|
+
br.plugins.resume.getResumeValue = jest.fn(() => null);
|
54
54
|
br.urlReadFragment = jest.fn(() => '');
|
55
55
|
br.options.plugins.resume.enabled = false;
|
56
56
|
|
57
57
|
const params = br.initParams();
|
58
|
-
expect(br.
|
58
|
+
expect(br.plugins.resume.getResumeValue).toHaveBeenCalledTimes(0);
|
59
59
|
expect(params.init).toBe(true);
|
60
60
|
expect(params.index).toBe(0);
|
61
61
|
expect(params.fragmentChange).toBe(false);
|
62
62
|
});
|
63
63
|
|
64
64
|
test('gets index from fragment when both fragment and cookie when InitParams called', () => {
|
65
|
-
br.
|
65
|
+
br.plugins.resume.getResumeValue = jest.fn(() => 15);
|
66
66
|
br.urlReadFragment = jest.fn(() => 'page/n4');
|
67
67
|
br.options.plugins.resume.enabled = true;
|
68
68
|
|
69
69
|
const params = br.initParams();
|
70
|
-
expect(br.
|
70
|
+
expect(br.plugins.resume.getResumeValue).toHaveBeenCalledTimes(1);
|
71
71
|
expect(params.init).toBe(true);
|
72
72
|
expect(params.index).toBe(4);
|
73
73
|
expect(params.fragmentChange).toBe(true);
|
@@ -117,7 +117,7 @@ test('has added BR property: bookPath', () => {
|
|
117
117
|
});
|
118
118
|
|
119
119
|
test('has suppressFragmentChange true when init with no input', () => {
|
120
|
-
br.
|
120
|
+
br.plugins.resume.getResumeValue = jest.fn(() => null);
|
121
121
|
br.urlReadFragment = jest.fn(() => '');
|
122
122
|
br.urlReadHashFragment = jest.fn(() => '');
|
123
123
|
br.switchMode = jest.fn();
|
@@ -128,7 +128,7 @@ test('has suppressFragmentChange true when init with no input', () => {
|
|
128
128
|
});
|
129
129
|
|
130
130
|
test('has suppressFragmentChange false when init with cookie', () => {
|
131
|
-
br.
|
131
|
+
br.plugins.resume.getResumeValue = jest.fn(() => 5);
|
132
132
|
br.urlReadFragment = jest.fn(() => '');
|
133
133
|
br.switchMode = jest.fn();
|
134
134
|
|
@@ -138,7 +138,7 @@ test('has suppressFragmentChange false when init with cookie', () => {
|
|
138
138
|
});
|
139
139
|
|
140
140
|
test('has suppressFragmentChange false when init with fragment', () => {
|
141
|
-
br.
|
141
|
+
br.plugins.resume.getResumeValue = jest.fn(() => null);
|
142
142
|
br.urlReadFragment = jest.fn(() => 'mode/1up');
|
143
143
|
br.switchMode = jest.fn();
|
144
144
|
|
@@ -148,7 +148,7 @@ test('has suppressFragmentChange false when init with fragment', () => {
|
|
148
148
|
});
|
149
149
|
|
150
150
|
test('has suppressFragmentChange false when init with hash fragment', () => {
|
151
|
-
br.
|
151
|
+
br.plugins.resume.getResumeValue = jest.fn(() => null);
|
152
152
|
br.urlReadFragment = jest.fn(() => '');
|
153
153
|
br.urlReadHashFragment = jest.fn(() => 'mode/1up');
|
154
154
|
br.switchMode = jest.fn();
|
@@ -15,21 +15,21 @@ afterEach(() => {
|
|
15
15
|
|
16
16
|
describe('Plugin: Menu Toggle', () => {
|
17
17
|
test('autoplay does not start when BookReaderInitializes', () => {
|
18
|
-
br.
|
18
|
+
br.plugins.autoplay.toggle = jest.fn();
|
19
19
|
br.init();
|
20
|
-
expect(br.
|
20
|
+
expect(br.plugins.autoplay.toggle).toHaveBeenCalledTimes(0);
|
21
21
|
});
|
22
22
|
test('autoplay will run without `flipSpeed` parameters', () => {
|
23
|
-
const initialTimer = br.
|
23
|
+
const initialTimer = br.plugins.autoplay.timer;
|
24
24
|
br.next = jest.fn();
|
25
|
-
br.
|
25
|
+
br.plugins.autoplay.stop = jest.fn();
|
26
26
|
br.init();
|
27
|
-
br.
|
27
|
+
br.plugins.autoplay.toggle();
|
28
28
|
// internally referenced functions that fire
|
29
29
|
expect(br.next).toHaveBeenCalledTimes(1);
|
30
30
|
|
31
31
|
expect(initialTimer).toBeFalsy();
|
32
32
|
// timer changes when autoplay turns on
|
33
|
-
expect(br.
|
33
|
+
expect(br.plugins.autoplay.timer).toBeTruthy();
|
34
34
|
});
|
35
35
|
});
|
@@ -2,8 +2,8 @@ import sinon from "sinon";
|
|
2
2
|
|
3
3
|
import "@/src/BookReader.js";
|
4
4
|
import {ChaptersPlugin} from "@/src/plugins/plugin.chapters.js";
|
5
|
-
import { BookModel } from "@/src/BookReader/BookModel";
|
6
|
-
import { deepCopy } from "../utils";
|
5
|
+
import { BookModel } from "@/src/BookReader/BookModel.js";
|
6
|
+
import { deepCopy } from "../utils.js";
|
7
7
|
/** @typedef {import('@/src/plugins/plugin.chapters').TocEntry} TocEntry */
|
8
8
|
|
9
9
|
/** @type {TocEntry[]} */
|
@@ -29,9 +29,9 @@ describe('updateResumeValue', () => {
|
|
29
29
|
In this branch .toHaveBeenCalledTimes() === 1
|
30
30
|
*/
|
31
31
|
test.skip('starts when BookReaderInit is called', () => {
|
32
|
-
br.
|
32
|
+
br.plugins.resume.updateResumeValue = jest.fn();
|
33
33
|
br.init();
|
34
|
-
expect(br.
|
34
|
+
expect(br.plugins.resume.updateResumeValue).toHaveBeenCalledTimes(2);
|
35
35
|
});
|
36
36
|
|
37
37
|
test('handles cookieName=null', () => {
|
@@ -48,38 +48,38 @@ describe('updateResumeValue', () => {
|
|
48
48
|
test('handles cookiePath not set', () => {
|
49
49
|
const setItemSpy = sinon.spy(docCookies, 'setItem');
|
50
50
|
// Save function
|
51
|
-
const saveFn = br.
|
52
|
-
br.
|
53
|
-
br.
|
51
|
+
const saveFn = br.plugins.resume.getCookiePath;
|
52
|
+
br.plugins.resume.getCookiePath = jest.fn(() => '/details/foo');
|
53
|
+
br.plugins.resume.updateResumeValue(16);
|
54
54
|
expect(setItemSpy.args[0][3]).toEqual('/details/foo');
|
55
55
|
// Restore function
|
56
|
-
br.
|
56
|
+
br.plugins.resume.getCookiePath = saveFn;
|
57
57
|
});
|
58
58
|
|
59
59
|
test('handles cookie path from URL with decoration', () => {
|
60
60
|
const complexPathWithPage = '/details/2008ELMValidityStudyFinalReportRevised/Executive%20Summary%20for%20the%20EPT%26ELM%20Validity%20Studie_20100603%20-%20Copy/page/n1/mode/2up';
|
61
61
|
const complexPath = '/details/2008ELMValidityStudyFinalReportRevised/Executive%20Summary%20for%20the%20EPT%26ELM%20Validity%20Studie_20100603%20-%20Copy';
|
62
|
-
expect(br.
|
62
|
+
expect(br.plugins.resume.getCookiePath(complexPathWithPage))
|
63
63
|
.toEqual(complexPath);
|
64
64
|
|
65
|
-
expect(br.
|
65
|
+
expect(br.plugins.resume.getCookiePath('/details/item/mode/1up'))
|
66
66
|
.toEqual('/details/item');
|
67
67
|
|
68
|
-
expect(br.
|
68
|
+
expect(br.plugins.resume.getCookiePath('/details/item/inside/a/long/path/model/is/used'))
|
69
69
|
.toEqual('/details/item/inside/a/long/path/model/is/used');
|
70
70
|
|
71
|
-
expect(br.
|
71
|
+
expect(br.plugins.resume.getCookiePath('/details/item/inside/a/long/path/mode/is/used'))
|
72
72
|
.toEqual('/details/item/inside/a/long/path');
|
73
73
|
});
|
74
74
|
|
75
75
|
test('handles cookie path from URL with no decoration', () => {
|
76
|
-
expect(br.
|
76
|
+
expect(br.plugins.resume.getCookiePath('/details/item'))
|
77
77
|
.toEqual('/details/item');
|
78
78
|
|
79
|
-
expect(br.
|
79
|
+
expect(br.plugins.resume.getCookiePath('/details/item/'))
|
80
80
|
.toEqual('/details/item/');
|
81
81
|
|
82
|
-
expect(br.
|
82
|
+
expect(br.plugins.resume.getCookiePath('/details/item/almost/any/kind/of/long/path'))
|
83
83
|
.toEqual('/details/item/almost/any/kind/of/long/path');
|
84
84
|
});
|
85
85
|
});
|