diff --git a/src/calibre/ebooks/oeb/display/cfi.coffee b/src/calibre/ebooks/oeb/display/cfi.coffee index 511f8fa300..7afaf5523d 100644 --- a/src/calibre/ebooks/oeb/display/cfi.coffee +++ b/src/calibre/ebooks/oeb/display/cfi.coffee @@ -69,14 +69,15 @@ get_current_time = (target) -> # {{{ viewport_to_document = (x, y, doc) -> # {{{ win = doc.defaultView - x += win.scrollX - y += win.scrollY + x += if win.scrollX then win.scrollX else 0 + y += if win.scrollY then win.scrollY else 0 + if doc != window.document # We are in a frame node = win.frameElement rect = node.getBoundingClientRect() return viewport_to_document(rect.left, rect.top, node.ownerDocument) - return [x + win.scrollX, y + win.scrollY] + return [x, y] # }}} # Equivalent for caretRangeFromPoint for non WebKit browsers {{{ @@ -146,6 +147,15 @@ class CanonicalFragmentIdentifier constructor: () -> # {{{ this.CREATE_RANGE_ERR = "Your browser does not support the createRange function. Update it to a newer version." this.IE_ERR = "Your browser is too old. You need Internet Explorer version 8 or newer." + div = document.createElement('div') + ver = 3 + while true + div.innerHTML = "" + if div.getElementsByTagName('i').length == 0 + break + this.iever = ver + this.isie = ver > 4 + # }}} is_compatible: () -> # {{{ @@ -153,13 +163,7 @@ class CanonicalFragmentIdentifier throw this.CREATE_RANGE_ERR # Check if Internet Explorer >= 8 as getClientRects returns physical # rather than logical pixels on older IE - div = document.createElement('div') - ver = 3 - while true - div.innerHTML = "" - if div.getElementsByTagName('i').length == 0 - break - if ver > 4 and ver < 8 + if this.isie and this.iever < 8 # We have IE < 8 throw this.IE_ERR # }}} diff --git a/src/calibre/ebooks/oeb/display/test/cfi-test.coffee b/src/calibre/ebooks/oeb/display/test/cfi-test.coffee index ab82c32df4..d3af7fde8d 100644 --- a/src/calibre/ebooks/oeb/display/test/cfi-test.coffee +++ b/src/calibre/ebooks/oeb/display/test/cfi-test.coffee @@ -28,7 +28,7 @@ mark_and_reload = (evt) -> # Remove image in case the click was on the image itself, we want the cfi to # be on the underlying element ms = document.getElementById("marker") - ms.parentNode.removeChild(ms) + ms.parentNode?.removeChild(ms) fn = () -> window.current_cfi = window.cfi.at(evt.clientX, evt.clientY)