EPUB CFI: at_current() works

This commit is contained in:
Kovid Goyal 2012-01-25 13:02:40 +05:30
parent bc4ff3e011
commit df246b0979
3 changed files with 38 additions and 25 deletions

View File

@ -579,11 +579,12 @@ class CanonicalFragmentIdentifier
get_cfi = (ox, oy) ->
try
cfi = this.at(ox, oy)
point = this.point(cfi)
cfi = window.cfi.at(ox, oy)
point = window.cfi.point(cfi)
catch err
cfi = null
if cfi
if point.range != null
r = point.range
rect = r.getClientRects()[0]

View File

@ -30,18 +30,23 @@ window_ypos = (pos=null) ->
window.scrollTo(0, pos)
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
x = evt.clientX
y = evt.clientY
if evt.button == 2
return # Right mouse click, generated only in firefox
reset = document.getElementById('reset')
if document.elementFromPoint(x, y) == reset
if document.elementFromPoint(x, y)?.getAttribute('id') in ['reset', 'viewport_mode']
return
# 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")
if ms
ms.parentNode?.removeChild(ms)
ms.style.display = 'none'
if document.getElementById('viewport_mode').checked
cfi = window.cfi.at_current()
window.cfi.scroll_to(cfi)
return
fn = () ->
try

View File

@ -8,6 +8,7 @@
body {
font-family: sans-serif;
background-color: white;
padding-bottom: 500px;
}
h1, h2 { color: #005a9c }
@ -48,7 +49,13 @@
<div id="container">
<h1 id="first-h1">Testing cfi.coffee</h1>
<p>Click anywhere and the location will be marked with a marker, whose position is set via a CFI.</p>
<p><a id="reset" href="/">Reset CFI to None</a></p>
<p>
<a id="reset" href="/">Reset CFI to None</a>
&nbsp;
Test viewport location calculation:
<input type="checkbox" id="viewport_mode" title=
"Checking this will cause the window to scroll to a position based on a CFI calculated for the windows current position."/>
</p>
<h2>A div with scrollbars</h2>
<p>Scroll down and click on some elements. Make sure to hit both
bold and not bold text as well as different points on the image</p>