@internetarchive/bookreader 5.0.0-24-sortingstate → 5.0.0-25-02
Sign up to get free protection for your applications and to get access to all the features.
- package/BookReader/BookReader.css +4 -0
- package/BookReader/BookReader.js +2 -32148
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bookreader-component-bundle.js +1286 -11261
- package/BookReader/bookreader-component-bundle.js.map +1 -1
- package/BookReader/icons/1up.svg +1 -12
- package/BookReader/icons/2up.svg +1 -15
- package/BookReader/icons/advance.svg +3 -26
- package/BookReader/icons/chevron-right.svg +1 -1
- package/BookReader/icons/close-circle-dark.svg +1 -1
- package/BookReader/icons/close-circle.svg +1 -1
- package/BookReader/icons/fullscreen.svg +1 -17
- package/BookReader/icons/fullscreen_exit.svg +1 -17
- package/BookReader/icons/hamburger.svg +1 -15
- package/BookReader/icons/left-arrow.svg +1 -12
- package/BookReader/icons/magnify-minus.svg +1 -16
- package/BookReader/icons/magnify-plus.svg +1 -17
- package/BookReader/icons/magnify.svg +1 -15
- package/BookReader/icons/pause.svg +1 -23
- package/BookReader/icons/play.svg +1 -22
- package/BookReader/icons/playback-speed.svg +1 -34
- package/BookReader/icons/read-aloud.svg +1 -22
- package/BookReader/icons/review.svg +3 -22
- package/BookReader/icons/thumbnails.svg +1 -17
- package/BookReader/icons/voice.svg +1 -1
- package/BookReader/icons/volume-full.svg +1 -22
- package/BookReader/images/BRicons.svg +5 -94
- package/BookReader/images/books_graphic.svg +1 -177
- package/BookReader/images/icon_book.svg +1 -12
- package/BookReader/images/icon_bookmark.svg +1 -12
- package/BookReader/images/icon_gear.svg +1 -14
- package/BookReader/images/icon_hamburger.svg +1 -20
- package/BookReader/images/icon_home.svg +1 -21
- package/BookReader/images/icon_info.svg +1 -11
- package/BookReader/images/icon_one_page.svg +1 -8
- package/BookReader/images/icon_pause.svg +1 -1
- package/BookReader/images/icon_play.svg +1 -1
- package/BookReader/images/icon_playback-rate.svg +1 -15
- package/BookReader/images/icon_search_button.svg +1 -8
- package/BookReader/images/icon_share.svg +1 -9
- package/BookReader/images/icon_skip-ahead.svg +1 -6
- package/BookReader/images/icon_skip-back.svg +2 -13
- package/BookReader/images/icon_speaker.svg +1 -18
- package/BookReader/images/icon_speaker_open.svg +1 -10
- package/BookReader/images/icon_thumbnails.svg +1 -12
- package/BookReader/images/icon_toc.svg +1 -5
- package/BookReader/images/icon_two_pages.svg +1 -9
- package/BookReader/images/marker_chap-off.svg +1 -11
- package/BookReader/images/marker_chap-on.svg +1 -11
- package/BookReader/images/marker_srch-on.svg +1 -11
- package/BookReader/jquery-1.10.1.js +2 -108
- package/BookReader/plugins/plugin.archive_analytics.js +1 -170
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -163
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +1 -333
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.iframe.js +1 -72
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js +1 -332
- package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -241
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1263
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -839
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +2 -9114
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -750
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -326
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReader/webcomponents-bundle.js +2 -411
- package/BookReader/webcomponents-bundle.js.map +1 -1
- package/package.json +1 -1
- package/src/BookNavigator/volumes/volumes-provider.js +9 -39
- package/src/BookReader.js +0 -4
- package/src/css/_controls.scss +4 -0
- package/src/plugins/plugin.url.js +2 -209
- package/tests/jest/plugins/plugin.url.test.js +1 -160
- package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +6 -6
- package/.nvmrc +0 -1
package/package.json
CHANGED
@@ -7,16 +7,8 @@ import volumesIcon from '../assets/icon_volumes.js';
|
|
7
7
|
|
8
8
|
import './volumes.js';
|
9
9
|
|
10
|
-
const sortType = {
|
11
|
-
title_asc: 'title_asc',
|
12
|
-
title_desc: 'title_desc',
|
13
|
-
default: 'default'
|
14
|
-
};
|
15
10
|
export default class VolumesProvider {
|
16
11
|
|
17
|
-
/**
|
18
|
-
* @param {import('../../BookReader').default} bookreader
|
19
|
-
*/
|
20
12
|
constructor(baseHost, bookreader, optionChange) {
|
21
13
|
this.optionChange = optionChange;
|
22
14
|
this.component = document.createElement("viewable-files");
|
@@ -25,9 +17,6 @@ export default class VolumesProvider {
|
|
25
17
|
this.viewableFiles = Object.keys(files).map(item => files[item]);
|
26
18
|
this.volumeCount = Object.keys(files).length;
|
27
19
|
|
28
|
-
/** @type {import('../../BookReader').default} */
|
29
|
-
this.bookreader = bookreader;
|
30
|
-
|
31
20
|
this.component.subPrefix = bookreader.options.subPrefix || "";
|
32
21
|
this.component.hostUrl = baseHost;
|
33
22
|
this.component.viewableFiles = this.viewableFiles;
|
@@ -36,27 +25,20 @@ export default class VolumesProvider {
|
|
36
25
|
this.label = `Viewable files (${this.volumeCount})`;
|
37
26
|
this.icon = html`${volumesIcon}`;
|
38
27
|
|
39
|
-
|
40
|
-
this.
|
41
|
-
const urlSortValue = this.bookreader.urlPlugin.getUrlParam('sort');
|
42
|
-
if (urlSortValue === sortType.title_asc || urlSortValue === sortType.title_desc) {
|
43
|
-
this.sortOrderBy = urlSortValue;
|
44
|
-
} else {
|
45
|
-
this.sortOrderBy = sortType.default;
|
46
|
-
}
|
47
|
-
this.sortVolumes(this.sortOrderBy);
|
28
|
+
this.sortOrderBy = "orig_sort";
|
29
|
+
this.sortVolumes("orig_sort");
|
48
30
|
}
|
49
31
|
|
50
32
|
get sortButton() {
|
51
33
|
const sortIcons = {
|
52
|
-
|
34
|
+
orig_sort: html`
|
53
35
|
<button class="sort-by neutral-icon" aria-label="Sort volumes in initial order" @click=${() => this.sortVolumes("title_asc")}>${sortNeutralIcon}</button>
|
54
36
|
`,
|
55
37
|
title_asc: html`
|
56
38
|
<button class="sort-by asc-icon" aria-label="Sort volumes in ascending order" @click=${() => this.sortVolumes("title_desc")}>${sortAscIcon}</button>
|
57
39
|
`,
|
58
40
|
title_desc: html`
|
59
|
-
<button class="sort-by desc-icon" aria-label="Sort volumes in descending order" @click=${() => this.sortVolumes("
|
41
|
+
<button class="sort-by desc-icon" aria-label="Sort volumes in descending order" @click=${() => this.sortVolumes("orig_sort")}>${sortDescIcon}</button>
|
60
42
|
`,
|
61
43
|
};
|
62
44
|
|
@@ -64,40 +46,28 @@ export default class VolumesProvider {
|
|
64
46
|
}
|
65
47
|
|
66
48
|
/**
|
67
|
-
* @param {'
|
49
|
+
* @param {'orig_sort' | 'title_asc' | 'title_desc'} sortByType
|
68
50
|
*/
|
69
51
|
sortVolumes(sortByType) {
|
70
52
|
let sortedFiles = [];
|
71
53
|
|
72
54
|
const files = this.viewableFiles;
|
73
55
|
sortedFiles = files.sort((a, b) => {
|
74
|
-
if (sortByType ===
|
75
|
-
else if (sortByType ===
|
76
|
-
else return a.
|
56
|
+
if (sortByType === 'orig_sort') return a.orig_sort - b.orig_sort;
|
57
|
+
else if (sortByType === 'title_asc') return a.title.localeCompare(b.title);
|
58
|
+
else return b.title.localeCompare(a.title);
|
77
59
|
});
|
78
60
|
|
79
61
|
this.sortOrderBy = sortByType;
|
80
62
|
this.component.viewableFiles = [...sortedFiles];
|
81
63
|
this.actionButton = this.sortButton;
|
82
|
-
|
83
|
-
if (this.sortOrderBy !== sortType.default) {
|
84
|
-
this.bookreader.urlPlugin.setUrlParam('sort', sortByType);
|
85
|
-
} else {
|
86
|
-
this.bookreader.urlPlugin.removeUrlParam('sort');
|
87
|
-
}
|
88
|
-
|
89
|
-
const urlSchema = this.bookreader.urlPlugin.urlSchema;
|
90
|
-
const urlState = this.bookreader.urlPlugin.urlState;
|
91
|
-
this.bookreader.urlPlugin.urlStateToUrlString(urlSchema, urlState);
|
92
|
-
this.bookreader.urlPlugin.pushToAddressBar();
|
93
|
-
|
94
64
|
this.optionChange(this.bookreader);
|
95
65
|
|
96
66
|
this.multipleFilesClicked(sortByType);
|
97
67
|
}
|
98
68
|
|
99
69
|
/**
|
100
|
-
* @param {'
|
70
|
+
* @param {'orig_sort' | 'title_asc' | 'title_desc'} orderBy
|
101
71
|
*/
|
102
72
|
multipleFilesClicked(orderBy) {
|
103
73
|
if (!window.archive_analytics) {
|
package/src/BookReader.js
CHANGED
@@ -63,10 +63,6 @@ if (location.toString().indexOf('_debugShowConsole=true') != -1) {
|
|
63
63
|
*/
|
64
64
|
export default function BookReader(overrides = {}) {
|
65
65
|
const options = jQuery.extend(true, {}, BookReader.defaultOptions, overrides, BookReader.optionOverrides);
|
66
|
-
|
67
|
-
/** @type {import('./plugins/plugin.url').UrlPlugin | null} */
|
68
|
-
this.urlPlugin = null;
|
69
|
-
|
70
66
|
this.setup(options);
|
71
67
|
}
|
72
68
|
|
package/src/css/_controls.scss
CHANGED
@@ -50,7 +50,7 @@ BookReader.prototype.init = (function(super_) {
|
|
50
50
|
this.bind(BookReader.eventNames.PostInit, () => {
|
51
51
|
const { updateWindowTitle, urlMode } = this.options;
|
52
52
|
if (updateWindowTitle) {
|
53
|
-
document.title = this.shortTitle(
|
53
|
+
document.title = this.shortTitle(50);
|
54
54
|
}
|
55
55
|
if (urlMode === 'hash') {
|
56
56
|
this.urlStartLocationPolling();
|
@@ -86,7 +86,7 @@ BookReader.prototype.urlStartLocationPolling = function() {
|
|
86
86
|
this.oldLocationHash = this.urlReadFragment();
|
87
87
|
|
88
88
|
if (this.locationPollId) {
|
89
|
-
clearInterval(this.
|
89
|
+
clearInterval(this.locationPollID);
|
90
90
|
this.locationPollId = null;
|
91
91
|
}
|
92
92
|
|
@@ -196,210 +196,3 @@ BookReader.prototype.urlReadFragment = function() {
|
|
196
196
|
BookReader.prototype.urlReadHashFragment = function() {
|
197
197
|
return window.location.hash.substr(1);
|
198
198
|
};
|
199
|
-
export class UrlPlugin {
|
200
|
-
constructor(options = {}) {
|
201
|
-
this.bookReaderOptions = options;
|
202
|
-
|
203
|
-
this.urlSchema = [
|
204
|
-
{ name: 'page', position: 'path', default: 'n0' },
|
205
|
-
{ name: 'mode', position: 'path', default: '2up' },
|
206
|
-
{ name: 'search', position: 'path', deprecated_for: 'q' },
|
207
|
-
{ name: 'q', position: 'query_param' },
|
208
|
-
{ name: 'sort', position: 'query_param' },
|
209
|
-
{ name: 'view', position: 'query_param' },
|
210
|
-
{ name: 'admin', position: 'query_param' },
|
211
|
-
];
|
212
|
-
|
213
|
-
this.urlState = {};
|
214
|
-
this.urlMode = 'hash';
|
215
|
-
this.urlHistoryBasePath = '/';
|
216
|
-
this.urlLocationPollId = null;
|
217
|
-
this.oldLocationHash = null;
|
218
|
-
this.oldUserHash = null;
|
219
|
-
}
|
220
|
-
|
221
|
-
/**
|
222
|
-
* Parse JSON object URL state to string format
|
223
|
-
* Arrange path names in an order that it is positioned on the urlSchema
|
224
|
-
* @param {object} urlState
|
225
|
-
* @returns {string}
|
226
|
-
*/
|
227
|
-
urlStateToUrlString(urlSchema, urlState) {
|
228
|
-
const searchParams = new URLSearchParams();
|
229
|
-
const pathParams = {};
|
230
|
-
|
231
|
-
Object.keys(urlState).forEach(key => {
|
232
|
-
let schema = urlSchema.find(schema => schema.name === key);
|
233
|
-
if (schema?.deprecated_for) {
|
234
|
-
schema = urlSchema.find(schemaKey => schemaKey.name === schema.deprecated_for);
|
235
|
-
}
|
236
|
-
if (schema?.position == 'path') {
|
237
|
-
pathParams[schema?.name] = urlState[key];
|
238
|
-
} else {
|
239
|
-
searchParams.append(schema?.name || key, urlState[key]);
|
240
|
-
}
|
241
|
-
});
|
242
|
-
|
243
|
-
const strPathParams = urlSchema
|
244
|
-
.filter(s => s.position == 'path')
|
245
|
-
.map(schema => pathParams[schema.name] ? `${schema.name}/${pathParams[schema.name]}` : '')
|
246
|
-
.join('/');
|
247
|
-
|
248
|
-
const strStrippedTrailingSlash = `${strPathParams.replace(/\/$/, '')}`;
|
249
|
-
const concatenatedPath = `/${strStrippedTrailingSlash}?${searchParams.toString()}`;
|
250
|
-
return searchParams.toString() ? concatenatedPath : `/${strStrippedTrailingSlash}`;
|
251
|
-
}
|
252
|
-
|
253
|
-
/**
|
254
|
-
* Parse string URL and add it in the current urlState
|
255
|
-
* Example:
|
256
|
-
* /page/n7/mode/2up => {page: 'n7', mode: '2up'}
|
257
|
-
* /page/n7/mode/2up/search/hello => {page: 'n7', mode: '2up', q: 'hello'}
|
258
|
-
* @param {array} urlSchema
|
259
|
-
* @param {string} str
|
260
|
-
* @returns {object}
|
261
|
-
*/
|
262
|
-
urlStringToUrlState(urlSchema, str) {
|
263
|
-
const urlState = {};
|
264
|
-
|
265
|
-
// Fetch searchParams from given {str}
|
266
|
-
// Note: whole URL path is needed for URLSearchParams
|
267
|
-
const urlPath = new URL(str, 'http://example.com');
|
268
|
-
const urlSearchParamsObj = Object.fromEntries(urlPath.searchParams.entries());
|
269
|
-
const urlStrSplitSlashObj = Object.fromEntries(urlPath.pathname
|
270
|
-
.match(/[^\\/]+\/[^\\/]+/g)
|
271
|
-
.map(x => x.split('/'))
|
272
|
-
);
|
273
|
-
const doesKeyExists = (_object, _key) => {
|
274
|
-
return Object.keys(_object).some(value => value == _key);
|
275
|
-
};
|
276
|
-
|
277
|
-
urlSchema
|
278
|
-
.filter(schema => schema.position == 'path')
|
279
|
-
.forEach(schema => {
|
280
|
-
if (!urlStrSplitSlashObj[schema.name] && schema.default) {
|
281
|
-
return urlState[schema.name] = schema.default;
|
282
|
-
}
|
283
|
-
const hasPropertyKey = doesKeyExists(urlStrSplitSlashObj, schema.name);
|
284
|
-
const hasDeprecatedKey = doesKeyExists(schema, 'deprecated_for') && hasPropertyKey;
|
285
|
-
|
286
|
-
if (hasDeprecatedKey)
|
287
|
-
return urlState[schema.deprecated_for] = urlStrSplitSlashObj[schema.name];
|
288
|
-
|
289
|
-
if (hasPropertyKey)
|
290
|
-
return urlState[schema.name] = urlStrSplitSlashObj[schema.name];
|
291
|
-
});
|
292
|
-
|
293
|
-
// Add searchParams to urlState
|
294
|
-
// Check if Object value is a Boolean and convert value to Boolean
|
295
|
-
// Otherwise, return Object value
|
296
|
-
const isBoolean = value => value === 'true' || (value === 'false' ? false : value);
|
297
|
-
Object.entries(urlSearchParamsObj).forEach(([key, value]) => {
|
298
|
-
urlState[key] = isBoolean(value);
|
299
|
-
});
|
300
|
-
|
301
|
-
return urlState;
|
302
|
-
}
|
303
|
-
|
304
|
-
/**
|
305
|
-
* Add or update key-value to the urlState
|
306
|
-
* @param {string} key
|
307
|
-
* @param {string} val
|
308
|
-
*/
|
309
|
-
setUrlParam(key, value) {
|
310
|
-
this.urlState[key] = value;
|
311
|
-
|
312
|
-
this.pushToAddressBar();
|
313
|
-
}
|
314
|
-
|
315
|
-
/**
|
316
|
-
* Delete key-value to the urlState
|
317
|
-
* @param {string} key
|
318
|
-
*/
|
319
|
-
removeUrlParam(key) {
|
320
|
-
delete this.urlState[key];
|
321
|
-
|
322
|
-
this.pushToAddressBar();
|
323
|
-
}
|
324
|
-
|
325
|
-
/**
|
326
|
-
* Get key-value from the urlState
|
327
|
-
* @param {string} key
|
328
|
-
* @return {string}
|
329
|
-
*/
|
330
|
-
getUrlParam(key) {
|
331
|
-
return this.urlState[key];
|
332
|
-
}
|
333
|
-
|
334
|
-
/**
|
335
|
-
* Push URL params to addressbar
|
336
|
-
*/
|
337
|
-
pushToAddressBar() {
|
338
|
-
const urlStrPath = this.urlStateToUrlString(this.urlSchema, this.urlState);
|
339
|
-
if (this.urlMode == 'history') {
|
340
|
-
if (window.history && window.history.replaceState) {
|
341
|
-
const newUrlPath = `${this.urlHistoryBasePath}${urlStrPath}`;
|
342
|
-
window.history.replaceState({}, null, newUrlPath);
|
343
|
-
}
|
344
|
-
} else {
|
345
|
-
window.location.replace('#' + urlStrPath);
|
346
|
-
}
|
347
|
-
this.oldLocationHash = urlStrPath;
|
348
|
-
}
|
349
|
-
|
350
|
-
/**
|
351
|
-
* Get the url and check if it has changed
|
352
|
-
* If it was changeed, update the urlState
|
353
|
-
*/
|
354
|
-
listenForHashChanges() {
|
355
|
-
this.oldLocationHash = window.location.hash.substr(1);
|
356
|
-
if (this.urlLocationPollId) {
|
357
|
-
clearInterval(this.urlLocationPollId);
|
358
|
-
this.urlLocationPollId = null;
|
359
|
-
}
|
360
|
-
|
361
|
-
// check if the URL changes
|
362
|
-
const updateHash = () => {
|
363
|
-
const newFragment = window.location.hash.substr(1);
|
364
|
-
const hasFragmentChange = newFragment != this.oldLocationHash;
|
365
|
-
|
366
|
-
if (!hasFragmentChange) { return; }
|
367
|
-
|
368
|
-
this.urlState = this.urlStringToUrlState(newFragment);
|
369
|
-
};
|
370
|
-
this.urlLocationPollId = setInterval(updateHash, 500);
|
371
|
-
}
|
372
|
-
|
373
|
-
/**
|
374
|
-
* Will read either the hash or URL and return the bookreader fragment
|
375
|
-
* @param {string} location
|
376
|
-
* @return {string}
|
377
|
-
*/
|
378
|
-
pullFromAddressBar (location) {
|
379
|
-
const path = this.urlMode === 'history'
|
380
|
-
? location.substr(this.urlHistoryBasePath.length)
|
381
|
-
: location.substr(1);
|
382
|
-
this.urlState = this.urlStringToUrlState(this.urlSchema, path);
|
383
|
-
}
|
384
|
-
}
|
385
|
-
export class BookreaderUrlPlugin extends BookReader {
|
386
|
-
|
387
|
-
init() {
|
388
|
-
if (this.options.enableUrlPlugin) {
|
389
|
-
this.urlPlugin = new UrlPlugin(this.options);
|
390
|
-
this.bind(BookReader.eventNames.PostInit, () => {
|
391
|
-
const { urlMode } = this.options;
|
392
|
-
|
393
|
-
if (urlMode === 'hash') {
|
394
|
-
this.urlPlugin.listenForHashChanges();
|
395
|
-
}
|
396
|
-
});
|
397
|
-
}
|
398
|
-
|
399
|
-
super.init();
|
400
|
-
}
|
401
|
-
|
402
|
-
}
|
403
|
-
|
404
|
-
window.BookReader = BookreaderUrlPlugin;
|
405
|
-
export default BookreaderUrlPlugin;
|
@@ -1,7 +1,6 @@
|
|
1
|
+
|
1
2
|
import BookReader from '@/src/BookReader.js';
|
2
3
|
import '@/src/plugins/plugin.url.js';
|
3
|
-
import { UrlPlugin } from '@/src/plugins/plugin.url.js';
|
4
|
-
import sinon from 'sinon';
|
5
4
|
|
6
5
|
let br;
|
7
6
|
beforeAll(() => {
|
@@ -11,164 +10,6 @@ beforeAll(() => {
|
|
11
10
|
|
12
11
|
afterEach(() => {
|
13
12
|
jest.clearAllMocks();
|
14
|
-
sinon.restore();
|
15
|
-
});
|
16
|
-
|
17
|
-
|
18
|
-
describe.only('UrlPlugin tests', () => {
|
19
|
-
const urlPlugin = new UrlPlugin();
|
20
|
-
const urlSchema = [
|
21
|
-
{ name: 'page', position: 'path', default: 'n0' },
|
22
|
-
{ name: 'mode', position: 'path', default: '2up' },
|
23
|
-
{ name: 'search', position: 'path', deprecated_for: 'q' },
|
24
|
-
{ name: 'q', position: 'query_param' },
|
25
|
-
{ name: 'sort', position: 'query_param' },
|
26
|
-
{ name: 'view', position: 'query_param' },
|
27
|
-
{ name: 'admin', position: 'query_param' },
|
28
|
-
];
|
29
|
-
|
30
|
-
describe('urlStateToUrlString tests', () => {
|
31
|
-
test('urlStateToUrlString with known states in schema', () => {
|
32
|
-
const urlState = { page: 'n7', mode: '1up', search: 'foo' };
|
33
|
-
const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', view: 'theater', sort: 'title_asc' };
|
34
|
-
|
35
|
-
const expectedUrlFromState = '/page/n7/mode/1up?q=foo';
|
36
|
-
const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&view=theater&sort=title_asc';
|
37
|
-
|
38
|
-
expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
|
39
|
-
expect(urlPlugin.urlStateToUrlString(urlSchema, urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
40
|
-
});
|
41
|
-
|
42
|
-
test('urlStateToUrlString with unknown states in schema', () => {
|
43
|
-
const urlState = { page: 'n7', mode: '1up' };
|
44
|
-
const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', viewer: 'theater', sortBy: 'title_asc' };
|
45
|
-
|
46
|
-
const expectedUrlFromState = '/page/n7/mode/1up';
|
47
|
-
const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&viewer=theater&sortBy=title_asc';
|
48
|
-
|
49
|
-
expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
|
50
|
-
expect(urlPlugin.urlStateToUrlString(urlSchema, urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
51
|
-
});
|
52
|
-
|
53
|
-
test('urlStateToUrlString with boolean value', () => {
|
54
|
-
const urlState = { page: 'n7', mode: '1up', search: 'foo', view: 'theater', wrapper: false };
|
55
|
-
const expectedUrlFromState = '/page/n7/mode/1up?q=foo&view=theater&wrapper=false';
|
56
|
-
|
57
|
-
expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
|
58
|
-
});
|
59
|
-
});
|
60
|
-
|
61
|
-
describe('urlStringToUrlState tests', () => {
|
62
|
-
test('urlStringToUrlState without query string', () => {
|
63
|
-
const url = '/page/n7/mode/2up';
|
64
|
-
const url1 = '/page/n7/mode/1up';
|
65
|
-
|
66
|
-
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up'});
|
67
|
-
expect(urlPlugin.urlStringToUrlState(urlSchema, url1)).toEqual({page: 'n7', mode: '1up'});
|
68
|
-
});
|
69
|
-
|
70
|
-
test('urlStringToUrlState with deprecated_for', () => {
|
71
|
-
const url = '/page/n7/mode/2up/search/hello';
|
72
|
-
|
73
|
-
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
74
|
-
});
|
75
|
-
|
76
|
-
test('urlStringToUrlState with query string', () => {
|
77
|
-
const url = '/page/n7/mode/2up/search/hello?view=theather&foo=bar&sort=title_asc';
|
78
|
-
const url1 = '/mode/2up?ref=ol&ui=embed&wrapper=false&view=theater';
|
79
|
-
|
80
|
-
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual(
|
81
|
-
{page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'}
|
82
|
-
);
|
83
|
-
expect(urlPlugin.urlStringToUrlState(urlSchema, url1)).toEqual(
|
84
|
-
{page: 'n0', mode: '2up', ref: 'ol', ui: 'embed', wrapper: false, view: 'theater'}
|
85
|
-
);
|
86
|
-
});
|
87
|
-
|
88
|
-
test('urlStringToUrlState compare search and ?q', () => {
|
89
|
-
const url = '/page/n7/mode/2up/search/hello';
|
90
|
-
urlPlugin.urlState = { q: 'hello' };
|
91
|
-
|
92
|
-
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
93
|
-
});
|
94
|
-
});
|
95
|
-
|
96
|
-
describe('url plugin helper functions', () => {
|
97
|
-
test('setUrlParam', () => {
|
98
|
-
urlPlugin.urlState = {};
|
99
|
-
urlPlugin.setUrlParam('page', '20');
|
100
|
-
urlPlugin.setUrlParam('mode', '2up');
|
101
|
-
|
102
|
-
expect(urlPlugin.urlState).toEqual({page: '20', mode: '2up'});
|
103
|
-
});
|
104
|
-
|
105
|
-
test('removeUrlParam', () => {
|
106
|
-
urlPlugin.setUrlParam('page', '20');
|
107
|
-
urlPlugin.setUrlParam('mode', '2up');
|
108
|
-
urlPlugin.removeUrlParam('mode');
|
109
|
-
|
110
|
-
expect(urlPlugin.urlState).toEqual({page: '20'});
|
111
|
-
});
|
112
|
-
|
113
|
-
test('getUrlParam', () => {
|
114
|
-
urlPlugin.setUrlParam('page', '20');
|
115
|
-
urlPlugin.setUrlParam('mode', '2up');
|
116
|
-
expect(urlPlugin.getUrlParam('page')).toEqual('20');
|
117
|
-
expect(urlPlugin.getUrlParam('mode')).toEqual('2up');
|
118
|
-
});
|
119
|
-
});
|
120
|
-
|
121
|
-
describe('pullFromAddressBar and pushToAddressBar - hash mode', () => {
|
122
|
-
test('url without mode state value - use default', () => {
|
123
|
-
urlPlugin.urlState = {};
|
124
|
-
urlPlugin.urlMode = 'hash';
|
125
|
-
|
126
|
-
urlPlugin.pullFromAddressBar('/page/12');
|
127
|
-
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
128
|
-
|
129
|
-
urlPlugin.pushToAddressBar();
|
130
|
-
expect(window.location.hash).toEqual('#/page/12/mode/2up');
|
131
|
-
});
|
132
|
-
|
133
|
-
test('url with query param', () => {
|
134
|
-
urlPlugin.urlState = {};
|
135
|
-
urlPlugin.urlMode = 'hash';
|
136
|
-
|
137
|
-
urlPlugin.pullFromAddressBar('/page/12/search/hello?view=theater');
|
138
|
-
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
139
|
-
|
140
|
-
urlPlugin.pushToAddressBar();
|
141
|
-
expect(window.location.hash).toEqual('#/page/12/mode/2up?q=hello&view=theater');
|
142
|
-
});
|
143
|
-
});
|
144
|
-
|
145
|
-
describe('pullFromAddressBar and pushToAddressBar - history mode', () => {
|
146
|
-
test('url without mode state value - use default', () => {
|
147
|
-
urlPlugin.urlState = {};
|
148
|
-
urlPlugin.urlHistoryBasePath = '/details/foo';
|
149
|
-
urlPlugin.urlMode = 'history';
|
150
|
-
|
151
|
-
urlPlugin.pullFromAddressBar('/details/foo/page/12');
|
152
|
-
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
153
|
-
|
154
|
-
urlPlugin.pushToAddressBar();
|
155
|
-
expect(window.location.pathname).toEqual('/details/foo/page/12/mode/2up');
|
156
|
-
});
|
157
|
-
|
158
|
-
test('url with query param', () => {
|
159
|
-
urlPlugin.urlState = {};
|
160
|
-
urlPlugin.urlHistoryBasePath = '/details/foo';
|
161
|
-
urlPlugin.urlMode = 'history';
|
162
|
-
|
163
|
-
urlPlugin.pullFromAddressBar('/details/foo/page/12/search/hello?view=theater');
|
164
|
-
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
165
|
-
|
166
|
-
urlPlugin.pushToAddressBar();
|
167
|
-
const locationUrl = `${window.location.pathname}${window.location.search}`;
|
168
|
-
expect(locationUrl).toEqual('/details/foo/page/12/mode/2up?q=hello&view=theater');
|
169
|
-
});
|
170
|
-
});
|
171
|
-
|
172
13
|
});
|
173
14
|
|
174
15
|
describe('Plugin: URL controller', () => {
|
@@ -64,7 +64,7 @@ describe('Volumes Provider', () => {
|
|
64
64
|
const baseHost = "https://archive.org";
|
65
65
|
const provider = new volumesProvider(baseHost, brOptions, onSortClick);
|
66
66
|
|
67
|
-
expect(provider.sortOrderBy).to.equal("
|
67
|
+
expect(provider.sortOrderBy).to.equal("orig_sort");
|
68
68
|
|
69
69
|
provider.sortVolumes("title_asc");
|
70
70
|
expect(provider.sortOrderBy).to.equal("title_asc");
|
@@ -74,8 +74,8 @@ describe('Volumes Provider', () => {
|
|
74
74
|
expect(provider.sortOrderBy).to.equal("title_desc");
|
75
75
|
expect(provider.sortButton.getHTML()).includes("sort-by desc-icon");
|
76
76
|
|
77
|
-
provider.sortVolumes("
|
78
|
-
expect(provider.sortOrderBy).to.equal("
|
77
|
+
provider.sortVolumes("orig_sort");
|
78
|
+
expect(provider.sortOrderBy).to.equal("orig_sort");
|
79
79
|
expect(provider.sortButton.getHTML()).includes("sort-by neutral-icon");
|
80
80
|
});
|
81
81
|
|
@@ -88,9 +88,9 @@ describe('Volumes Provider', () => {
|
|
88
88
|
const files = Object.keys(parsedFiles).map(item => parsedFiles[item]).sort((a, b) => a.orig_sort - b.orig_sort);
|
89
89
|
const origSortTitles = files.map(item => item.title);
|
90
90
|
|
91
|
-
provider.sortVolumes("
|
91
|
+
provider.sortVolumes("orig_sort");
|
92
92
|
|
93
|
-
expect(provider.sortOrderBy).to.equal("
|
93
|
+
expect(provider.sortOrderBy).to.equal("orig_sort");
|
94
94
|
expect(provider.actionButton).to.exist;
|
95
95
|
|
96
96
|
const providerFileTitles = provider.viewableFiles.map(item => item.title);
|
@@ -144,7 +144,7 @@ describe('Volumes Provider', () => {
|
|
144
144
|
const baseHost = "https://archive.org";
|
145
145
|
const provider = new volumesProvider(baseHost, brOptions, onSortClick);
|
146
146
|
|
147
|
-
provider.sortOrderBy = '
|
147
|
+
provider.sortOrderBy = 'orig_sort';
|
148
148
|
const origSortButton = await fixture(provider.sortButton);
|
149
149
|
expect(origSortButton.classList.contains('neutral-icon')).to.be.true;
|
150
150
|
|
package/.nvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
14
|