Skip to content

Commit

Permalink
Merge pull request #1345 from cdrini/1344/fix/br-toolbar-w-search
Browse files Browse the repository at this point in the history
Fix Toolbar requiring SearchView.init having already been called
  • Loading branch information
cdrini authored Oct 3, 2024
2 parents 3ebaa8a + 46bdf4c commit 44da86f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
13 changes: 10 additions & 3 deletions BookReaderDemo/IADemoBr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { extraVolOptions, custvolumesManifest } from './ia-multiple-volumes-mani
* This is how Internet Archive loads bookreader
*/
const urlParams = new URLSearchParams(window.location.search);
function getFromUrl(name, def) {
if (urlParams.has(name)) {
return urlParams.get(name);
} else {
return def;
}
}

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

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

const options = {
Expand All @@ -62,7 +69,7 @@ const initializeBookReader = (brManifest) => {
initialSearchTerm: searchTerm ? searchTerm : '',
// leaving this option commented out bc we change given user agent on archive.org
// onePage: { autofit: <?=json_encode($this->ios ? 'width' : 'auto')?> },
showToolbar: false,
showToolbar: getFromUrl('options.showToolbar', 'false') === 'true',
/* Multiple volumes */
// To show multiple volumes:
enableMultipleBooks: false, // turn this on
Expand Down
25 changes: 15 additions & 10 deletions src/plugins/search/plugin.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,28 @@ BookReader.prototype.setup = (function (super_) {
/** @type { {[pageIndex: number]: SearchInsideMatchBox[]} } */
this._searchBoxesByIndex = {};

this.searchView = undefined;
if (this.enableSearch) {
this.searchView = new SearchView({
br: this,
searchCancelledCallback: () => {
this._cancelSearch();
this.trigger('SearchCanceled', { term: this.searchTerm, instance: this });
}
});
} else {
this.searchView = null;
}
};
})(BookReader.prototype.setup);

/** @override */
BookReader.prototype.init = (function (super_) {
return function () {
super_.call(this);
// give SearchView the most complete bookreader state
this.searchView = new SearchView({
br: this,
searchCancelledCallback: () => {
this._cancelSearch();
this.trigger('SearchCanceled', { term: this.searchTerm, instance: this });
}
});
if (this.options.enableSearch && this.options.initialSearchTerm) {
if (!this.enableSearch) return;

this.searchView.init();
if (this.options.initialSearchTerm) {
/**
* this.search() take two parameter
* 1. this.options.initialSearchTerm - search term
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/search/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ class SearchView {
this.br = br;
this.matches = [];
this.cacheDOMElements();
this.bindEvents();
this.cancelSearch = searchCancelledCallback;
}

init() {
this.bindEvents();
}

cacheDOMElements() {
this.dom = {};
// Search input within the top toolbar. Will be removed once the mobile menu is replaced.
Expand Down

0 comments on commit 44da86f

Please sign in to comment.