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:
parent
ef2a0771c6
commit
6b16ebe9d0
3 changed files with 21 additions and 52 deletions
|
@ -69,7 +69,6 @@
|
||||||
|
|
||||||
rendition.on("keyup", keyListener);
|
rendition.on("keyup", keyListener);
|
||||||
document.addEventListener("keyup", keyListener, false);
|
document.addEventListener("keyup", keyListener, false);
|
||||||
|
|
||||||
|
|
||||||
book.ready.then(function(){
|
book.ready.then(function(){
|
||||||
// Load in stored locations from json or local storage
|
// Load in stored locations from json or local storage
|
||||||
|
@ -81,7 +80,7 @@
|
||||||
// Or generate the locations on the fly
|
// Or generate the locations on the fly
|
||||||
// Can pass an option number of chars to break sections by
|
// Can pass an option number of chars to break sections by
|
||||||
// default is 150 chars
|
// default is 150 chars
|
||||||
return book.locations.generate(600);
|
return book.locations.generate(1600);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(function(locations){
|
.then(function(locations){
|
||||||
|
|
|
@ -119,15 +119,31 @@ class Locations {
|
||||||
pos = len;
|
pos = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while (pos < len) {
|
while (pos < len) {
|
||||||
// counter = this.break;
|
dist = _break - counter;
|
||||||
pos += dist;
|
|
||||||
|
if (counter === 0) {
|
||||||
|
// Start new range
|
||||||
|
pos += 1;
|
||||||
|
range = this.createRange();
|
||||||
|
range.startContainer = node;
|
||||||
|
range.startOffset = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pos += dist;
|
||||||
|
|
||||||
// Gone over
|
// Gone over
|
||||||
if(pos >= len){
|
if(pos + dist >= len){
|
||||||
// Continue counter for next node
|
// Continue counter for next node
|
||||||
counter = len - (pos - _break);
|
counter += len - pos;
|
||||||
|
// break
|
||||||
|
pos = len;
|
||||||
// At End
|
// At End
|
||||||
} else {
|
} else {
|
||||||
|
// Advance pos
|
||||||
|
pos += dist;
|
||||||
|
|
||||||
// End the previous range
|
// End the previous range
|
||||||
range.endContainer = node;
|
range.endContainer = node;
|
||||||
range.endOffset = pos;
|
range.endOffset = pos;
|
||||||
|
@ -135,14 +151,6 @@ class Locations {
|
||||||
let cfi = new EpubCFI(range, cfiBase).toString();
|
let cfi = new EpubCFI(range, cfiBase).toString();
|
||||||
locations.push(cfi);
|
locations.push(cfi);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
// Start new range
|
|
||||||
pos += 1;
|
|
||||||
range = this.createRange();
|
|
||||||
range.startContainer = node;
|
|
||||||
range.startOffset = pos;
|
|
||||||
|
|
||||||
dist = _break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev = node;
|
prev = node;
|
||||||
|
@ -154,7 +162,6 @@ class Locations {
|
||||||
if (range && range.startContainer && prev) {
|
if (range && range.startContainer && prev) {
|
||||||
range.endContainer = prev;
|
range.endContainer = prev;
|
||||||
range.endOffset = prev.length;
|
range.endOffset = prev.length;
|
||||||
// cfi = section.cfiFromRange(range);
|
|
||||||
let cfi = new EpubCFI(range, cfiBase).toString();
|
let cfi = new EpubCFI(range, cfiBase).toString();
|
||||||
locations.push(cfi);
|
locations.push(cfi);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
|
@ -539,43 +539,6 @@ class DefaultViewManager {
|
||||||
});
|
});
|
||||||
|
|
||||||
return sections;
|
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){
|
isVisible(view, offsetPrev, offsetNext, _container){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue