diff --git a/src/calibre/ebooks/oeb/display/test-cfi/cfi-test.coffee b/src/calibre/ebooks/oeb/display/test-cfi/cfi-test.coffee index 508ab111f4..3a91600045 100644 --- a/src/calibre/ebooks/oeb/display/test-cfi/cfi-test.coffee +++ b/src/calibre/ebooks/oeb/display/test-cfi/cfi-test.coffee @@ -24,6 +24,11 @@ show_cfi = () -> window.cfi.scroll_to(window.current_cfi, fn) null +window_ypos = (pos=null) -> + if pos == null + return window.pageYOffset + 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 @@ -35,11 +40,12 @@ mark_and_reload = (evt) -> try window.current_cfi = window.cfi.at(evt.clientX, evt.clientY) catch err - log("Failed to calculate cfi: #{ err }") + alert("Failed to calculate cfi: #{ err }") return if window.current_cfi - epubcfi = "#epubcfi(#{ window.current_cfi })" - newloc = window.location.href.replace(/#.*$/, '') + epubcfi + epubcfi = "epubcfi(#{ window.current_cfi })" + ypos = window_ypos() + newloc = window.location.href.replace(/#.*$/, '') + "#" + ypos + epubcfi window.location.replace(newloc) document.getElementById('current-cfi').innerHTML = window.current_cfi window.location.reload() @@ -54,10 +60,14 @@ window.onload = -> alert(error) return document.onclick = mark_and_reload - r = location.hash.match(/#epubcfi\((.+)\)$/) + r = location.hash.match(/#(\d*)epubcfi\((.+)\)$/) if r - window.current_cfi = r[1] + window.current_cfi = r[2] + ypos = if r[1] then 0+r[1] else 0 document.getElementById('current-cfi').innerHTML = window.current_cfi - setTimeout(show_cfi, 100) + fn = () -> + show_cfi() + window_ypos(ypos) + setTimeout(fn, 100) null diff --git a/src/calibre/ebooks/oeb/display/test-cfi/index.html b/src/calibre/ebooks/oeb/display/test-cfi/index.html index cde2715ea4..eb1429d196 100644 --- a/src/calibre/ebooks/oeb/display/test-cfi/index.html +++ b/src/calibre/ebooks/oeb/display/test-cfi/index.html @@ -2,7 +2,6 @@