summaryrefslogtreecommitdiff
path: root/js/read.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-27 16:40:01 +0300
committerAndrew Dolgov <[email protected]>2017-02-27 16:40:01 +0300
commitcbe10493b9de11d36a9e24a98a975565f5ad5f08 (patch)
tree7712527db099f8f5d00b5a025eb39428c3141727 /js/read.js
parent0113910ec610ca0ec33d1dd6776e6282f485d07a (diff)
add chapter search
Diffstat (limited to 'js/read.js')
-rw-r--r--js/read.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/js/read.js b/js/read.js
index 41ef391..38b5d97 100644
--- a/js/read.js
+++ b/js/read.js
@@ -169,5 +169,32 @@ function apply_night_mode() {
$("body").css("background", "white");
}
});
+}
+
+function search() {
+ var query = $(".search_input").val();
+ var list = $(".search_results");
+
+ 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.&nbsp;" + window.book.pagination.pageFromCfi(row.cfi) + ")</b>")
+ .attr('data-cfi', row.cfi)
+ .attr('data-id', row.id)
+ .click(function() {
+ window.book.gotoCfi(a.attr('data-cfi'));
+ });
+ list.append($("<li>").append(a));
+
+ });
+ }
}
+
+