diff options
author | Andrew Dolgov <[email protected]> | 2018-06-29 17:56:20 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-06-29 17:56:20 +0300 |
commit | d4a1bb6a2f2d7a9e0e0dad419b032d6de915291a (patch) | |
tree | 8c25daa5e94fdc2c731f236e4c4fa373dc0d554c | |
parent | f46c3f561f6d079a4ac8fb8ba0134508479a9eff (diff) |
fix book search
-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> |