mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Listen for scroll event in rendition and report location
This commit is contained in:
parent
f5fe50bd24
commit
ff081bc389
5 changed files with 44 additions and 32 deletions
38
dist/epub.js
vendored
38
dist/epub.js
vendored
|
@ -9781,13 +9781,13 @@ ContinuousViewManager.prototype.scrolledLocation = function(){
|
|||
var container = this.container.getBoundingClientRect();
|
||||
|
||||
if(visible.length === 1) {
|
||||
return this.mapping.page(visible[0]);
|
||||
return this.mapping.page(visible[0].contents, visible[0].section.cfiBase);
|
||||
}
|
||||
|
||||
if(visible.length > 1) {
|
||||
|
||||
startPage = this.mapping.page(visible[0]);
|
||||
endPage = this.mapping.page(visible[visible.length-1]);
|
||||
startPage = this.mapping.page(visible[0].contents, visible[0].section.cfiBase);
|
||||
endPage = this.mapping.page(visible[visible.length-1].contents, visible[visible.length-1].section.cfiBase);
|
||||
|
||||
return {
|
||||
start: startPage.start,
|
||||
|
@ -9807,7 +9807,7 @@ ContinuousViewManager.prototype.paginatedLocation = function(){
|
|||
startA = container.left - visible[0].position().left;
|
||||
endA = startA + this.layout.spreadWidth;
|
||||
|
||||
return this.mapping.page(visible[0], startA, endA);
|
||||
return this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA);
|
||||
}
|
||||
|
||||
if(visible.length > 1) {
|
||||
|
@ -9820,8 +9820,8 @@ ContinuousViewManager.prototype.paginatedLocation = function(){
|
|||
startB = container.left + this.layout.spreadWidth - visible[visible.length-1].position().left;
|
||||
endB = startB + this.layout.columnWidth;
|
||||
|
||||
pageLeft = this.mapping.page(visible[0], startA, endA);
|
||||
pageRight = this.mapping.page(visible[visible.length-1], startB, endB);
|
||||
pageLeft = this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA);
|
||||
pageRight = this.mapping.page(visible[visible.length-1].contents, visible[visible.length-1].section.cfiBase, startB, endB);
|
||||
|
||||
return {
|
||||
start: pageLeft.start,
|
||||
|
@ -10368,26 +10368,27 @@ SingleViewManager.prototype.updateFlow = function(flow){
|
|||
module.exports = SingleViewManager;
|
||||
|
||||
},{"../core":13,"../epubcfi":14,"../mapping":20,"../queue":23,"../stage":29,"../views":31,"rsvp":5}],20:[function(require,module,exports){
|
||||
var EpubCFI = require('./epubcfi');
|
||||
|
||||
function Mapping(layout){
|
||||
this.layout = layout;
|
||||
};
|
||||
|
||||
Mapping.prototype.section = function(view) {
|
||||
var ranges = this.findRanges(view);
|
||||
var map = this.rangeListToCfiList(view, ranges);
|
||||
var map = this.rangeListToCfiList(view.section.cfiBase, ranges);
|
||||
|
||||
return map;
|
||||
};
|
||||
|
||||
Mapping.prototype.page = function(view, start, end) {
|
||||
var contents = view.contents;
|
||||
Mapping.prototype.page = function(contents, cfiBase, start, end) {
|
||||
var root = contents && contents.document ? contents.document.body : false;
|
||||
|
||||
if (!root) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.rangePairToCfiPair(view.section, {
|
||||
return this.rangePairToCfiPair(cfiBase, {
|
||||
start: this.findStart(root, start, end),
|
||||
end: this.findEnd(root, start, end)
|
||||
});
|
||||
|
@ -10629,7 +10630,7 @@ Mapping.prototype.splitTextNodeIntoRanges = function(node, _splitter){
|
|||
|
||||
|
||||
|
||||
Mapping.prototype.rangePairToCfiPair = function(section, rangePair){
|
||||
Mapping.prototype.rangePairToCfiPair = function(cfiBase, rangePair){
|
||||
|
||||
var startRange = rangePair.start;
|
||||
var endRange = rangePair.end;
|
||||
|
@ -10637,8 +10638,10 @@ Mapping.prototype.rangePairToCfiPair = function(section, rangePair){
|
|||
startRange.collapse(true);
|
||||
endRange.collapse(true);
|
||||
|
||||
startCfi = section.cfiFromRange(startRange);
|
||||
endCfi = section.cfiFromRange(endRange);
|
||||
// startCfi = section.cfiFromRange(startRange);
|
||||
// endCfi = section.cfiFromRange(endRange);
|
||||
startCfi = new EpubCFI(startRange, cfiBase).toString();
|
||||
endCfi = new EpubCFI(endRange, cfiBase).toString();
|
||||
|
||||
return {
|
||||
start: startCfi,
|
||||
|
@ -10647,12 +10650,12 @@ Mapping.prototype.rangePairToCfiPair = function(section, rangePair){
|
|||
|
||||
};
|
||||
|
||||
Mapping.prototype.rangeListToCfiList = function(view, columns){
|
||||
Mapping.prototype.rangeListToCfiList = function(cfiBase, columns){
|
||||
var map = [];
|
||||
var rangePair, cifPair;
|
||||
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
cifPair = this.rangePairToCfiPair(view.section, columns[i]);
|
||||
cifPair = this.rangePairToCfiPair(cfiBase, columns[i]);
|
||||
|
||||
map.push(cifPair);
|
||||
|
||||
|
@ -10663,7 +10666,7 @@ Mapping.prototype.rangeListToCfiList = function(view, columns){
|
|||
|
||||
module.exports = Mapping;
|
||||
|
||||
},{}],21:[function(require,module,exports){
|
||||
},{"./epubcfi":14}],21:[function(require,module,exports){
|
||||
var core = require('./core');
|
||||
var Parser = require('./parser');
|
||||
var RSVP = require('rsvp');
|
||||
|
@ -11585,6 +11588,9 @@ Rendition.prototype.start = function(){
|
|||
// Listen for resizing
|
||||
this.manager.on("resized", this.onResized.bind(this));
|
||||
|
||||
// Listen for scroll changes
|
||||
this.manager.on("scroll", this.reportLocation.bind(this));
|
||||
|
||||
|
||||
this.on('displayed', this.reportLocation.bind(this));
|
||||
|
||||
|
|
2
dist/epub.js.map
vendored
2
dist/epub.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -493,13 +493,13 @@ ContinuousViewManager.prototype.scrolledLocation = function(){
|
|||
var container = this.container.getBoundingClientRect();
|
||||
|
||||
if(visible.length === 1) {
|
||||
return this.mapping.page(visible[0]);
|
||||
return this.mapping.page(visible[0].contents, visible[0].section.cfiBase);
|
||||
}
|
||||
|
||||
if(visible.length > 1) {
|
||||
|
||||
startPage = this.mapping.page(visible[0]);
|
||||
endPage = this.mapping.page(visible[visible.length-1]);
|
||||
startPage = this.mapping.page(visible[0].contents, visible[0].section.cfiBase);
|
||||
endPage = this.mapping.page(visible[visible.length-1].contents, visible[visible.length-1].section.cfiBase);
|
||||
|
||||
return {
|
||||
start: startPage.start,
|
||||
|
@ -519,7 +519,7 @@ ContinuousViewManager.prototype.paginatedLocation = function(){
|
|||
startA = container.left - visible[0].position().left;
|
||||
endA = startA + this.layout.spreadWidth;
|
||||
|
||||
return this.mapping.page(visible[0], startA, endA);
|
||||
return this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA);
|
||||
}
|
||||
|
||||
if(visible.length > 1) {
|
||||
|
@ -532,8 +532,8 @@ ContinuousViewManager.prototype.paginatedLocation = function(){
|
|||
startB = container.left + this.layout.spreadWidth - visible[visible.length-1].position().left;
|
||||
endB = startB + this.layout.columnWidth;
|
||||
|
||||
pageLeft = this.mapping.page(visible[0], startA, endA);
|
||||
pageRight = this.mapping.page(visible[visible.length-1], startB, endB);
|
||||
pageLeft = this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA);
|
||||
pageRight = this.mapping.page(visible[visible.length-1].contents, visible[visible.length-1].section.cfiBase, startB, endB);
|
||||
|
||||
return {
|
||||
start: pageLeft.start,
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
var EpubCFI = require('./epubcfi');
|
||||
|
||||
function Mapping(layout){
|
||||
this.layout = layout;
|
||||
};
|
||||
|
||||
Mapping.prototype.section = function(view) {
|
||||
var ranges = this.findRanges(view);
|
||||
var map = this.rangeListToCfiList(view, ranges);
|
||||
var map = this.rangeListToCfiList(view.section.cfiBase, ranges);
|
||||
|
||||
return map;
|
||||
};
|
||||
|
||||
Mapping.prototype.page = function(view, start, end) {
|
||||
var contents = view.contents;
|
||||
Mapping.prototype.page = function(contents, cfiBase, start, end) {
|
||||
var root = contents && contents.document ? contents.document.body : false;
|
||||
|
||||
if (!root) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.rangePairToCfiPair(view.section, {
|
||||
return this.rangePairToCfiPair(cfiBase, {
|
||||
start: this.findStart(root, start, end),
|
||||
end: this.findEnd(root, start, end)
|
||||
});
|
||||
|
@ -259,7 +260,7 @@ Mapping.prototype.splitTextNodeIntoRanges = function(node, _splitter){
|
|||
|
||||
|
||||
|
||||
Mapping.prototype.rangePairToCfiPair = function(section, rangePair){
|
||||
Mapping.prototype.rangePairToCfiPair = function(cfiBase, rangePair){
|
||||
|
||||
var startRange = rangePair.start;
|
||||
var endRange = rangePair.end;
|
||||
|
@ -267,8 +268,10 @@ Mapping.prototype.rangePairToCfiPair = function(section, rangePair){
|
|||
startRange.collapse(true);
|
||||
endRange.collapse(true);
|
||||
|
||||
startCfi = section.cfiFromRange(startRange);
|
||||
endCfi = section.cfiFromRange(endRange);
|
||||
// startCfi = section.cfiFromRange(startRange);
|
||||
// endCfi = section.cfiFromRange(endRange);
|
||||
startCfi = new EpubCFI(startRange, cfiBase).toString();
|
||||
endCfi = new EpubCFI(endRange, cfiBase).toString();
|
||||
|
||||
return {
|
||||
start: startCfi,
|
||||
|
@ -277,12 +280,12 @@ Mapping.prototype.rangePairToCfiPair = function(section, rangePair){
|
|||
|
||||
};
|
||||
|
||||
Mapping.prototype.rangeListToCfiList = function(view, columns){
|
||||
Mapping.prototype.rangeListToCfiList = function(cfiBase, columns){
|
||||
var map = [];
|
||||
var rangePair, cifPair;
|
||||
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
cifPair = this.rangePairToCfiPair(view.section, columns[i]);
|
||||
cifPair = this.rangePairToCfiPair(cfiBase, columns[i]);
|
||||
|
||||
map.push(cifPair);
|
||||
|
||||
|
|
|
@ -127,6 +127,9 @@ Rendition.prototype.start = function(){
|
|||
// Listen for resizing
|
||||
this.manager.on("resized", this.onResized.bind(this));
|
||||
|
||||
// Listen for scroll changes
|
||||
this.manager.on("scroll", this.reportLocation.bind(this));
|
||||
|
||||
|
||||
this.on('displayed', this.reportLocation.bind(this));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue