Skip to content

Commit 44da86f

Browse files
authored
Merge pull request #1345 from cdrini/1344/fix/br-toolbar-w-search
Fix Toolbar requiring SearchView.init having already been called
2 parents 3ebaa8a + 46bdf4c commit 44da86f

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

BookReaderDemo/IADemoBr.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { extraVolOptions, custvolumesManifest } from './ia-multiple-volumes-mani
55
* This is how Internet Archive loads bookreader
66
*/
77
const urlParams = new URLSearchParams(window.location.search);
8+
function getFromUrl(name, def) {
9+
if (urlParams.has(name)) {
10+
return urlParams.get(name);
11+
} else {
12+
return def;
13+
}
14+
}
815

916
const ocaid = urlParams.get('ocaid');
1017
const openFullImmersionTheater = urlParams.get('view') === 'theater';
@@ -41,8 +48,8 @@ const initializeBookReader = (brManifest) => {
4148

4249
const customAutoflipParams = {
4350
autoflip: !!autoflip,
44-
flipSpeed: urlParams.flipSpeed || 2000,
45-
flipDelay: urlParams.flipDelay || 5000
51+
flipSpeed: parseFloat(getFromUrl('flipSpeed', '2000')),
52+
flipDelay: parseFloat(getFromUrl('flipDelay', '5000')),
4653
};
4754

4855
const options = {
@@ -62,7 +69,7 @@ const initializeBookReader = (brManifest) => {
6269
initialSearchTerm: searchTerm ? searchTerm : '',
6370
// leaving this option commented out bc we change given user agent on archive.org
6471
// onePage: { autofit: <?=json_encode($this->ios ? 'width' : 'auto')?> },
65-
showToolbar: false,
72+
showToolbar: getFromUrl('options.showToolbar', 'false') === 'true',
6673
/* Multiple volumes */
6774
// To show multiple volumes:
6875
enableMultipleBooks: false, // turn this on

src/plugins/search/plugin.search.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,28 @@ BookReader.prototype.setup = (function (super_) {
6666
/** @type { {[pageIndex: number]: SearchInsideMatchBox[]} } */
6767
this._searchBoxesByIndex = {};
6868

69-
this.searchView = undefined;
69+
if (this.enableSearch) {
70+
this.searchView = new SearchView({
71+
br: this,
72+
searchCancelledCallback: () => {
73+
this._cancelSearch();
74+
this.trigger('SearchCanceled', { term: this.searchTerm, instance: this });
75+
}
76+
});
77+
} else {
78+
this.searchView = null;
79+
}
7080
};
7181
})(BookReader.prototype.setup);
7282

7383
/** @override */
7484
BookReader.prototype.init = (function (super_) {
7585
return function () {
7686
super_.call(this);
77-
// give SearchView the most complete bookreader state
78-
this.searchView = new SearchView({
79-
br: this,
80-
searchCancelledCallback: () => {
81-
this._cancelSearch();
82-
this.trigger('SearchCanceled', { term: this.searchTerm, instance: this });
83-
}
84-
});
85-
if (this.options.enableSearch && this.options.initialSearchTerm) {
87+
if (!this.enableSearch) return;
88+
89+
this.searchView.init();
90+
if (this.options.initialSearchTerm) {
8691
/**
8792
* this.search() take two parameter
8893
* 1. this.options.initialSearchTerm - search term

src/plugins/search/view.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ class SearchView {
1111
this.br = br;
1212
this.matches = [];
1313
this.cacheDOMElements();
14-
this.bindEvents();
1514
this.cancelSearch = searchCancelledCallback;
1615
}
1716

17+
init() {
18+
this.bindEvents();
19+
}
20+
1821
cacheDOMElements() {
1922
this.dom = {};
2023
// Search input within the top toolbar. Will be removed once the mobile menu is replaced.

0 commit comments

Comments
 (0)