diff options
-rw-r--r-- | js/read.js | 34 | ||||
-rw-r--r-- | read.html | 2 |
2 files changed, 21 insertions, 15 deletions
@@ -270,21 +270,27 @@ function search() { list.html(""); if (query) { - var results = window.book.currentChapter.find(query); - - $.each(results, function (i, row) { - var a = $("<a>") - .attr('href', '#') - .html(row.excerpt + - " <b>(Loc. " + window.book.pagination.pageFromCfi(row.cfi) + ")</b>") - .attr('data-cfi', row.cfi) - .attr('data-id', row.id) - .click(function() { - window.book.rendition.display(a.attr('data-cfi')); - }); - - list.append($("<li>").append(a)); + Promise.all( + book.spine.spineItems.map( + item => item.load(book.load.bind(book)) + .then(item.find.bind(item, query)) + .finally(item.unload.bind(item))) + ) + .then(results => Promise.resolve([].concat.apply([], results))) + .then(function(results) { + $.each(results, function (i, row) { + var a = $("<a>") + .attr('href', '#') + .html(row.excerpt) + .attr('data-cfi', row.cfi) + .attr('data-id', row.id) + .click(function() { + window.book.rendition.display(a.attr('data-cfi')); + }); + + list.append($("<li>").append(a)); + }); }); } } @@ -170,7 +170,7 @@ <form class="form-horizontal" onsubmit="return false;"> <div class="form-group"> - <label class="col-sm-4 control-label">Search</label> + <label class="col-sm-4 control-label">Search query</label> <div class="col-sm-8"> <input type="search" class="form-control search_input"> </div> |