diff --git a/src/calibre/ebooks/oeb/display/cfi.coffee b/src/calibre/ebooks/oeb/display/cfi.coffee index 076277eaed..29815c8f77 100644 --- a/src/calibre/ebooks/oeb/display/cfi.coffee +++ b/src/calibre/ebooks/oeb/display/cfi.coffee @@ -4,9 +4,11 @@ ### Copyright 2011, Kovid Goyal 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) -> # {{{ @@ -118,11 +120,24 @@ class CanonicalFragmentIdentifier # object 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: () -> 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 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) -> # {{{ if target.currentTime == undefined @@ -353,7 +368,7 @@ class CanonicalFragmentIdentifier else if cdoc.createRange [target, offset] = find_offset_for_point(x, y, target, cdoc) else - throw this.COMPAT_ERR + throw this.CREATE_RANGE_ERR this.encode(doc, target, offset, tail) # }}} @@ -375,7 +390,7 @@ class CanonicalFragmentIdentifier if typeof(r.offset) == "number" # Character offset if not ndoc.createRange - throw this.COMPAT_ERR + throw this.CREATE_RANGE_ERR range = ndoc.createRange() if r.forward try_list = [{start:0, end:0, a:0.5}, {start:0, end:1, a:1}, {start:-1, end:0, a:0}] diff --git a/src/calibre/ebooks/oeb/display/test/cfi-test.coffee b/src/calibre/ebooks/oeb/display/test/cfi-test.coffee index e371bab4df..5c3bb6ee16 100644 --- a/src/calibre/ebooks/oeb/display/test/cfi-test.coffee +++ b/src/calibre/ebooks/oeb/display/test/cfi-test.coffee @@ -22,18 +22,18 @@ viewport_left = (node) -> show_cfi = (dont_seek) -> if window.current_cfi pos = window.cfi.point(window.current_cfi) - ms = document.getElementById("marker").style if pos - ms.visibility = "visible" - ms.top = (pos.y - 30) + window.scrollY + "px" - ms.left = (pos.x - 1) + window.scrollX + "px" + ms = $("#marker") + ms.offset({left:pos.x-1, top:pos.y-30}) + ms.css('visibility', 'visible') if not dont_seek if typeof pos.time == "number" window.cfi.set_current_time(pos.node, pos.time) scrollTo(0, pos.y - 30) null -RELOAD = true +# Set this to true to have the browser reload the page with the current cfi +RELOAD = false mark_and_reload = (evt) -> window.current_cfi = window.cfi.at(evt.clientX, evt.clientY) diff --git a/src/calibre/utils/coffeescript.py b/src/calibre/utils/coffeescript.py index 13db6011f0..057cfeef17 100644 --- a/src/calibre/utils/coffeescript.py +++ b/src/calibre/utils/coffeescript.py @@ -70,7 +70,7 @@ class HTTPD(SocketServer.TCPServer): def serve(resources={}, port=8000): Handler.special_resources = resources - httpd = HTTPD(('localhost', port), Handler) + httpd = HTTPD(('0.0.0.0', port), Handler) print('serving at localhost:%d'%port) try: httpd.serve_forever()