1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Tidy up Locations

This commit is contained in:
Fred Chasen 2017-07-20 15:57:58 -04:00
parent ef2a0771c6
commit 6b16ebe9d0
3 changed files with 21 additions and 52 deletions

View file

@ -69,7 +69,6 @@
rendition.on("keyup", keyListener);
document.addEventListener("keyup", keyListener, false);
book.ready.then(function(){
// Load in stored locations from json or local storage
@ -81,7 +80,7 @@
// Or generate the locations on the fly
// Can pass an option number of chars to break sections by
// default is 150 chars
return book.locations.generate(600);
return book.locations.generate(1600);
}
})
.then(function(locations){

View file

@ -119,15 +119,31 @@ class Locations {
pos = len;
}
while (pos < len) {
// counter = this.break;
pos += dist;
dist = _break - counter;
if (counter === 0) {
// Start new range
pos += 1;
range = this.createRange();
range.startContainer = node;
range.startOffset = pos;
}
// pos += dist;
// Gone over
if(pos >= len){
if(pos + dist >= len){
// Continue counter for next node
counter = len - (pos - _break);
counter += len - pos;
// break
pos = len;
// At End
} else {
// Advance pos
pos += dist;
// End the previous range
range.endContainer = node;
range.endOffset = pos;
@ -135,14 +151,6 @@ class Locations {
let cfi = new EpubCFI(range, cfiBase).toString();
locations.push(cfi);
counter = 0;
// Start new range
pos += 1;
range = this.createRange();
range.startContainer = node;
range.startOffset = pos;
dist = _break;
}
}
prev = node;
@ -154,7 +162,6 @@ class Locations {
if (range && range.startContainer && prev) {
range.endContainer = prev;
range.endOffset = prev.length;
// cfi = section.cfiFromRange(range);
let cfi = new EpubCFI(range, cfiBase).toString();
locations.push(cfi);
counter = 0;

View file

@ -539,43 +539,6 @@ class DefaultViewManager {
});
return sections;
/*
if(visible.length === 1) {
startA = container.left - visible[0].position().left;
endA = startA + this.layout.spreadWidth + this.layout.gap;
pageLeft = this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA)
return {
index : visible[0].section.index,
href : visible[0].section.href,
start: pageLeft.start,
end: pageLeft.end
};
}
if(visible.length > 1) {
last = visible.length - 1;
// Left Col
startA = container.left - visible[0].position().left;
endA = startA + this.layout.columnWidth + this.layout.gap / 2;
// Right Col
startB = container.left + this.layout.spreadWidth - visible[last].position().left;
endB = startB + this.layout.columnWidth + this.layout.gap / 2;
pageLeft = this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA);
pageRight = this.mapping.page(visible[last].contents, visible[last].section.cfiBase, startB, endB);
return {
index : visible[last].section.index,
href : visible[last].section.href,
start: pageLeft.start,
end: pageRight.end
};
}
*/
}
isVisible(view, offsetPrev, offsetNext, _container){