@internetarchive/bookreader 5.0.0-46-no-right-click → 5.0.0-46-no-right-click-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.
@@ -130,6 +130,8 @@
|
|
130
130
|
// analytics stub
|
131
131
|
window.archive_analytics = {
|
132
132
|
send_event_no_sampling: (category, action, label) => console.log('~~~ NO SAMPLE EVENT CALLED: ', { category, action, label }),
|
133
|
+
send_event: (category, action, label) => console.log('~~~ send_event SAMPLE EVENT CALLED: ', { category, action, label }),
|
134
|
+
send_ping: (category, action, label) => console.log('~~~ send_ping SAMPLE EVENT CALLED: ', { category, action, label }),
|
133
135
|
}
|
134
136
|
</script>
|
135
137
|
|
package/package.json
CHANGED
@@ -13,9 +13,8 @@ import VolumesProvider from '@/src/BookNavigator/volumes/volumes-provider.js';
|
|
13
13
|
import { ModalManager } from '@internetarchive/modal-manager';
|
14
14
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
15
15
|
import '@/src/BookNavigator/book-navigator.js';
|
16
|
-
import { sleep } from '@/src/BookReader/utils';
|
17
16
|
|
18
|
-
const promise0 = () => new Promise(
|
17
|
+
const promise0 = () => new Promise(res => setTimeout(res, 0));
|
19
18
|
|
20
19
|
const container = (sharedObserver = null) => {
|
21
20
|
const itemStub = {
|
@@ -23,7 +22,7 @@ const container = (sharedObserver = null) => {
|
|
23
22
|
identifier: 'foo',
|
24
23
|
creator: 'bar',
|
25
24
|
title: 'baz',
|
26
|
-
}
|
25
|
+
}
|
27
26
|
};
|
28
27
|
const modalMgr = new ModalManager();
|
29
28
|
return html`
|
@@ -33,18 +32,18 @@ const container = (sharedObserver = null) => {
|
|
33
32
|
.sharedObserver=${sharedObserver || new SharedResizeObserver()}
|
34
33
|
.modal=${modalMgr}
|
35
34
|
>
|
36
|
-
<div slot=
|
37
|
-
<div id=
|
38
|
-
<p class=
|
35
|
+
<div slot="main">
|
36
|
+
<div id="BookReader"></div>
|
37
|
+
<p class="visible-in-reader">now showing</p>
|
39
38
|
<\div>
|
40
39
|
</book-navigator>
|
41
40
|
`;
|
42
41
|
};
|
43
42
|
|
44
43
|
window.ResizeObserver = class ResizeObserver {
|
45
|
-
observe = sinon.fake()
|
46
|
-
unobserve = sinon.fake()
|
47
|
-
disconnect = sinon.fake()
|
44
|
+
observe = sinon.fake()
|
45
|
+
unobserve = sinon.fake()
|
46
|
+
disconnect = sinon.fake()
|
48
47
|
};
|
49
48
|
|
50
49
|
afterEach(() => {
|
@@ -53,11 +52,11 @@ afterEach(() => {
|
|
53
52
|
const body = document.querySelector('body');
|
54
53
|
body.innerHTML = '';
|
55
54
|
sinon.restore();
|
56
|
-
window.archive_analytics = null;
|
57
55
|
});
|
58
56
|
|
57
|
+
|
59
58
|
describe('<book-navigator>', () => {
|
60
|
-
describe(
|
59
|
+
describe("How it loads", () => {
|
61
60
|
describe('Attaches BookReader listeners before `br.init` is called', () => {
|
62
61
|
test('binds global event listeners', async () => {
|
63
62
|
const el = fixtureSync(container());
|
@@ -72,7 +71,7 @@ describe('<book-navigator>', () => {
|
|
72
71
|
jumpToIndex: sinon.fake(),
|
73
72
|
options: { enableMultipleBooks: false }, // for multipleBooks
|
74
73
|
el: '#BookReader',
|
75
|
-
refs: {}
|
74
|
+
refs: {}
|
76
75
|
};
|
77
76
|
|
78
77
|
const sharedObserver = new SharedResizeObserver();
|
@@ -86,11 +85,9 @@ describe('<book-navigator>', () => {
|
|
86
85
|
|
87
86
|
expect(brStub.resize.callCount).toEqual(0);
|
88
87
|
|
89
|
-
window.dispatchEvent(
|
90
|
-
|
91
|
-
|
92
|
-
})
|
93
|
-
);
|
88
|
+
window.dispatchEvent(new CustomEvent('BookReader:PostInit', {
|
89
|
+
detail: { props: brStub }
|
90
|
+
}));
|
94
91
|
await elementUpdated(el);
|
95
92
|
|
96
93
|
expect(el.emitLoadingStatusUpdate.callCount).toEqual(1);
|
@@ -123,15 +120,13 @@ describe('<book-navigator>', () => {
|
|
123
120
|
const itemImage = fixtureSync(el.itemImage);
|
124
121
|
expect(itemImage).toBeInstanceOf(HTMLImageElement);
|
125
122
|
expect(itemImage.getAttribute('class')).toEqual('cover-img');
|
126
|
-
expect(itemImage.getAttribute('src')).toEqual(
|
127
|
-
'https://https://foo.archive.org/services/img/foo'
|
128
|
-
);
|
123
|
+
expect(itemImage.getAttribute('src')).toEqual('https://https://foo.archive.org/services/img/foo');
|
129
124
|
});
|
130
125
|
});
|
131
126
|
describe('Menu/Layer Provider', () => {
|
132
127
|
describe('Connecting with a provider:', () => {
|
133
128
|
// loads Providers with base shared resources
|
134
|
-
test('We load 3 Sub Menus by default', async
|
129
|
+
test('We load 3 Sub Menus by default', async() => {
|
135
130
|
const el = fixtureSync(container());
|
136
131
|
const $brContainer = document.createElement('div');
|
137
132
|
const brStub = {
|
@@ -140,8 +135,8 @@ describe('<book-navigator>', () => {
|
|
140
135
|
jumpToIndex: sinon.fake(),
|
141
136
|
options: {},
|
142
137
|
refs: {
|
143
|
-
$brContainer
|
144
|
-
}
|
138
|
+
$brContainer
|
139
|
+
}
|
145
140
|
};
|
146
141
|
el.bookreader = brStub;
|
147
142
|
await el.elementUpdated;
|
@@ -156,12 +151,10 @@ describe('<book-navigator>', () => {
|
|
156
151
|
expect(el.menuProviders.share).toBeInstanceOf(SharingProvider);
|
157
152
|
|
158
153
|
expect(defaultMenus).toContain('visualAdjustments');
|
159
|
-
expect(el.menuProviders.visualAdjustments).toBeInstanceOf(
|
160
|
-
VisualAdjustmentsProvider
|
161
|
-
);
|
154
|
+
expect(el.menuProviders.visualAdjustments).toBeInstanceOf(VisualAdjustmentsProvider);
|
162
155
|
});
|
163
156
|
describe('Loading Sub Menus By Plugin Flags', () => {
|
164
|
-
test('Search: uses `enableSearch` flag', async
|
157
|
+
test('Search: uses `enableSearch` flag', async() => {
|
165
158
|
const el = fixtureSync(container());
|
166
159
|
const $brContainer = document.createElement('div');
|
167
160
|
const brStub = {
|
@@ -170,8 +163,8 @@ describe('<book-navigator>', () => {
|
|
170
163
|
jumpToIndex: sinon.fake(),
|
171
164
|
options: { enableSearch: true },
|
172
165
|
refs: {
|
173
|
-
$brContainer
|
174
|
-
}
|
166
|
+
$brContainer
|
167
|
+
}
|
175
168
|
};
|
176
169
|
el.bookreader = brStub;
|
177
170
|
await el.elementUpdated;
|
@@ -183,9 +176,9 @@ describe('<book-navigator>', () => {
|
|
183
176
|
expect(el.menuProviders.search).toBeInstanceOf(SearchProvider);
|
184
177
|
|
185
178
|
// also adds a menu shortcut
|
186
|
-
expect(el.menuShortcuts.find(
|
179
|
+
expect(el.menuShortcuts.find(m => m.id === 'search')).toBeDefined();
|
187
180
|
});
|
188
|
-
test('Volumes/Multiple Books: uses `enableMultipleBooks` flag', async
|
181
|
+
test('Volumes/Multiple Books: uses `enableMultipleBooks` flag', async() => {
|
189
182
|
const el = fixtureSync(container());
|
190
183
|
const $brContainer = document.createElement('div');
|
191
184
|
const brStub = {
|
@@ -196,13 +189,13 @@ describe('<book-navigator>', () => {
|
|
196
189
|
enableMultipleBooks: true,
|
197
190
|
multipleBooksList: {
|
198
191
|
by_subprefix: {
|
199
|
-
fooSubprefix: 'beep'
|
200
|
-
}
|
201
|
-
}
|
192
|
+
fooSubprefix: 'beep'
|
193
|
+
}
|
194
|
+
}
|
202
195
|
},
|
203
196
|
refs: {
|
204
|
-
$brContainer
|
205
|
-
}
|
197
|
+
$brContainer
|
198
|
+
}
|
206
199
|
};
|
207
200
|
el.bookreader = brStub;
|
208
201
|
await el.elementUpdated;
|
@@ -214,9 +207,7 @@ describe('<book-navigator>', () => {
|
|
214
207
|
expect(el.menuProviders.volumes).toBeInstanceOf(VolumesProvider);
|
215
208
|
|
216
209
|
// also adds a menu shortcut
|
217
|
-
expect(
|
218
|
-
el.menuShortcuts.find((m) => m.id === 'volumes')
|
219
|
-
).toBeDefined();
|
210
|
+
expect(el.menuShortcuts.find(m => m.id === 'volumes')).toBeDefined();
|
220
211
|
});
|
221
212
|
});
|
222
213
|
test('keeps track of base shared resources for providers in: `baseProviderConfig`', () => {
|
@@ -324,9 +315,7 @@ describe('<book-navigator>', () => {
|
|
324
315
|
console.log();
|
325
316
|
sidePanelConfig = e.detail;
|
326
317
|
});
|
327
|
-
const toggleSearchMenuEvent = new Event(
|
328
|
-
'BookReader:ToggleSearchMenu'
|
329
|
-
);
|
318
|
+
const toggleSearchMenuEvent = new Event('BookReader:ToggleSearchMenu');
|
330
319
|
window.dispatchEvent(toggleSearchMenuEvent);
|
331
320
|
|
332
321
|
await elementUpdated(el);
|
@@ -338,15 +327,15 @@ describe('<book-navigator>', () => {
|
|
338
327
|
});
|
339
328
|
});
|
340
329
|
|
341
|
-
describe('Resizing',
|
330
|
+
describe('Resizing',() => {
|
342
331
|
test('keeps track of `brWidth` and `brHeight`', async () => {
|
343
332
|
const el = fixtureSync(container());
|
344
333
|
const brStub = {
|
345
334
|
resize: sinon.fake(),
|
346
335
|
options: {},
|
347
336
|
refs: {
|
348
|
-
$brContainer: document.createElement('div')
|
349
|
-
}
|
337
|
+
$brContainer: document.createElement('div')
|
338
|
+
}
|
350
339
|
};
|
351
340
|
el.bookreader = brStub;
|
352
341
|
await elementUpdated(el);
|
@@ -356,9 +345,9 @@ describe('<book-navigator>', () => {
|
|
356
345
|
const mockResizeEvent = {
|
357
346
|
contentRect: {
|
358
347
|
height: 500,
|
359
|
-
width: 900
|
348
|
+
width: 900
|
360
349
|
},
|
361
|
-
target: el.mainBRContainer
|
350
|
+
target: el.mainBRContainer
|
362
351
|
};
|
363
352
|
el.handleResize(mockResizeEvent);
|
364
353
|
|
@@ -375,8 +364,8 @@ describe('<book-navigator>', () => {
|
|
375
364
|
resize: sinon.fake(),
|
376
365
|
options: {},
|
377
366
|
refs: {
|
378
|
-
$brContainer: document.createElement('div')
|
379
|
-
}
|
367
|
+
$brContainer: document.createElement('div')
|
368
|
+
}
|
380
369
|
};
|
381
370
|
|
382
371
|
el.bookreader = brStub;
|
@@ -481,7 +470,7 @@ describe('<book-navigator>', () => {
|
|
481
470
|
|
482
471
|
expect(el.closeFullscreen.callCount).toEqual(1);
|
483
472
|
});
|
484
|
-
test('removes Fullscreen shortcut when leaving fullscreen', async
|
473
|
+
test('removes Fullscreen shortcut when leaving fullscreen', async() => {
|
485
474
|
const el = fixtureSync(container());
|
486
475
|
const brStub = {
|
487
476
|
isFullscreen: () => false,
|
@@ -500,7 +489,7 @@ describe('<book-navigator>', () => {
|
|
500
489
|
expect(el.menuShortcuts.length).toEqual(0);
|
501
490
|
expect(el.emitMenuShortcutsUpdated.callCount).toEqual(1);
|
502
491
|
});
|
503
|
-
test('Event: Listens for `BookReader:FullscreenToggled', async
|
492
|
+
test('Event: Listens for `BookReader:FullscreenToggled', async() => {
|
504
493
|
const el = fixtureSync(container());
|
505
494
|
const brStub = {
|
506
495
|
isFullscreen: () => true,
|
@@ -602,5 +591,40 @@ describe('<book-navigator>', () => {
|
|
602
591
|
expect(preventDefaultSpy.called).toEqual(true);
|
603
592
|
});
|
604
593
|
});
|
594
|
+
it('Allows unrestricted books access to context menu', async () => {
|
595
|
+
window.archive_analytics = { send_event_no_sampling: sinon.fake() };
|
596
|
+
|
597
|
+
const el = fixtureSync(container());
|
598
|
+
const brStub = {
|
599
|
+
options: { restricted: false },
|
600
|
+
};
|
601
|
+
|
602
|
+
el.bookreader = brStub;
|
603
|
+
el.bookIsRestricted = false;
|
604
|
+
|
605
|
+
await el.elementUpdated;
|
606
|
+
|
607
|
+
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
|
608
|
+
false
|
609
|
+
);
|
610
|
+
|
611
|
+
const body = document.querySelector('body');
|
612
|
+
// const element stub for img.BRpageimage
|
613
|
+
const imgBRpageimage = document.createElement('img');
|
614
|
+
imgBRpageimage.classList.add('not-targeted-element');
|
615
|
+
body.appendChild(imgBRpageimage);
|
616
|
+
const contextMenuEvent = new Event('contextmenu', { bubbles: true });
|
617
|
+
|
618
|
+
// Set spy on contextMenuEvent to check if `preventDefault` is called
|
619
|
+
const preventDefaultSpy = sinon.spy(contextMenuEvent, 'preventDefault');
|
620
|
+
expect(preventDefaultSpy.called).toEqual(false);
|
621
|
+
|
622
|
+
imgBRpageimage.dispatchEvent(contextMenuEvent);
|
623
|
+
|
624
|
+
// analytics fires
|
625
|
+
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(true);
|
626
|
+
// we do not prevent default
|
627
|
+
expect(preventDefaultSpy.called).toEqual(false);
|
628
|
+
});
|
605
629
|
});
|
606
630
|
});
|