1
0
Fork 0
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:
Fred Chasen 2017-09-01 22:59:23 -04:00
parent f3a2f21fb3
commit 6313bb09d0
4 changed files with 35 additions and 11 deletions

View file

@ -218,7 +218,7 @@
<i class="material-icons">menu</i> <i class="material-icons">menu</i>
</a> </a>
<div id="viewer" class="spreads"></div> <div id="viewer" class="spreads"></div>
<span id="hiddenTitle"></span> <span id="hiddenTitle"></span>g
<a id="prev" href="#prev" class="arrow"> <a id="prev" href="#prev" class="arrow">
<i class="material-icons">chevron_left</i> <i class="material-icons">chevron_left</i>
</a> </a>

View file

@ -1,6 +1,6 @@
{ {
"name": "epubjs", "name": "epubjs",
"version": "0.3.49", "version": "0.3.50",
"description": "Parse and Render Epubs", "description": "Parse and Render Epubs",
"main": "lib/index.js", "main": "lib/index.js",
"module": "src/index.js", "module": "src/index.js",

View file

@ -8,6 +8,11 @@ import { Pane, Highlight, Underline } from "marks-pane";
// Dom events to listen for // Dom events to listen for
const EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart"]; 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 { class Contents {
constructor(doc, content, cfiBase, sectionIndex) { constructor(doc, content, cfiBase, sectionIndex) {
// Blank Cfi for Parsing // Blank Cfi for Parsing
@ -455,12 +460,26 @@ class Contents {
} else { } else {
// Webkit does not handle collapsed range bounds correctly // Webkit does not handle collapsed range bounds correctly
// https://bugs.webkit.org/show_bug.cgi?id=138949 // 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 { } else {
position = range.getBoundingClientRect(); position = range.getBoundingClientRect();
} }
} }
} }

View file

@ -124,11 +124,14 @@ class DefaultViewManager {
this.removeEventListeners(); this.removeEventListeners();
this.views.each(function(view){ if (this.views) {
if (view) { this.views.each(function(view){
view.destroy(); if (view) {
} view.destroy();
}); }
});
}
this.stage.destroy(); this.stage.destroy();
@ -295,7 +298,6 @@ class DefaultViewManager {
distX = this.container.scrollWidth - this.layout.delta; distX = this.container.scrollWidth - this.layout.delta;
} }
} }
this.scrollTo(distX, distY, true); this.scrollTo(distX, distY, true);
} }
@ -760,6 +762,9 @@ class DefaultViewManager {
getContents(){ getContents(){
var contents = []; var contents = [];
if (!this.views) {
return contents;
}
this.views.each(function(view){ this.views.each(function(view){
const viewContents = view && view.contents; const viewContents = view && view.contents;
if (viewContents) { if (viewContents) {