Skip to content

Commit aac7a96

Browse files
Fix plugin initialization order when reduceSet is invalid
1 parent 710e930 commit aac7a96

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/BookReader.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ BookReader.prototype.setup = function(options) {
174174
/** @deprecated */
175175
this.bookPath = options.bookPath;
176176

177+
if (options.reduceSet && !NAMED_REDUCE_SETS[options.reduceSet]) {
178+
console.warn(
179+
`Invalid reduceSet "${options.reduceSet}". Falling back to default.`
180+
);
181+
}
182+
this.reduceSet =NAMED_REDUCE_SETS[options.reduceSet] || NAMED_REDUCE_SETS[DEFAULT_OPTIONS.reduceSet];
183+
this.pageProgression = options.pageProgression;
184+
this.protected = options.protected;
185+
this.data = options.data;
186+
this.book = new BookModel(this);
187+
177188
// Construct the usual plugins first to get type hints
178189
this.plugins = {
179190
archiveAnalytics: BookReader.PLUGINS.archiveAnalytics ? new BookReader.PLUGINS.archiveAnalytics(this) : null,
@@ -247,12 +258,6 @@ BookReader.prototype.setup = function(options) {
247258
this.defaults = options.defaults;
248259
this.padding = options.padding;
249260

250-
this.reduceSet = NAMED_REDUCE_SETS[options.reduceSet];
251-
if (!this.reduceSet) {
252-
console.warn(`Invalid reduceSet ${options.reduceSet}. Ignoring.`);
253-
this.reduceSet = NAMED_REDUCE_SETS[DEFAULT_OPTIONS.reduceSet];
254-
}
255-
256261
/** @type {number}
257262
* can be 1 or 2 or 3 based on the display mode const value
258263
*/
@@ -305,19 +310,10 @@ BookReader.prototype.setup = function(options) {
305310
this.enableExperimentalControls = options.enableExperimentalControls;
306311
this.el = options.el;
307312

308-
this.pageProgression = options.pageProgression;
309-
this.protected = options.protected;
310313
this.getEmbedCode = options.getEmbedCode;
311314
this.popup = null;
312315

313-
// Assign the data methods
314-
this.data = options.data;
315316

316-
/** @type {{[name: string]: JQuery}} */
317-
this.refs = {};
318-
319-
/** The book being displayed in BookReader*/
320-
this.book = new BookModel(this);
321317

322318
if (options.getNumLeafs) this.book.getNumLeafs = options.getNumLeafs.bind(this);
323319
if (options.getPageWidth) this.book.getPageWidth = options.getPageWidth.bind(this);
@@ -329,6 +325,11 @@ BookReader.prototype.setup = function(options) {
329325
if (options.getSpreadIndices) this.book.getSpreadIndices = options.getSpreadIndices.bind(this);
330326
if (options.leafNumToIndex) this.book.leafNumToIndex = options.leafNumToIndex.bind(this);
331327

328+
329+
/** @type {{[name: string]: JQuery}} */
330+
this.refs = {};
331+
332+
332333
/**
333334
* @private Components are 'subchunks' of bookreader functionality, usually UI related
334335
* They should be relatively decoupled from each other/bookreader.

0 commit comments

Comments
 (0)