mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Fix for webkit not supporting position of collapsed ranges
This commit is contained in:
parent
f3a2f21fb3
commit
6313bb09d0
4 changed files with 35 additions and 11 deletions
|
@ -218,7 +218,7 @@
|
|||
<i class="material-icons">menu</i>
|
||||
</a>
|
||||
<div id="viewer" class="spreads"></div>
|
||||
<span id="hiddenTitle"></span>
|
||||
<span id="hiddenTitle"></span>g
|
||||
<a id="prev" href="#prev" class="arrow">
|
||||
<i class="material-icons">chevron_left</i>
|
||||
</a>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "epubjs",
|
||||
"version": "0.3.49",
|
||||
"version": "0.3.50",
|
||||
"description": "Parse and Render Epubs",
|
||||
"main": "lib/index.js",
|
||||
"module": "src/index.js",
|
||||
|
|
|
@ -8,6 +8,11 @@ import { Pane, Highlight, Underline } from "marks-pane";
|
|||
// Dom events to listen for
|
||||
const EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart"];
|
||||
|
||||
const isWebkit = /AppleWebKit/.test(navigator.userAgent);
|
||||
|
||||
const ELEMENT_NODE = 1;
|
||||
const TEXT_NODE = 3;
|
||||
|
||||
class Contents {
|
||||
constructor(doc, content, cfiBase, sectionIndex) {
|
||||
// Blank Cfi for Parsing
|
||||
|
@ -455,12 +460,26 @@ class Contents {
|
|||
} else {
|
||||
// Webkit does not handle collapsed range bounds correctly
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=138949
|
||||
if (range.collapsed) {
|
||||
position = range.getClientRects()[0];
|
||||
|
||||
// Construct a new non-collapsed range
|
||||
if (isWebkit) {
|
||||
let container = range.startContainer;
|
||||
let newRange = new Range();
|
||||
|
||||
if (container.nodeType === ELEMENT_NODE) {
|
||||
position = container.getBoundingClientRect();
|
||||
} else if (container.length + 2 < range.startOffset) {
|
||||
newRange.setStart(container, range.startOffset);
|
||||
newRange.setEnd(container, range.startOffset + 2);
|
||||
position = newRange.getBoundingClientRect();
|
||||
} else {
|
||||
newRange.setStart(container, range.startOffset - 2);
|
||||
newRange.setEnd(container, range.startOffset);
|
||||
position = newRange.getBoundingClientRect();
|
||||
}
|
||||
} else {
|
||||
position = range.getBoundingClientRect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,11 +124,14 @@ class DefaultViewManager {
|
|||
|
||||
this.removeEventListeners();
|
||||
|
||||
if (this.views) {
|
||||
this.views.each(function(view){
|
||||
if (view) {
|
||||
view.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.stage.destroy();
|
||||
|
||||
|
@ -295,7 +298,6 @@ class DefaultViewManager {
|
|||
distX = this.container.scrollWidth - this.layout.delta;
|
||||
}
|
||||
}
|
||||
|
||||
this.scrollTo(distX, distY, true);
|
||||
}
|
||||
|
||||
|
@ -760,6 +762,9 @@ class DefaultViewManager {
|
|||
|
||||
getContents(){
|
||||
var contents = [];
|
||||
if (!this.views) {
|
||||
return contents;
|
||||
}
|
||||
this.views.each(function(view){
|
||||
const viewContents = view && view.contents;
|
||||
if (viewContents) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue