mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Fixed spaces in Section
This commit is contained in:
parent
c2b3284259
commit
8bfed1593c
2 changed files with 54 additions and 53 deletions
|
@ -52,6 +52,7 @@
|
|||
|
||||
|
||||
rendition.on("rendered", function(section){
|
||||
console.log("rendered", section);
|
||||
var nextSection = section.next();
|
||||
var prevSection = section.prev();
|
||||
|
||||
|
|
104
src/section.js
104
src/section.js
|
@ -54,7 +54,7 @@ class Section {
|
|||
// var directory = new Url(this.url).directory;
|
||||
|
||||
this.document = xml;
|
||||
this.contents = xml.documentElement;
|
||||
this.contents = xml.documentElement;
|
||||
|
||||
return this.hooks.content.trigger(this.document, this);
|
||||
}.bind(this))
|
||||
|
@ -97,8 +97,8 @@ class Section {
|
|||
} else {
|
||||
Serializer = XMLSerializer;
|
||||
}
|
||||
var serializer = new Serializer();
|
||||
this.output = serializer.serializeToString(contents);
|
||||
var serializer = new Serializer();
|
||||
this.output = serializer.serializeToString(contents);
|
||||
return this.output;
|
||||
}.bind(this)).
|
||||
then(function(){
|
||||
|
@ -114,64 +114,64 @@ class Section {
|
|||
return rendered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a string in a section
|
||||
* @param {string} _query The query string to find
|
||||
* @return {object[]} A list of matches, with form {cfi, excerpt}
|
||||
*/
|
||||
find(_query){
|
||||
var section = this;
|
||||
var matches = [];
|
||||
var query = _query.toLowerCase();
|
||||
var find = function(node){
|
||||
var text = node.textContent.toLowerCase();
|
||||
var range = section.document.createRange();
|
||||
var cfi;
|
||||
var pos;
|
||||
var last = -1;
|
||||
var excerpt;
|
||||
var limit = 150;
|
||||
/**
|
||||
* Find a string in a section
|
||||
* @param {string} _query The query string to find
|
||||
* @return {object[]} A list of matches, with form {cfi, excerpt}
|
||||
*/
|
||||
find(_query){
|
||||
var section = this;
|
||||
var matches = [];
|
||||
var query = _query.toLowerCase();
|
||||
var find = function(node){
|
||||
var text = node.textContent.toLowerCase();
|
||||
var range = section.document.createRange();
|
||||
var cfi;
|
||||
var pos;
|
||||
var last = -1;
|
||||
var excerpt;
|
||||
var limit = 150;
|
||||
|
||||
while (pos != -1) {
|
||||
// Search for the query
|
||||
pos = text.indexOf(query, last + 1);
|
||||
while (pos != -1) {
|
||||
// Search for the query
|
||||
pos = text.indexOf(query, last + 1);
|
||||
|
||||
if (pos != -1) {
|
||||
// We found it! Generate a CFI
|
||||
range = section.document.createRange();
|
||||
range.setStart(node, pos);
|
||||
range.setEnd(node, pos + query.length);
|
||||
if (pos != -1) {
|
||||
// We found it! Generate a CFI
|
||||
range = section.document.createRange();
|
||||
range.setStart(node, pos);
|
||||
range.setEnd(node, pos + query.length);
|
||||
|
||||
cfi = section.cfiFromRange(range);
|
||||
cfi = section.cfiFromRange(range);
|
||||
|
||||
// Generate the excerpt
|
||||
if (node.textContent.length < limit) {
|
||||
excerpt = node.textContent;
|
||||
}
|
||||
else {
|
||||
excerpt = node.textContent.substring(pos - limit/2, pos + limit/2);
|
||||
excerpt = "..." + excerpt + "...";
|
||||
}
|
||||
// Generate the excerpt
|
||||
if (node.textContent.length < limit) {
|
||||
excerpt = node.textContent;
|
||||
}
|
||||
else {
|
||||
excerpt = node.textContent.substring(pos - limit/2, pos + limit/2);
|
||||
excerpt = "..." + excerpt + "...";
|
||||
}
|
||||
|
||||
// Add the CFI to the matches list
|
||||
matches.push({
|
||||
cfi: cfi,
|
||||
excerpt: excerpt
|
||||
});
|
||||
}
|
||||
// Add the CFI to the matches list
|
||||
matches.push({
|
||||
cfi: cfi,
|
||||
excerpt: excerpt
|
||||
});
|
||||
}
|
||||
|
||||
last = pos;
|
||||
}
|
||||
};
|
||||
last = pos;
|
||||
}
|
||||
};
|
||||
|
||||
sprint(section.document, function(node) {
|
||||
find(node);
|
||||
});
|
||||
sprint(section.document, function(node) {
|
||||
find(node);
|
||||
});
|
||||
|
||||
return matches;
|
||||
};
|
||||
return matches;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Reconciles the current chapters layout properies with
|
||||
* the global layout properities.
|
||||
* @param {object} global The globa layout settings object, chapter properties string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue