@internetarchive/bookreader 5.0.0-24-sortingstate-1 → 5.0.0-24-sortingstate-2
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.js +1 -4
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bookreader-component-bundle.js +16 -22
- 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 +46 -33
- 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 +1 -1
- package/src/BookReader.js +0 -4
- package/src/plugins/plugin.url.js +22 -16
- package/tests/jest/plugins/plugin.url.test.js +4 -4
- package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +6 -6
package/package.json
CHANGED
@@ -37,7 +37,7 @@ export default class VolumesProvider {
|
|
37
37
|
this.icon = html`${volumesIcon}`;
|
38
38
|
|
39
39
|
// get sort state from query param
|
40
|
-
this.bookreader.urlPlugin.pullFromAddressBar(
|
40
|
+
this.bookreader.urlPlugin.pullFromAddressBar();
|
41
41
|
const urlSortValue = this.bookreader.urlPlugin.getUrlParam('sort');
|
42
42
|
console.log('urlSortValue: ', urlSortValue);
|
43
43
|
if (urlSortValue === sortType.title_asc || urlSortValue === sortType.title_desc) {
|
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
|
|
@@ -200,6 +200,7 @@ export class UrlPlugin {
|
|
200
200
|
constructor(options = {}) {
|
201
201
|
this.bookReaderOptions = options;
|
202
202
|
|
203
|
+
// the canonical order of elements is important in the path and query string
|
203
204
|
this.urlSchema = [
|
204
205
|
{ name: 'page', position: 'path', default: 'n0' },
|
205
206
|
{ name: 'mode', position: 'path', default: '2up' },
|
@@ -221,7 +222,8 @@ export class UrlPlugin {
|
|
221
222
|
/**
|
222
223
|
* Parse JSON object URL state to string format
|
223
224
|
* Arrange path names in an order that it is positioned on the urlSchema
|
224
|
-
* @param {object}
|
225
|
+
* @param {object} urlSchema
|
226
|
+
* @param {string} urlState
|
225
227
|
* @returns {string}
|
226
228
|
*/
|
227
229
|
urlStateToUrlString(urlSchema, urlState) {
|
@@ -256,15 +258,15 @@ export class UrlPlugin {
|
|
256
258
|
* /page/n7/mode/2up => {page: 'n7', mode: '2up'}
|
257
259
|
* /page/n7/mode/2up/search/hello => {page: 'n7', mode: '2up', q: 'hello'}
|
258
260
|
* @param {array} urlSchema
|
259
|
-
* @param {string}
|
261
|
+
* @param {string} urlString
|
260
262
|
* @returns {object}
|
261
263
|
*/
|
262
|
-
urlStringToUrlState(urlSchema,
|
264
|
+
urlStringToUrlState(urlSchema, urlString) {
|
263
265
|
const urlState = {};
|
264
266
|
|
265
|
-
// Fetch searchParams from given {
|
267
|
+
// Fetch searchParams from given {urlString}
|
266
268
|
// Note: whole URL path is needed for URLSearchParams
|
267
|
-
const urlPath = new URL(
|
269
|
+
const urlPath = new URL(urlString, 'http://example.com');
|
268
270
|
const urlSearchParamsObj = Object.fromEntries(urlPath.searchParams.entries());
|
269
271
|
const urlStrSplitSlashObj = Object.fromEntries(urlPath.pathname
|
270
272
|
.match(/[^\\/]+\/[^\\/]+/g)
|
@@ -274,6 +276,7 @@ export class UrlPlugin {
|
|
274
276
|
return Object.keys(_object).some(value => value == _key);
|
275
277
|
};
|
276
278
|
|
279
|
+
// Add path objects to urlState
|
277
280
|
urlSchema
|
278
281
|
.filter(schema => schema.position == 'path')
|
279
282
|
.forEach(schema => {
|
@@ -283,19 +286,23 @@ export class UrlPlugin {
|
|
283
286
|
const hasPropertyKey = doesKeyExists(urlStrSplitSlashObj, schema.name);
|
284
287
|
const hasDeprecatedKey = doesKeyExists(schema, 'deprecated_for') && hasPropertyKey;
|
285
288
|
|
286
|
-
if (hasDeprecatedKey)
|
287
|
-
|
289
|
+
if (hasDeprecatedKey) {
|
290
|
+
urlState[schema.deprecated_for] = urlStrSplitSlashObj[schema.name];
|
291
|
+
return;
|
292
|
+
}
|
288
293
|
|
289
|
-
if (hasPropertyKey)
|
290
|
-
|
294
|
+
if (hasPropertyKey) {
|
295
|
+
urlState[schema.name] = urlStrSplitSlashObj[schema.name];
|
296
|
+
return;
|
297
|
+
}
|
291
298
|
});
|
292
299
|
|
293
300
|
// Add searchParams to urlState
|
294
301
|
// Check if Object value is a Boolean and convert value to Boolean
|
295
302
|
// Otherwise, return Object value
|
296
|
-
const
|
303
|
+
const isBooleanValue = value => value === 'true' || (value === 'false' ? false : value);
|
297
304
|
Object.entries(urlSearchParamsObj).forEach(([key, value]) => {
|
298
|
-
urlState[key] =
|
305
|
+
urlState[key] = isBooleanValue(value);
|
299
306
|
});
|
300
307
|
|
301
308
|
return urlState;
|
@@ -372,16 +379,15 @@ export class UrlPlugin {
|
|
372
379
|
|
373
380
|
/**
|
374
381
|
* Will read either the hash or URL and return the bookreader fragment
|
375
|
-
* @param {string} location
|
376
|
-
* @return {string}
|
377
382
|
*/
|
378
|
-
pullFromAddressBar (location) {
|
383
|
+
pullFromAddressBar (location = window.location) {
|
379
384
|
const path = this.urlMode === 'history'
|
380
|
-
? location.substr(this.urlHistoryBasePath.length)
|
381
|
-
: location.substr(1);
|
385
|
+
? (location.pathname.substr(this.urlHistoryBasePath.length) + location.search)
|
386
|
+
: location.hash.substr(1);
|
382
387
|
this.urlState = this.urlStringToUrlState(this.urlSchema, path);
|
383
388
|
}
|
384
389
|
}
|
390
|
+
|
385
391
|
export class BookreaderUrlPlugin extends BookReader {
|
386
392
|
|
387
393
|
init() {
|
@@ -123,7 +123,7 @@ describe.only('UrlPlugin tests', () => {
|
|
123
123
|
urlPlugin.urlState = {};
|
124
124
|
urlPlugin.urlMode = 'hash';
|
125
125
|
|
126
|
-
urlPlugin.pullFromAddressBar('/page/12');
|
126
|
+
urlPlugin.pullFromAddressBar({ pathname: '/page/12', search: '', hash: '' });
|
127
127
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
128
128
|
|
129
129
|
urlPlugin.pushToAddressBar();
|
@@ -134,7 +134,7 @@ describe.only('UrlPlugin tests', () => {
|
|
134
134
|
urlPlugin.urlState = {};
|
135
135
|
urlPlugin.urlMode = 'hash';
|
136
136
|
|
137
|
-
urlPlugin.pullFromAddressBar('/page/12
|
137
|
+
urlPlugin.pullFromAddressBar({ pathname: '/page/12', search: '?q=hello&view=theater', hash: '' });
|
138
138
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
139
139
|
|
140
140
|
urlPlugin.pushToAddressBar();
|
@@ -148,7 +148,7 @@ describe.only('UrlPlugin tests', () => {
|
|
148
148
|
urlPlugin.urlHistoryBasePath = '/details/foo';
|
149
149
|
urlPlugin.urlMode = 'history';
|
150
150
|
|
151
|
-
urlPlugin.pullFromAddressBar('/details/foo/page/12');
|
151
|
+
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '', hash: '' });
|
152
152
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
153
153
|
|
154
154
|
urlPlugin.pushToAddressBar();
|
@@ -160,7 +160,7 @@ describe.only('UrlPlugin tests', () => {
|
|
160
160
|
urlPlugin.urlHistoryBasePath = '/details/foo';
|
161
161
|
urlPlugin.urlMode = 'history';
|
162
162
|
|
163
|
-
urlPlugin.pullFromAddressBar('/details/foo/page/12
|
163
|
+
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '?q=hello&view=theater', hash: '' });
|
164
164
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
165
165
|
|
166
166
|
urlPlugin.pushToAddressBar();
|
@@ -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
|
|