1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Find returns excerpt of text

This commit is contained in:
Fred Chasen 2014-08-05 23:56:35 -04:00
parent 5700a10b54
commit 16f671d224
9 changed files with 66 additions and 10 deletions

File diff suppressed because one or more lines are too long

16
reader/js/epub.min.js vendored
View file

@ -3690,6 +3690,8 @@ EPUBJS.Chapter.prototype.find = function(_query){
var cfi;
var pos;
var last = -1;
var excerpt;
var limit = 150;
while (pos != -1) {
pos = text.indexOf(query, last + 1);
@ -3702,8 +3704,20 @@ EPUBJS.Chapter.prototype.find = function(_query){
//Generate CFI
cfi = chapter.cfiFromRange(range);
// Generate Excerpt
if(node.textContent.length < limit) {
excerpt = node.textContent;
} else {
excerpt = node.textContent.substring(pos-limit/2,pos+limit/2);
excerpt = "..." + excerpt + "...";
}
//Add CFI to list
matches.push(cfi);
matches.push({
cfi: cfi,
excerpt: excerpt
});
}
last = pos;