mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
EPUB CFI works on IE 9. That was easier than I thought :)
This commit is contained in:
parent
fd8e334e16
commit
e66b4323fd
@ -4,9 +4,11 @@
|
|||||||
###
|
###
|
||||||
Copyright 2011, Kovid Goyal <kovid@kovidgoyal.net>
|
Copyright 2011, Kovid Goyal <kovid@kovidgoyal.net>
|
||||||
Released under the GPLv3 License
|
Released under the GPLv3 License
|
||||||
Based on code originally written by Peter Sorotkin (http://code.google.com/p/epub-revision/source/browse/trunk/src/samples/cfi/epubcfi.js)
|
Based on code originally written by Peter Sorotkin
|
||||||
|
(http://code.google.com/p/epub-revision/source/browse/trunk/src/samples/cfi/epubcfi.js)
|
||||||
|
|
||||||
This script requires the createRange method on the document object that must create a W3C compliant range object
|
To check if this script is compatible with the current browser, call
|
||||||
|
window.cfi.is_compatible() it will throw an exception if not compatible.
|
||||||
###
|
###
|
||||||
|
|
||||||
log = (error) -> # {{{
|
log = (error) -> # {{{
|
||||||
@ -118,11 +120,24 @@ class CanonicalFragmentIdentifier
|
|||||||
# object
|
# object
|
||||||
|
|
||||||
constructor: () ->
|
constructor: () ->
|
||||||
this.COMPAT_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.is_compatible()
|
||||||
|
|
||||||
is_compatible: () ->
|
is_compatible: () ->
|
||||||
if not window.document.createRange
|
if not window.document.createRange
|
||||||
throw this.COMPAT_ERR
|
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 gt IE #{ ++ver }]><i></i><![endif]-->"
|
||||||
|
if div.getElementsByTagName('i').length == 0
|
||||||
|
break
|
||||||
|
if ver > 4 and ver < 8
|
||||||
|
# We have IE < 8
|
||||||
|
throw this.IE_ERR
|
||||||
|
|
||||||
set_current_time: (target, val) -> # {{{
|
set_current_time: (target, val) -> # {{{
|
||||||
if target.currentTime == undefined
|
if target.currentTime == undefined
|
||||||
@ -353,7 +368,7 @@ class CanonicalFragmentIdentifier
|
|||||||
else if cdoc.createRange
|
else if cdoc.createRange
|
||||||
[target, offset] = find_offset_for_point(x, y, target, cdoc)
|
[target, offset] = find_offset_for_point(x, y, target, cdoc)
|
||||||
else
|
else
|
||||||
throw this.COMPAT_ERR
|
throw this.CREATE_RANGE_ERR
|
||||||
|
|
||||||
this.encode(doc, target, offset, tail)
|
this.encode(doc, target, offset, tail)
|
||||||
# }}}
|
# }}}
|
||||||
@ -375,7 +390,7 @@ class CanonicalFragmentIdentifier
|
|||||||
if typeof(r.offset) == "number"
|
if typeof(r.offset) == "number"
|
||||||
# Character offset
|
# Character offset
|
||||||
if not ndoc.createRange
|
if not ndoc.createRange
|
||||||
throw this.COMPAT_ERR
|
throw this.CREATE_RANGE_ERR
|
||||||
range = ndoc.createRange()
|
range = ndoc.createRange()
|
||||||
if r.forward
|
if r.forward
|
||||||
try_list = [{start:0, end:0, a:0.5}, {start:0, end:1, a:1}, {start:-1, end:0, a:0}]
|
try_list = [{start:0, end:0, a:0.5}, {start:0, end:1, a:1}, {start:-1, end:0, a:0}]
|
||||||
|
@ -22,18 +22,18 @@ viewport_left = (node) ->
|
|||||||
show_cfi = (dont_seek) ->
|
show_cfi = (dont_seek) ->
|
||||||
if window.current_cfi
|
if window.current_cfi
|
||||||
pos = window.cfi.point(window.current_cfi)
|
pos = window.cfi.point(window.current_cfi)
|
||||||
ms = document.getElementById("marker").style
|
|
||||||
if pos
|
if pos
|
||||||
ms.visibility = "visible"
|
ms = $("#marker")
|
||||||
ms.top = (pos.y - 30) + window.scrollY + "px"
|
ms.offset({left:pos.x-1, top:pos.y-30})
|
||||||
ms.left = (pos.x - 1) + window.scrollX + "px"
|
ms.css('visibility', 'visible')
|
||||||
if not dont_seek
|
if not dont_seek
|
||||||
if typeof pos.time == "number"
|
if typeof pos.time == "number"
|
||||||
window.cfi.set_current_time(pos.node, pos.time)
|
window.cfi.set_current_time(pos.node, pos.time)
|
||||||
scrollTo(0, pos.y - 30)
|
scrollTo(0, pos.y - 30)
|
||||||
null
|
null
|
||||||
|
|
||||||
RELOAD = true
|
# Set this to true to have the browser reload the page with the current cfi
|
||||||
|
RELOAD = false
|
||||||
|
|
||||||
mark_and_reload = (evt) ->
|
mark_and_reload = (evt) ->
|
||||||
window.current_cfi = window.cfi.at(evt.clientX, evt.clientY)
|
window.current_cfi = window.cfi.at(evt.clientX, evt.clientY)
|
||||||
|
@ -70,7 +70,7 @@ class HTTPD(SocketServer.TCPServer):
|
|||||||
|
|
||||||
def serve(resources={}, port=8000):
|
def serve(resources={}, port=8000):
|
||||||
Handler.special_resources = resources
|
Handler.special_resources = resources
|
||||||
httpd = HTTPD(('localhost', port), Handler)
|
httpd = HTTPD(('0.0.0.0', port), Handler)
|
||||||
print('serving at localhost:%d'%port)
|
print('serving at localhost:%d'%port)
|
||||||
try:
|
try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user