mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
reduced number of word checks
This commit is contained in:
parent
4f93358b09
commit
27f2f01bf7
12 changed files with 323 additions and 111 deletions
105
build/epub.js
105
build/epub.js
|
@ -2624,7 +2624,6 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
"page" : currentPage
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
if(pager.pageMap.length % 2 > 0 &&
|
||||
|
@ -2637,7 +2636,9 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
}
|
||||
|
||||
// Load up the next chapter
|
||||
nextChapter(done);
|
||||
setTimeout(function(){
|
||||
nextChapter(done);
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
return done.promise;
|
||||
|
@ -3499,7 +3500,7 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}else{
|
||||
url = this.absolute;
|
||||
}
|
||||
|
||||
/*
|
||||
loaded = EPUBJS.core.request(url, 'xml', false);
|
||||
loaded.then(function(contents){
|
||||
chapter.contents = contents;
|
||||
|
@ -3507,6 +3508,8 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}, function(error){
|
||||
deferred.reject(error);
|
||||
});
|
||||
*/
|
||||
deferred.resolve(url);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
@ -3524,7 +3527,7 @@ EPUBJS.Chapter.prototype.getID = function(){
|
|||
};
|
||||
|
||||
EPUBJS.Chapter.prototype.unload = function(store){
|
||||
|
||||
this.contents = null;
|
||||
if(this.tempUrl && store) {
|
||||
store.revokeUrl(this.tempUrl);
|
||||
this.tempUrl = false;
|
||||
|
@ -5470,8 +5473,7 @@ EPUBJS.Render.Iframe.prototype.load = function(url){
|
|||
var render = this,
|
||||
deferred = new RSVP.defer();
|
||||
|
||||
this.iframe.src = url;
|
||||
|
||||
this.iframe.contentWindow.location.replace(url);
|
||||
// Reset the scroll position
|
||||
render.leftPos = 0;
|
||||
|
||||
|
@ -5755,11 +5757,14 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
|||
this.removeEventListeners();
|
||||
this.removeSelectionListeners();
|
||||
this.trigger("renderer:chapterUnloaded");
|
||||
this.contents = null;
|
||||
this.doc = null;
|
||||
this.pageMap = null;
|
||||
}
|
||||
|
||||
this.currentChapter = chapter;
|
||||
this.chapterPos = 1;
|
||||
|
||||
this.pageMap = null;
|
||||
this.currentChapterCfiBase = chapter.cfiBase;
|
||||
|
||||
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||
|
@ -5789,7 +5794,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
|||
|
||||
render.then(function(contents) {
|
||||
var formated;
|
||||
|
||||
this.currentChapter.contents = this.render.document;
|
||||
this.contents = contents;
|
||||
this.doc = this.render.document;
|
||||
|
||||
|
@ -6137,8 +6142,7 @@ EPUBJS.Renderer.prototype.containsPoint = function(el, x, y){
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
EPUBJS.Renderer.prototype.textSprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: function (node) {
|
||||
if ( ! /^\s*$/.test(node.data) ) {
|
||||
|
@ -6148,13 +6152,21 @@ EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
|||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, false, false);
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.mapPage = function(){
|
||||
var renderer = this;
|
||||
|
@ -6163,21 +6175,42 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
var page = 1;
|
||||
var width = this.layout.colWidth + this.layout.gap;
|
||||
var offset = this.formated.pageWidth * (this.chapterPos-1);
|
||||
var limit = (width * page) - offset;
|
||||
var limit = (width * page) - offset;// (width * page) - offset;
|
||||
var elLimit = 0;
|
||||
var prevRange;
|
||||
var cfi;
|
||||
var check = function(node) {
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
var elPos;
|
||||
var children = Array.prototype.slice.call(node.childNodes);
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
elPos = node.getBoundingClientRect();
|
||||
if(elPos.left + elPos.width > elLimit) {
|
||||
|
||||
// console.log("checking text node of: ", node);
|
||||
children.forEach(function(node){
|
||||
if(node.nodeType == Node.TEXT_NODE &&
|
||||
node.textContent.trim().length) {
|
||||
checkText(node);
|
||||
}
|
||||
});
|
||||
// renderer.textSprint(node, checkText);
|
||||
}
|
||||
}
|
||||
|
||||
// if (node.nodeType != Node.TEXT_NODE) {
|
||||
// renderer.handleTextNode(node, map, prevRange, limit, cfi);
|
||||
// }
|
||||
};
|
||||
var checkText = function(node){
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
ranges.forEach(function(range){
|
||||
var pos = renderer.rangePosition(range);
|
||||
|
||||
var pos = range.getBoundingClientRect();
|
||||
// console.log(pos.left, pos.top, node);
|
||||
|
||||
if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(pos.left + pos.width < limit) {
|
||||
if(!map[page-1].start){
|
||||
range.collapse(true);
|
||||
|
@ -6199,17 +6232,21 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
});
|
||||
page += 1;
|
||||
limit = (width * page) - offset;
|
||||
elLimit = limit;
|
||||
}
|
||||
|
||||
prevRange = range;
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.sprint(root, check);
|
||||
// this.textSprint(root, checkText);
|
||||
|
||||
if(prevRange){
|
||||
prevRange.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||
map[page-1].end = cfi;
|
||||
}
|
||||
|
@ -6219,21 +6256,27 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
range = this.doc.createRange();
|
||||
range.selectNodeContents(root);
|
||||
range.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||
map[0].start = cfi;
|
||||
map[0].end = cfi;
|
||||
}
|
||||
|
||||
// clean up
|
||||
prevRange = null;
|
||||
ranges = null;
|
||||
range = null;
|
||||
root = null;
|
||||
return map;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||
var ranges = [];
|
||||
var text = node.textContent;
|
||||
var text = node.textContent.trim();
|
||||
var range;
|
||||
var rect;
|
||||
var list;
|
||||
|
||||
pos = text.indexOf(" ");
|
||||
|
||||
if(pos === -1) {
|
||||
|
@ -6243,20 +6286,30 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
|||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
range = false;
|
||||
|
||||
while ( pos != -1 ) {
|
||||
|
||||
pos = text.indexOf(" ", pos + 1);
|
||||
if(pos > 0) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
|
||||
if(range) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
}
|
||||
}
|
||||
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
if(range) {
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
return ranges;
|
||||
};
|
||||
|
|
File diff suppressed because one or more lines are too long
6
build/epub.min.js
vendored
6
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2623,7 +2623,6 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
"page" : currentPage
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
if(pager.pageMap.length % 2 > 0 &&
|
||||
|
@ -2636,7 +2635,9 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
}
|
||||
|
||||
// Load up the next chapter
|
||||
nextChapter(done);
|
||||
setTimeout(function(){
|
||||
nextChapter(done);
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
return done.promise;
|
||||
|
@ -3498,7 +3499,7 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}else{
|
||||
url = this.absolute;
|
||||
}
|
||||
|
||||
/*
|
||||
loaded = EPUBJS.core.request(url, 'xml', false);
|
||||
loaded.then(function(contents){
|
||||
chapter.contents = contents;
|
||||
|
@ -3506,6 +3507,8 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}, function(error){
|
||||
deferred.reject(error);
|
||||
});
|
||||
*/
|
||||
deferred.resolve(url);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
@ -3523,7 +3526,7 @@ EPUBJS.Chapter.prototype.getID = function(){
|
|||
};
|
||||
|
||||
EPUBJS.Chapter.prototype.unload = function(store){
|
||||
|
||||
this.contents = null;
|
||||
if(this.tempUrl && store) {
|
||||
store.revokeUrl(this.tempUrl);
|
||||
this.tempUrl = false;
|
||||
|
@ -5469,8 +5472,7 @@ EPUBJS.Render.Iframe.prototype.load = function(url){
|
|||
var render = this,
|
||||
deferred = new RSVP.defer();
|
||||
|
||||
this.iframe.src = url;
|
||||
|
||||
this.iframe.contentWindow.location.replace(url);
|
||||
// Reset the scroll position
|
||||
render.leftPos = 0;
|
||||
|
||||
|
@ -5754,11 +5756,14 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
|||
this.removeEventListeners();
|
||||
this.removeSelectionListeners();
|
||||
this.trigger("renderer:chapterUnloaded");
|
||||
this.contents = null;
|
||||
this.doc = null;
|
||||
this.pageMap = null;
|
||||
}
|
||||
|
||||
this.currentChapter = chapter;
|
||||
this.chapterPos = 1;
|
||||
|
||||
this.pageMap = null;
|
||||
this.currentChapterCfiBase = chapter.cfiBase;
|
||||
|
||||
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||
|
@ -5788,7 +5793,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
|||
|
||||
render.then(function(contents) {
|
||||
var formated;
|
||||
|
||||
this.currentChapter.contents = this.render.document;
|
||||
this.contents = contents;
|
||||
this.doc = this.render.document;
|
||||
|
||||
|
@ -6136,8 +6141,7 @@ EPUBJS.Renderer.prototype.containsPoint = function(el, x, y){
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
EPUBJS.Renderer.prototype.textSprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: function (node) {
|
||||
if ( ! /^\s*$/.test(node.data) ) {
|
||||
|
@ -6147,13 +6151,21 @@ EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
|||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, false, false);
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.mapPage = function(){
|
||||
var renderer = this;
|
||||
|
@ -6162,21 +6174,42 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
var page = 1;
|
||||
var width = this.layout.colWidth + this.layout.gap;
|
||||
var offset = this.formated.pageWidth * (this.chapterPos-1);
|
||||
var limit = (width * page) - offset;
|
||||
var limit = (width * page) - offset;// (width * page) - offset;
|
||||
var elLimit = 0;
|
||||
var prevRange;
|
||||
var cfi;
|
||||
var check = function(node) {
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
var elPos;
|
||||
var children = Array.prototype.slice.call(node.childNodes);
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
elPos = node.getBoundingClientRect();
|
||||
if(elPos.left + elPos.width > elLimit) {
|
||||
|
||||
// console.log("checking text node of: ", node);
|
||||
children.forEach(function(node){
|
||||
if(node.nodeType == Node.TEXT_NODE &&
|
||||
node.textContent.trim().length) {
|
||||
checkText(node);
|
||||
}
|
||||
});
|
||||
// renderer.textSprint(node, checkText);
|
||||
}
|
||||
}
|
||||
|
||||
// if (node.nodeType != Node.TEXT_NODE) {
|
||||
// renderer.handleTextNode(node, map, prevRange, limit, cfi);
|
||||
// }
|
||||
};
|
||||
var checkText = function(node){
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
ranges.forEach(function(range){
|
||||
var pos = renderer.rangePosition(range);
|
||||
|
||||
var pos = range.getBoundingClientRect();
|
||||
// console.log(pos.left, pos.top, node);
|
||||
|
||||
if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(pos.left + pos.width < limit) {
|
||||
if(!map[page-1].start){
|
||||
range.collapse(true);
|
||||
|
@ -6198,17 +6231,21 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
});
|
||||
page += 1;
|
||||
limit = (width * page) - offset;
|
||||
elLimit = limit;
|
||||
}
|
||||
|
||||
prevRange = range;
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.sprint(root, check);
|
||||
// this.textSprint(root, checkText);
|
||||
|
||||
if(prevRange){
|
||||
prevRange.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||
map[page-1].end = cfi;
|
||||
}
|
||||
|
@ -6218,21 +6255,27 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
range = this.doc.createRange();
|
||||
range.selectNodeContents(root);
|
||||
range.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||
map[0].start = cfi;
|
||||
map[0].end = cfi;
|
||||
}
|
||||
|
||||
// clean up
|
||||
prevRange = null;
|
||||
ranges = null;
|
||||
range = null;
|
||||
root = null;
|
||||
return map;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||
var ranges = [];
|
||||
var text = node.textContent;
|
||||
var text = node.textContent.trim();
|
||||
var range;
|
||||
var rect;
|
||||
var list;
|
||||
|
||||
pos = text.indexOf(" ");
|
||||
|
||||
if(pos === -1) {
|
||||
|
@ -6242,20 +6285,30 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
|||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
range = false;
|
||||
|
||||
while ( pos != -1 ) {
|
||||
|
||||
pos = text.indexOf(" ", pos + 1);
|
||||
if(pos > 0) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
|
||||
if(range) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
}
|
||||
}
|
||||
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
if(range) {
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
return ranges;
|
||||
};
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
105
reader/js/epub.min.js
vendored
105
reader/js/epub.min.js
vendored
|
@ -2624,7 +2624,6 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
"page" : currentPage
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
if(pager.pageMap.length % 2 > 0 &&
|
||||
|
@ -2637,7 +2636,9 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
}
|
||||
|
||||
// Load up the next chapter
|
||||
nextChapter(done);
|
||||
setTimeout(function(){
|
||||
nextChapter(done);
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
return done.promise;
|
||||
|
@ -3499,7 +3500,7 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}else{
|
||||
url = this.absolute;
|
||||
}
|
||||
|
||||
/*
|
||||
loaded = EPUBJS.core.request(url, 'xml', false);
|
||||
loaded.then(function(contents){
|
||||
chapter.contents = contents;
|
||||
|
@ -3507,6 +3508,8 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}, function(error){
|
||||
deferred.reject(error);
|
||||
});
|
||||
*/
|
||||
deferred.resolve(url);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
@ -3524,7 +3527,7 @@ EPUBJS.Chapter.prototype.getID = function(){
|
|||
};
|
||||
|
||||
EPUBJS.Chapter.prototype.unload = function(store){
|
||||
|
||||
this.contents = null;
|
||||
if(this.tempUrl && store) {
|
||||
store.revokeUrl(this.tempUrl);
|
||||
this.tempUrl = false;
|
||||
|
@ -5470,8 +5473,7 @@ EPUBJS.Render.Iframe.prototype.load = function(url){
|
|||
var render = this,
|
||||
deferred = new RSVP.defer();
|
||||
|
||||
this.iframe.src = url;
|
||||
|
||||
this.iframe.contentWindow.location.replace(url);
|
||||
// Reset the scroll position
|
||||
render.leftPos = 0;
|
||||
|
||||
|
@ -5755,11 +5757,14 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
|||
this.removeEventListeners();
|
||||
this.removeSelectionListeners();
|
||||
this.trigger("renderer:chapterUnloaded");
|
||||
this.contents = null;
|
||||
this.doc = null;
|
||||
this.pageMap = null;
|
||||
}
|
||||
|
||||
this.currentChapter = chapter;
|
||||
this.chapterPos = 1;
|
||||
|
||||
this.pageMap = null;
|
||||
this.currentChapterCfiBase = chapter.cfiBase;
|
||||
|
||||
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||
|
@ -5789,7 +5794,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
|||
|
||||
render.then(function(contents) {
|
||||
var formated;
|
||||
|
||||
this.currentChapter.contents = this.render.document;
|
||||
this.contents = contents;
|
||||
this.doc = this.render.document;
|
||||
|
||||
|
@ -6137,8 +6142,7 @@ EPUBJS.Renderer.prototype.containsPoint = function(el, x, y){
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
EPUBJS.Renderer.prototype.textSprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: function (node) {
|
||||
if ( ! /^\s*$/.test(node.data) ) {
|
||||
|
@ -6148,13 +6152,21 @@ EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
|||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, false, false);
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.mapPage = function(){
|
||||
var renderer = this;
|
||||
|
@ -6163,21 +6175,42 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
var page = 1;
|
||||
var width = this.layout.colWidth + this.layout.gap;
|
||||
var offset = this.formated.pageWidth * (this.chapterPos-1);
|
||||
var limit = (width * page) - offset;
|
||||
var limit = (width * page) - offset;// (width * page) - offset;
|
||||
var elLimit = 0;
|
||||
var prevRange;
|
||||
var cfi;
|
||||
var check = function(node) {
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
var elPos;
|
||||
var children = Array.prototype.slice.call(node.childNodes);
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
elPos = node.getBoundingClientRect();
|
||||
if(elPos.left + elPos.width > elLimit) {
|
||||
|
||||
// console.log("checking text node of: ", node);
|
||||
children.forEach(function(node){
|
||||
if(node.nodeType == Node.TEXT_NODE &&
|
||||
node.textContent.trim().length) {
|
||||
checkText(node);
|
||||
}
|
||||
});
|
||||
// renderer.textSprint(node, checkText);
|
||||
}
|
||||
}
|
||||
|
||||
// if (node.nodeType != Node.TEXT_NODE) {
|
||||
// renderer.handleTextNode(node, map, prevRange, limit, cfi);
|
||||
// }
|
||||
};
|
||||
var checkText = function(node){
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
ranges.forEach(function(range){
|
||||
var pos = renderer.rangePosition(range);
|
||||
|
||||
var pos = range.getBoundingClientRect();
|
||||
// console.log(pos.left, pos.top, node);
|
||||
|
||||
if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(pos.left + pos.width < limit) {
|
||||
if(!map[page-1].start){
|
||||
range.collapse(true);
|
||||
|
@ -6199,17 +6232,21 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
});
|
||||
page += 1;
|
||||
limit = (width * page) - offset;
|
||||
elLimit = limit;
|
||||
}
|
||||
|
||||
prevRange = range;
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.sprint(root, check);
|
||||
// this.textSprint(root, checkText);
|
||||
|
||||
if(prevRange){
|
||||
prevRange.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||
map[page-1].end = cfi;
|
||||
}
|
||||
|
@ -6219,21 +6256,27 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
range = this.doc.createRange();
|
||||
range.selectNodeContents(root);
|
||||
range.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||
map[0].start = cfi;
|
||||
map[0].end = cfi;
|
||||
}
|
||||
|
||||
// clean up
|
||||
prevRange = null;
|
||||
ranges = null;
|
||||
range = null;
|
||||
root = null;
|
||||
return map;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||
var ranges = [];
|
||||
var text = node.textContent;
|
||||
var text = node.textContent.trim();
|
||||
var range;
|
||||
var rect;
|
||||
var list;
|
||||
|
||||
pos = text.indexOf(" ");
|
||||
|
||||
if(pos === -1) {
|
||||
|
@ -6243,20 +6286,30 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
|||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
range = false;
|
||||
|
||||
while ( pos != -1 ) {
|
||||
|
||||
pos = text.indexOf(" ", pos + 1);
|
||||
if(pos > 0) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
|
||||
if(range) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
}
|
||||
}
|
||||
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
if(range) {
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
return ranges;
|
||||
};
|
||||
|
|
|
@ -374,7 +374,6 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
"page" : currentPage
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
if(pager.pageMap.length % 2 > 0 &&
|
||||
|
@ -387,7 +386,9 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
}
|
||||
|
||||
// Load up the next chapter
|
||||
nextChapter(done);
|
||||
setTimeout(function(){
|
||||
nextChapter(done);
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
return done.promise;
|
||||
|
|
|
@ -39,7 +39,7 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}else{
|
||||
url = this.absolute;
|
||||
}
|
||||
|
||||
/*
|
||||
loaded = EPUBJS.core.request(url, 'xml', false);
|
||||
loaded.then(function(contents){
|
||||
chapter.contents = contents;
|
||||
|
@ -47,6 +47,8 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
}, function(error){
|
||||
deferred.reject(error);
|
||||
});
|
||||
*/
|
||||
deferred.resolve(url);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
@ -64,7 +66,7 @@ EPUBJS.Chapter.prototype.getID = function(){
|
|||
};
|
||||
|
||||
EPUBJS.Chapter.prototype.unload = function(store){
|
||||
|
||||
this.contents = null;
|
||||
if(this.tempUrl && store) {
|
||||
store.revokeUrl(this.tempUrl);
|
||||
this.tempUrl = false;
|
||||
|
|
|
@ -31,8 +31,7 @@ EPUBJS.Render.Iframe.prototype.load = function(url){
|
|||
var render = this,
|
||||
deferred = new RSVP.defer();
|
||||
|
||||
this.iframe.src = url;
|
||||
|
||||
this.iframe.contentWindow.location.replace(url);
|
||||
// Reset the scroll position
|
||||
render.leftPos = 0;
|
||||
|
||||
|
|
|
@ -102,11 +102,14 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
|||
this.removeEventListeners();
|
||||
this.removeSelectionListeners();
|
||||
this.trigger("renderer:chapterUnloaded");
|
||||
this.contents = null;
|
||||
this.doc = null;
|
||||
this.pageMap = null;
|
||||
}
|
||||
|
||||
this.currentChapter = chapter;
|
||||
this.chapterPos = 1;
|
||||
|
||||
this.pageMap = null;
|
||||
this.currentChapterCfiBase = chapter.cfiBase;
|
||||
|
||||
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||
|
@ -136,7 +139,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
|||
|
||||
render.then(function(contents) {
|
||||
var formated;
|
||||
|
||||
this.currentChapter.contents = this.render.document;
|
||||
this.contents = contents;
|
||||
this.doc = this.render.document;
|
||||
|
||||
|
@ -484,8 +487,7 @@ EPUBJS.Renderer.prototype.containsPoint = function(el, x, y){
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
EPUBJS.Renderer.prototype.textSprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: function (node) {
|
||||
if ( ! /^\s*$/.test(node.data) ) {
|
||||
|
@ -495,13 +497,21 @@ EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
|||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.sprint = function(root, func) {
|
||||
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, false, false);
|
||||
var node;
|
||||
while ((node = treeWalker.nextNode())) {
|
||||
func(node);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Renderer.prototype.mapPage = function(){
|
||||
var renderer = this;
|
||||
|
@ -510,21 +520,42 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
var page = 1;
|
||||
var width = this.layout.colWidth + this.layout.gap;
|
||||
var offset = this.formated.pageWidth * (this.chapterPos-1);
|
||||
var limit = (width * page) - offset;
|
||||
var limit = (width * page) - offset;// (width * page) - offset;
|
||||
var elLimit = 0;
|
||||
var prevRange;
|
||||
var cfi;
|
||||
var check = function(node) {
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
var elPos;
|
||||
var children = Array.prototype.slice.call(node.childNodes);
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
elPos = node.getBoundingClientRect();
|
||||
if(elPos.left + elPos.width > elLimit) {
|
||||
|
||||
// console.log("checking text node of: ", node);
|
||||
children.forEach(function(node){
|
||||
if(node.nodeType == Node.TEXT_NODE &&
|
||||
node.textContent.trim().length) {
|
||||
checkText(node);
|
||||
}
|
||||
});
|
||||
// renderer.textSprint(node, checkText);
|
||||
}
|
||||
}
|
||||
|
||||
// if (node.nodeType != Node.TEXT_NODE) {
|
||||
// renderer.handleTextNode(node, map, prevRange, limit, cfi);
|
||||
// }
|
||||
};
|
||||
var checkText = function(node){
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
ranges.forEach(function(range){
|
||||
var pos = renderer.rangePosition(range);
|
||||
|
||||
var pos = range.getBoundingClientRect();
|
||||
// console.log(pos.left, pos.top, node);
|
||||
|
||||
if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(pos.left + pos.width < limit) {
|
||||
if(!map[page-1].start){
|
||||
range.collapse(true);
|
||||
|
@ -546,17 +577,21 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
});
|
||||
page += 1;
|
||||
limit = (width * page) - offset;
|
||||
elLimit = limit;
|
||||
}
|
||||
|
||||
prevRange = range;
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.sprint(root, check);
|
||||
// this.textSprint(root, checkText);
|
||||
|
||||
if(prevRange){
|
||||
prevRange.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||
map[page-1].end = cfi;
|
||||
}
|
||||
|
@ -566,21 +601,27 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
range = this.doc.createRange();
|
||||
range.selectNodeContents(root);
|
||||
range.collapse(true);
|
||||
|
||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||
map[0].start = cfi;
|
||||
map[0].end = cfi;
|
||||
}
|
||||
|
||||
// clean up
|
||||
prevRange = null;
|
||||
ranges = null;
|
||||
range = null;
|
||||
root = null;
|
||||
return map;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||
var ranges = [];
|
||||
var text = node.textContent;
|
||||
var text = node.textContent.trim();
|
||||
var range;
|
||||
var rect;
|
||||
var list;
|
||||
|
||||
pos = text.indexOf(" ");
|
||||
|
||||
if(pos === -1) {
|
||||
|
@ -590,20 +631,30 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
|||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
range = false;
|
||||
|
||||
while ( pos != -1 ) {
|
||||
|
||||
pos = text.indexOf(" ", pos + 1);
|
||||
if(pos > 0) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
|
||||
if(range) {
|
||||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
}
|
||||
}
|
||||
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
if(range) {
|
||||
range.setEnd(node, text.length);
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
return ranges;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue