Commit d38b05e2 authored by Robert Knight's avatar Robert Knight

Deactive side-by-side mode in VitalSource PDF books when client is unloaded

For EPUB books, this is handled by VitalSourceContentIntegration delegating to
HTMLIntegration.
parent f06a59cb
...@@ -275,9 +275,12 @@ describe('annotator/integrations/vitalsource', () => { ...@@ -275,9 +275,12 @@ describe('annotator/integrations/vitalsource', () => {
} }
describe('VitalSourceContentIntegration', () => { describe('VitalSourceContentIntegration', () => {
// List of active integrations.
let integrations; let integrations;
let fakeBookElement; let fakeBookElement;
/** Create a new integration and add it to the active list. */
function createIntegration() { function createIntegration() {
const integration = new VitalSourceContentIntegration(document.body, { const integration = new VitalSourceContentIntegration(document.body, {
bookElement: fakeBookElement, bookElement: fakeBookElement,
...@@ -286,6 +289,16 @@ describe('annotator/integrations/vitalsource', () => { ...@@ -286,6 +289,16 @@ describe('annotator/integrations/vitalsource', () => {
return integration; return integration;
} }
/** Destroy an integration and remove it from the active list. */
function destroyIntegration(integration) {
const idx = integrations.indexOf(integration);
if (idx === -1) {
throw new Error('Integration is not in list of active integrations');
}
integrations.splice(idx, 1);
integration.destroy();
}
beforeEach(() => { beforeEach(() => {
integrations = []; integrations = [];
fakeBookElement = new FakeMosaicBookElement(); fakeBookElement = new FakeMosaicBookElement();
...@@ -685,6 +698,18 @@ describe('annotator/integrations/vitalsource', () => { ...@@ -685,6 +698,18 @@ describe('annotator/integrations/vitalsource', () => {
assert.calledOnce(fakeImageTextLayer.destroy); assert.calledOnce(fakeImageTextLayer.destroy);
}); });
it('disables side-by-side mode when destroyed', () => {
createPageImageAndData();
const integration = createIntegration();
integration.fitSideBySide({ expanded: true, width: 100 });
assert.isTrue(integration.sideBySideActive());
destroyIntegration(integration);
assert.isFalse(integration.sideBySideActive());
});
context('when side-by-side mode is toggled', () => { context('when side-by-side mode is toggled', () => {
it('resizes page image', () => { it('resizes page image', () => {
createPageImageAndData(); createPageImageAndData();
......
...@@ -308,7 +308,19 @@ export class VitalSourceContentIntegration ...@@ -308,7 +308,19 @@ export class VitalSourceContentIntegration
} }
destroy() { destroy() {
this._textLayer?.destroy(); if (this._textLayer) {
this._textLayer.destroy();
// Turn off side-by-side for PDF books. For EPUBs this is handled by
// `this._htmlIntegration.destroy()`.
this.fitSideBySide({
// Dummy layout. Setting `expanded: false` disables side-by-side mode.
expanded: false,
height: window.innerHeight,
width: 0,
toolbarWidth: 0,
});
}
this._listeners.removeAll(); this._listeners.removeAll();
this._htmlIntegration.destroy(); this._htmlIntegration.destroy();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment