Skip to content

Commit

Permalink
Merge pull request #1364 from cdrini/autoflip-param
Browse files Browse the repository at this point in the history
Move autoflip url parameter handling to plugin.autoplay.js
  • Loading branch information
cdrini authored Jan 2, 2025
2 parents 7c7357e + 868a6ec commit 48f5a99
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 113 deletions.
59 changes: 0 additions & 59 deletions BookReaderDemo/BookReaderJSAutoplay.js

This file was deleted.

10 changes: 0 additions & 10 deletions BookReaderDemo/IADemoBr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function getFromUrl(name, def) {
const ocaid = urlParams.get('ocaid');
const openFullImmersionTheater = urlParams.get('view') === 'theater';
const ui = urlParams.get('ui');
const autoflip = urlParams.get('autoflip');
const searchTerm = urlParams.get('q');

const iaBookReader = document.querySelector('ia-bookreader');
Expand Down Expand Up @@ -46,12 +45,6 @@ BookReader.optionOverrides.imagesBaseURL = '/BookReader/images/';
const initializeBookReader = (brManifest) => {
console.log('initializeBookReader', brManifest);

const customAutoflipParams = {
autoflip: !!autoflip,
flipSpeed: parseFloat(getFromUrl('flipSpeed', '2000')),
flipDelay: parseFloat(getFromUrl('flipDelay', '5000')),
};

const options = {
el: '#BookReader',
/* Url plugin - IA uses History mode for URL */
Expand Down Expand Up @@ -90,9 +83,6 @@ const initializeBookReader = (brManifest) => {

const isRestricted = brManifest.data.isRestricted;
window.dispatchEvent(new CustomEvent('contextmenu', { detail: { isRestricted } }));
if (customAutoflipParams.autoflip) {
window.br.autoToggle(customAutoflipParams);
}
};

window.initializeBookReader = initializeBookReader;
Expand Down
37 changes: 0 additions & 37 deletions BookReaderDemo/demo-autoplay.html

This file was deleted.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<!-- plugin.search.js -->
<li><a href="BookReaderDemo/demo-internetarchive.html?ocaid=adventureofsherl0000unse">From Internet Archive - a book with CHAPTERS</a></li>
<li><a href="BookReaderDemo/demo-iiif.html">IIIF</a></li>
<li><a href="BookReaderDemo/demo-autoplay.html">Autoplay (kiosk mode)</a></li>
<li><a href="BookReaderDemo/demo-internetarchive.html?ocaid=goodytwoshoes00newyiala&autoflip=1">Autoplay (kiosk mode)</a></li>
<li><a href="BookReaderDemo/demo-plugin-menu-toggle.html">Plugin: Full screen menu toggle</a></li>
<li><a href="BookReaderDemo/immersion-mode.html">Start in immersion (fullscreen) mode</a></li>
<!-- plugin.search.js -->
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/plugin.autoplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ BookReader.prototype.setup = (function(super_) {
return function (options) {
super_.call(this, options);

this.auto = false;
this.autoTimer = null;
this.flipDelay = 5000;
};
Expand All @@ -28,7 +27,13 @@ BookReader.prototype.init = (function(super_) {
super_.call(this, options);

if (!this.options.enableAutoPlayPlugin) return;

this.bind(BookReader.eventNames.stop, () => this.autoStop());

const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('autoflip') === '1') {
this.autoToggle();
}
};
})(BookReader.prototype.init);

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/autoplay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const getLocationHref = ClientFunction(() => window.location.href.toString());
const FLIP_SPEED = 1000;
const FIRST_PAGE_DELAY = 2000;

fixture `Autoplay plugin`.page `${params.baseUrl}/BookReaderDemo/demo-autoplay.html`;
fixture `Autoplay plugin`.page `${params.baseUrl}/BookReaderDemo/demo-internetarchive.html?ocaid=goody&autoflip=1`;

test('page auto-advances after allotted flip speed and delay', async t => {
await t.wait(2 * FLIP_SPEED + FIRST_PAGE_DELAY);
Expand Down
4 changes: 0 additions & 4 deletions tests/jest/plugins/plugin.autoplay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ describe('Plugin: Menu Toggle', () => {
test('has option flag', () => {
expect(BookReader.defaultOptions.enableAutoPlayPlugin).toEqual(true);
});
test('has added BR property: auto', () => {
expect(br).toHaveProperty('auto');
expect(br.auto).toEqual(false);
});
test('has added BR property: autoTimer', () => {
expect(br).toHaveProperty('autoTimer');
expect(br.autoTimer).toEqual(null);
Expand Down

0 comments on commit 48f5a99

Please sign in to comment.