EPUBJSR.search = {}; // Search Server -- https://github.com/futurepress/epubjs-search EPUBJSR.search.SERVER = "http://localhost:5000"; EPUBJSR.search.request = function(q, callback) { var fetch = $.ajax({ dataType: "json", url: EPUBJSR.search.SERVER + "/search?q=" + encodeURIComponent(q) }); fetch.fail(function(err) { console.error(err); }); fetch.done(function(results) { callback(results); }); }; EPUBJSR.search.View = function(Book) { var $searchBox = $("#searchBox"), $searchResults = $("#searchResults"), $tocView = $("#toc"), $searchView = $("#searchView"), iframeDoc; $searchBox.on("search", function(e) { var q = $searchBox.val(); e.preventDefault(); //-- SearchBox is empty or cleared if(q == '') { $searchResults.empty(); $searchView.removeClass("shown"); $tocView.removeClass("hidden"); $(iframeDoc).find('body').unhighlight(); iframeDoc = false; return; } if(!$searchView.hasClass("shown")) { $searchView.addClass("shown"); $tocView.addClass("hidden"); } $searchResults.empty(); $searchResults.append("
Searching...
No Results Found
"+result.highlight+"
"); $item.on("click", function(e) { var $this = $(this), cfi = $this.data("cfi"); e.preventDefault(); Book.gotoCfi(cfi); Book.on("renderer:chapterDisplayed", function() { iframeDoc = $("#area iframe")[0].contentDocument; $(iframeDoc).find('body').highlight(q, { element: 'span' }); }) }); $li.append($item); $searchResults.append($li); }); }); }); };