mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
a46f333d3e
commit
d64a760619
@ -398,8 +398,8 @@ class CanonicalFragmentIdentifier
|
|||||||
break
|
break
|
||||||
|
|
||||||
rect = target.getBoundingClientRect()
|
rect = target.getBoundingClientRect()
|
||||||
x = x - rect.x
|
x -= rect.left
|
||||||
y = y - rect.y
|
y -= rect.top
|
||||||
cdoc = cd
|
cdoc = cd
|
||||||
cwin = cdoc.defaultView
|
cwin = cdoc.defaultView
|
||||||
|
|
||||||
|
@ -32,10 +32,12 @@ window_ypos = (pos=null) ->
|
|||||||
mark_and_reload = (evt) ->
|
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
|
||||||
|
x = evt.clientX
|
||||||
|
y = evt.clientY
|
||||||
if evt.button == 2
|
if evt.button == 2
|
||||||
return # Right mouse click, generated only in firefox
|
return # Right mouse click, generated only in firefox
|
||||||
reset = document.getElementById('reset')
|
reset = document.getElementById('reset')
|
||||||
if document.elementFromPoint(evt.clientX, evt.clientY) == reset
|
if document.elementFromPoint(x, y) == reset
|
||||||
return
|
return
|
||||||
ms = document.getElementById("marker")
|
ms = document.getElementById("marker")
|
||||||
if ms
|
if ms
|
||||||
@ -43,7 +45,7 @@ mark_and_reload = (evt) ->
|
|||||||
|
|
||||||
fn = () ->
|
fn = () ->
|
||||||
try
|
try
|
||||||
window.current_cfi = window.cfi.at(evt.clientX, evt.clientY)
|
window.current_cfi = window.cfi.at(x, y)
|
||||||
catch err
|
catch err
|
||||||
alert("Failed to calculate cfi: #{ err }")
|
alert("Failed to calculate cfi: #{ err }")
|
||||||
return
|
return
|
||||||
@ -57,6 +59,28 @@ mark_and_reload = (evt) ->
|
|||||||
setTimeout(fn, 1)
|
setTimeout(fn, 1)
|
||||||
null
|
null
|
||||||
|
|
||||||
|
window_scroll_pos = (win) ->
|
||||||
|
if typeof(win.pageXOffset) == 'number'
|
||||||
|
x = win.pageXOffset
|
||||||
|
y = win.pageYOffset
|
||||||
|
else # IE < 9
|
||||||
|
if document.body and ( document.body.scrollLeft or document.body.scrollTop )
|
||||||
|
x = document.body.scrollLeft
|
||||||
|
y = document.body.scrollTop
|
||||||
|
else if document.documentElement and ( document.documentElement.scrollLeft or document.documentElement.scrollTop)
|
||||||
|
y = document.documentElement.scrollTop
|
||||||
|
x = document.documentElement.scrollLeft
|
||||||
|
return [x, y]
|
||||||
|
|
||||||
|
frame_clicked = (evt) ->
|
||||||
|
iframe = evt.target.ownerDocument.defaultView.frameElement
|
||||||
|
# We know that the offset parent of the iframe is body
|
||||||
|
# So we can easily calculate the event co-ords w.r.t. the browser window
|
||||||
|
[winx, winy] = window_scroll_pos(window)
|
||||||
|
x = evt.clientX + iframe.offsetLeft - winx
|
||||||
|
y = evt.clientY + iframe.offsetTop - winy
|
||||||
|
mark_and_reload({'clientX':x, 'clientY':y, 'button':evt.button})
|
||||||
|
|
||||||
window.onload = ->
|
window.onload = ->
|
||||||
try
|
try
|
||||||
window.cfi.is_compatible()
|
window.cfi.is_compatible()
|
||||||
@ -65,7 +89,7 @@ window.onload = ->
|
|||||||
return
|
return
|
||||||
document.onclick = mark_and_reload
|
document.onclick = mark_and_reload
|
||||||
for iframe in document.getElementsByTagName("iframe")
|
for iframe in document.getElementsByTagName("iframe")
|
||||||
iframe.contentWindow.document.onclick = mark_and_reload
|
iframe.contentWindow.document.onclick = frame_clicked
|
||||||
|
|
||||||
r = location.hash.match(/#(\d*)epubcfi\((.+)\)$/)
|
r = location.hash.match(/#(\d*)epubcfi\((.+)\)$/)
|
||||||
if r
|
if r
|
||||||
|
Loading…
x
Reference in New Issue
Block a user