Skip to content

Commit

Permalink
Skips subsequent creation of search views when setup called 1+n times (
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneriley authored Oct 5, 2020
1 parent dd08f52 commit 3ab0cb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/js/plugins/search/plugin.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BookReader.prototype.setup = (function (super_) {
this.subPrefix = options.subPrefix;
this.bookPath = options.bookPath;

if (this.searchView) { return; }
this.searchView = new SearchView({
br: this,
selector: '#BRsearch_tray',
Expand Down
6 changes: 5 additions & 1 deletion src/js/plugins/search/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ class SearchView {
}

teardownSearchNavigation() {
if (!this.dom.searchNavigation) { return; }
if (!this.dom.searchNavigation) {
this.dom.searchNavigation = $('.BRsearch-navigation');
}
if (!this.dom.searchNavigation.length) { return; }

this.dom.searchNavigation.off('.searchNavigation').remove();
this.dom.searchNavigation = null;
Expand Down Expand Up @@ -423,6 +426,7 @@ class SearchView {
handleSearchCallback(e, { results }) {
this.matches = results.matches;
this.setCurrentMatchIndex();
this.teardownSearchNavigation();
this.renderSearchNavigation();
this.bindSearchNavigationEvents();
this.renderMatches(results.matches);
Expand Down

0 comments on commit 3ab0cb2

Please sign in to comment.