@internetarchive/bookreader 5.0.0-55 → 5.0.0-57
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 -1
- package/BookReader/ia-bookreader-bundle.js +1 -1
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/BookNavigator/book-navigator.js +5 -1
- package/src/plugins/url/UrlPlugin.js +12 -3
- package/src/plugins/url/plugin.url.js +17 -10
- package/tests/jest/BookNavigator/book-navigator.test.js +24 -0
- package/tests/jest/plugins/url/plugin.url.test.js +20 -0
|
@@ -124,7 +124,7 @@ BookReader.prototype.urlStartLocationPolling = function() {
|
|
|
124
124
|
*/
|
|
125
125
|
BookReader.prototype.urlUpdateFragment = function() {
|
|
126
126
|
const allParams = this.paramsFromCurrent();
|
|
127
|
-
const {
|
|
127
|
+
const { urlTrackIndex0, urlTrackedParams } = this.options;
|
|
128
128
|
|
|
129
129
|
if (!urlTrackIndex0
|
|
130
130
|
&& (typeof(allParams.index) !== 'undefined')
|
|
@@ -140,29 +140,36 @@ BookReader.prototype.urlUpdateFragment = function() {
|
|
|
140
140
|
return validParams;
|
|
141
141
|
}, {});
|
|
142
142
|
|
|
143
|
-
const newFragment = this.fragmentFromParams(params, urlMode);
|
|
143
|
+
const newFragment = this.fragmentFromParams(params, this.options.urlMode);
|
|
144
144
|
const currFragment = this.urlReadFragment();
|
|
145
145
|
const currQueryString = this.getLocationSearch();
|
|
146
|
-
const newQueryString = this.queryStringFromParams(params, currQueryString, urlMode);
|
|
146
|
+
const newQueryString = this.queryStringFromParams(params, currQueryString, this.options.urlMode);
|
|
147
147
|
if (currFragment === newFragment && currQueryString === newQueryString) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
if (urlMode === 'history') {
|
|
152
|
-
if (window.history
|
|
151
|
+
if (this.options.urlMode === 'history') {
|
|
152
|
+
if (!window.history || !window.history.replaceState) {
|
|
153
|
+
this.options.urlMode = 'hash';
|
|
154
|
+
} else {
|
|
153
155
|
const baseWithoutSlash = this.options.urlHistoryBasePath.replace(/\/+$/, '');
|
|
154
156
|
const newFragmentWithSlash = newFragment === '' ? '' : `/${newFragment}`;
|
|
155
157
|
|
|
156
158
|
const newUrlPath = `${baseWithoutSlash}${newFragmentWithSlash}${newQueryString}`;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
try {
|
|
160
|
+
window.history.replaceState({}, null, newUrlPath);
|
|
161
|
+
this.oldLocationHash = newFragment + newQueryString;
|
|
162
|
+
} catch (e) {
|
|
163
|
+
// DOMException on Chrome when in sandboxed iframe
|
|
164
|
+
this.options.urlMode = 'hash';
|
|
165
|
+
}
|
|
160
166
|
}
|
|
161
|
-
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (this.options.urlMode === 'hash') {
|
|
162
170
|
const newQueryStringSearch = this.urlParamsFiltersOnlySearch(this.readQueryString());
|
|
163
171
|
window.location.replace('#' + newFragment + newQueryStringSearch);
|
|
164
172
|
this.oldLocationHash = newFragment + newQueryStringSearch;
|
|
165
|
-
|
|
166
173
|
}
|
|
167
174
|
};
|
|
168
175
|
|
|
@@ -148,6 +148,9 @@ describe('<book-navigator>', () => {
|
|
|
148
148
|
el.bookreader = brStub;
|
|
149
149
|
await el.elementUpdated;
|
|
150
150
|
|
|
151
|
+
el.downloadableTypes = ['foo/bar'];
|
|
152
|
+
await el.elementUpdated;
|
|
153
|
+
|
|
151
154
|
el.initializeBookSubmenus();
|
|
152
155
|
await el.elementUpdated;
|
|
153
156
|
const defaultMenus = Object.keys(el.menuProviders);
|
|
@@ -229,6 +232,27 @@ describe('<book-navigator>', () => {
|
|
|
229
232
|
expect(baseConfigKeys).toContain('isAdmin');
|
|
230
233
|
expect(baseConfigKeys).toContain('onProviderChange');
|
|
231
234
|
});
|
|
235
|
+
|
|
236
|
+
test('Downloads panel - does not show if no available `downloadableTypes`', async () => {
|
|
237
|
+
const el = fixtureSync(container());
|
|
238
|
+
const $brContainer = document.createElement('div');
|
|
239
|
+
const brStub = {
|
|
240
|
+
resize: sinon.fake(),
|
|
241
|
+
currentIndex: sinon.fake(),
|
|
242
|
+
jumpToIndex: sinon.fake(),
|
|
243
|
+
options: {},
|
|
244
|
+
refs: {
|
|
245
|
+
$brContainer
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
el.bookreader = brStub;
|
|
249
|
+
await el.elementUpdated;
|
|
250
|
+
|
|
251
|
+
el.initializeBookSubmenus();
|
|
252
|
+
await el.elementUpdated;
|
|
253
|
+
const defaultMenus = Object.keys(el.menuProviders);
|
|
254
|
+
expect(defaultMenus.find(menu => menu === 'downloads')).toBeUndefined;
|
|
255
|
+
});
|
|
232
256
|
});
|
|
233
257
|
|
|
234
258
|
describe('Controlling Menu Side Panel & Shortcuts', () => {
|
|
@@ -114,6 +114,26 @@ describe('Plugin: URL controller', () => {
|
|
|
114
114
|
expect(window.history.replaceState).toHaveBeenCalled();
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
test('switches to hashMode if replaceState errors', () => {
|
|
118
|
+
window.history.replaceState = jest.fn(() => {
|
|
119
|
+
throw new Error('foo');
|
|
120
|
+
});
|
|
121
|
+
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
122
|
+
BookReader.prototype.urlReadFragment = jest.fn(() => '');
|
|
123
|
+
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
124
|
+
index: 1,
|
|
125
|
+
mode: 2,
|
|
126
|
+
view: 'theater'
|
|
127
|
+
}));
|
|
128
|
+
BookReader.prototype.search = jest.fn();
|
|
129
|
+
br.options.urlMode = 'history';
|
|
130
|
+
br.init();
|
|
131
|
+
br.urlUpdateFragment();
|
|
132
|
+
|
|
133
|
+
expect(window.history.replaceState).toHaveBeenCalled();
|
|
134
|
+
expect(br.options.urlMode).toEqual('hash');
|
|
135
|
+
});
|
|
136
|
+
|
|
117
137
|
test('does not update URL when search in query string', () => {
|
|
118
138
|
window.history.replaceState = jest.fn();
|
|
119
139
|
BookReader.prototype.currentIndex = jest.fn(() => 1);
|