This commit is contained in:
Kovid Goyal 2012-01-05 20:42:49 +05:30
parent c9601ae83b
commit 6c70624381
2 changed files with 15 additions and 11 deletions

View File

@ -69,14 +69,15 @@ get_current_time = (target) -> # {{{
viewport_to_document = (x, y, doc) -> # {{{ viewport_to_document = (x, y, doc) -> # {{{
win = doc.defaultView win = doc.defaultView
x += win.scrollX x += if win.scrollX then win.scrollX else 0
y += win.scrollY y += if win.scrollY then win.scrollY else 0
if doc != window.document if doc != window.document
# We are in a frame # We are in a frame
node = win.frameElement node = win.frameElement
rect = node.getBoundingClientRect() rect = node.getBoundingClientRect()
return viewport_to_document(rect.left, rect.top, node.ownerDocument) 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 {{{ # Equivalent for caretRangeFromPoint for non WebKit browsers {{{
@ -146,6 +147,15 @@ class CanonicalFragmentIdentifier
constructor: () -> # {{{ constructor: () -> # {{{
this.CREATE_RANGE_ERR = "Your browser does not support the createRange function. Update it to a newer version." 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." 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 gt IE #{ ++ver }]><i></i><![endif]-->"
if div.getElementsByTagName('i').length == 0
break
this.iever = ver
this.isie = ver > 4
# }}} # }}}
is_compatible: () -> # {{{ is_compatible: () -> # {{{
@ -153,13 +163,7 @@ class CanonicalFragmentIdentifier
throw this.CREATE_RANGE_ERR throw this.CREATE_RANGE_ERR
# Check if Internet Explorer >= 8 as getClientRects returns physical # Check if Internet Explorer >= 8 as getClientRects returns physical
# rather than logical pixels on older IE # rather than logical pixels on older IE
div = document.createElement('div') if this.isie and this.iever < 8
ver = 3
while true
div.innerHTML = "<!--[if gt IE #{ ++ver }]><i></i><![endif]-->"
if div.getElementsByTagName('i').length == 0
break
if ver > 4 and ver < 8
# We have IE < 8 # We have IE < 8
throw this.IE_ERR throw this.IE_ERR
# }}} # }}}

View File

@ -28,7 +28,7 @@ mark_and_reload = (evt) ->
# Remove image in case the click was on the image itself, we want the cfi to # Remove image in case the click was on the image itself, we want the cfi to
# be on the underlying element # be on the underlying element
ms = document.getElementById("marker") ms = document.getElementById("marker")
ms.parentNode.removeChild(ms) ms.parentNode?.removeChild(ms)
fn = () -> fn = () ->
window.current_cfi = window.cfi.at(evt.clientX, evt.clientY) window.current_cfi = window.cfi.at(evt.clientX, evt.clientY)