Skip to content

Commit ffc73a5

Browse files
committed
Fix Toolbar requiring SearchView.init having already been called
1 parent 3618991 commit ffc73a5

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

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)