Skip to content

Commit 9b49a04

Browse files
committed
Make unviewable page URI configurable via options
1 parent b314ea1 commit 9b49a04

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/BookReader/BookModel.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import { clamp } from './utils.js';
44
/** @typedef {import('./options.js').PageData} PageData */
55
/** @typedef {import('../BookReader.js').default} BookReader */
66

7-
// URI to display when a page is not viewable.
8-
// TODO Render configurable html for the user instead.
9-
// FIXME Don't reference files on archive.org
10-
const UNVIEWABLE_PAGE_URI = '/bookreader/static/preview-default.png';
11-
127
/**
138
* Contains information about the Book/Document independent of the way it is
149
* being rendering. Nothing here should reference e.g. the mode, zoom, etc.
@@ -160,7 +155,17 @@ export class BookModel {
160155
*/
161156
// eslint-disable-next-line no-unused-vars
162157
getPageURI(index, reduce, rotate) {
163-
return !this.getPageProp(index, 'viewable', true) ? UNVIEWABLE_PAGE_URI : this.getPageProp(index, 'uri');
158+
if (!this.getPageProp(index, 'viewable', true)) {
159+
const uri = this.br.options.unviewablePageURI;
160+
if (uri.startsWith('.')) {
161+
// It's a relative path, so make it relative to the images path
162+
return this.br.options.imagesBaseURL + uri;
163+
} else {
164+
return uri;
165+
}
166+
} else {
167+
return this.getPageProp(index, 'uri');
168+
}
164169
}
165170

166171
/**

src/BookReader/options.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ export const DEFAULT_OPTIONS = {
301301
* On init, by default, we want to use srcSet for images
302302
*/
303303
useSrcSet: false,
304+
305+
/**
306+
* @type {string}
307+
* Path to the image to display when a page is unviewable (i.e. when
308+
* displaying a preview of a book).
309+
*
310+
* Relative to the imagesBaseURL if a relative path is specified.
311+
*/
312+
unviewablePageURI: './unviewable_page.png',
304313
};
305314

306315
/**
5 KB
Loading

0 commit comments

Comments
 (0)