mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
896c451aef
commit
99b5a75691
@ -4,7 +4,7 @@
|
||||
###
|
||||
Copyright 2011, Kovid Goyal <kovid@kovidgoyal.net>
|
||||
Released under the GPLv3 License
|
||||
Based on code originally written by Peter Sorotkin (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)
|
||||
###
|
||||
#
|
||||
log = (error) ->
|
||||
@ -51,6 +51,24 @@ fstr = (d) -> # {{{
|
||||
ans
|
||||
# }}}
|
||||
|
||||
get_current_time = (target) -> # {{{
|
||||
ans = 0
|
||||
if target.currentTime != undefined
|
||||
ans = target.currentTime
|
||||
fstr(ans)
|
||||
# }}}
|
||||
|
||||
set_current_time = (target, val) -> # {{{
|
||||
if target.currentTime == undefined
|
||||
return
|
||||
if target.readyState == 4 or target.readyState == "complete"
|
||||
target.currentTime = val
|
||||
else
|
||||
fn = -> target.currentTime = val
|
||||
target.addEventListener("canplay", fn, false)
|
||||
|
||||
#}}}
|
||||
|
||||
class CanonicalFragmentIdentifier
|
||||
|
||||
# This class is a namespace to expose CFI functions via the window.cfi
|
||||
@ -102,7 +120,8 @@ class CanonicalFragmentIdentifier
|
||||
|
||||
# Add id assertions for robustness where possible
|
||||
id = node.getAttribute?('id')
|
||||
idspec = if id then "[#{ escape_for_cfi(id) }]" else ''
|
||||
idok = id and id.match(/^[-a-zA-Z_0-9.\u007F-\uFFFF]+$/)
|
||||
idspec = if idok then "[#{ escape_for_cfi(id) }]" else ''
|
||||
cfi = '/' + index + idspec + cfi
|
||||
node = p
|
||||
|
||||
@ -117,7 +136,7 @@ class CanonicalFragmentIdentifier
|
||||
error = null
|
||||
node = doc
|
||||
|
||||
until cfi.length <= 0 or error
|
||||
until cfi.length < 1 or error
|
||||
if ( (r = cfi.match(simple_node_regex)) is not null ) # Path step
|
||||
target = parseInt(r[1])
|
||||
assertion = r[2]
|
||||
@ -253,7 +272,7 @@ class CanonicalFragmentIdentifier
|
||||
(if target.parentNode then target.parentNode else target).normalize()
|
||||
|
||||
if name in ['audio', 'video']
|
||||
tail = "~" + fstr target.currentTime
|
||||
tail = "~" + get_current_time(target)
|
||||
|
||||
if name in ['img', 'video']
|
||||
px = ((x + cwin.scrollX - target.offsetLeft)*100)/target.offsetWidth
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing CFI functionality</title>
|
||||
<script type="text/javascript" src="../cfi.coffee"></script>
|
||||
<script type="text/javascript" src="cfi.coffee"></script>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="cfi-test.coffee"></script>
|
||||
</head>
|
@ -16,10 +16,9 @@ except ImportError:
|
||||
if False: init_calibre, serve
|
||||
from calibre.utils.coffeescript import serve
|
||||
|
||||
|
||||
def run_devel_server():
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
serve()
|
||||
serve(resources={'/cfi.coffee':'../cfi.coffee'})
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_devel_server()
|
||||
|
@ -15,12 +15,15 @@ import time, SimpleHTTPServer, SocketServer, os, subprocess
|
||||
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
|
||||
generated_files = set()
|
||||
special_resources = {}
|
||||
|
||||
def translate_path(self, path):
|
||||
path = self.special_resources.get(path, path)
|
||||
if path.endswith('jquery.js'):
|
||||
return P('content_server/jquery.js')
|
||||
if path.endswith('.coffee'):
|
||||
return self.compile_coffeescript(path[1:])
|
||||
path = path[1:] if path.startswith('/') else path
|
||||
return self.compile_coffeescript(path)
|
||||
|
||||
return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self,
|
||||
path)
|
||||
@ -49,8 +52,12 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
f.write('alert("Compilation of %s failed");'%src)
|
||||
return dest
|
||||
|
||||
def serve(port=8000):
|
||||
httpd = SocketServer.TCPServer(('localhost', port), Handler)
|
||||
class HTTPD(SocketServer.TCPServer):
|
||||
allow_reuse_address = True
|
||||
|
||||
def serve(resources={}, port=8000):
|
||||
Handler.special_resources = resources
|
||||
httpd = HTTPD(('localhost', port), Handler)
|
||||
print('serving at localhost:%d'%port)
|
||||
try:
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user