mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pass the MathJax files into the iframe
This commit is contained in:
parent
edb11dbd28
commit
eeb8212f13
@ -186,10 +186,28 @@ class DB:
|
||||
fdata = book.stored_files[key]
|
||||
mt = fdata.mimetype or 'application/octet-stream'
|
||||
if fdata.encoded:
|
||||
result = Blob([base64decode(fdata)], {'type':mt})
|
||||
result = Blob([base64decode(result)], {'type':mt})
|
||||
proceed(result, name, mt, book)
|
||||
)
|
||||
|
||||
def get_mathjax_files(self, proceed):
|
||||
c = self.idb.transaction('mathjax').objectStore('mathjax').openCursor()
|
||||
c.onerror = def(event):
|
||||
err = _('Failed to read the MathJax files from local storage')
|
||||
self.display_error(err, event)
|
||||
data = {}
|
||||
c.onsuccess = def(event):
|
||||
cursor = event.target.result
|
||||
if cursor:
|
||||
name, result = cursor.key, cursor.value
|
||||
if not isinstance(result, Blob):
|
||||
mt = 'application/x-font-woff' if name.endswith('.woff') else 'text/javascript'
|
||||
result = Blob([base64decode(result)], {'type':mt})
|
||||
data[name] = result
|
||||
cursor.continue()
|
||||
else:
|
||||
proceed(data)
|
||||
|
||||
def create_db(ui, interface_data):
|
||||
if not window.indexedDB:
|
||||
return ui.db_initialized(_('Your browser does not support IndexedDB. Cannot read books. Consider using a modern browser, such as Firefox, Chrome or Edge.'))
|
||||
|
@ -6,6 +6,7 @@ import traceback
|
||||
from aes import GCM
|
||||
from gettext import install, gettext as _
|
||||
from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item, set_layout_mode
|
||||
from read_book.mathjax import apply_mathjax
|
||||
from read_book.resources import finalize_resources, unserialize_html
|
||||
from read_book.flow_mode import flow_to_scroll_fraction, flow_onwheel, flow_onkeydown, layout as flow_layout
|
||||
from read_book.paged_mode import layout as paged_layout, scroll_to_fraction as paged_scroll_to_fraction, onwheel as paged_onwheel, onkeydown as paged_onkeydown, scroll_to_elem
|
||||
@ -89,10 +90,14 @@ class Boss:
|
||||
self.to_scroll_fraction = paged_scroll_to_fraction
|
||||
apply_settings(data.settings)
|
||||
set_current_spine_item({'name':data.name, 'is_first':index is 0, 'is_last':index is spine.length - 1, 'initial_position':data.initial_position})
|
||||
root_data = finalize_resources(self.book, data.name, data.resource_data)
|
||||
root_data, self.mathjax = finalize_resources(self.book, data.name, data.resource_data)
|
||||
unserialize_html(root_data, self.content_loaded)
|
||||
|
||||
def content_loaded(self):
|
||||
if self.mathjax:
|
||||
mj = self.mathjax
|
||||
self.mathjax = None
|
||||
return apply_mathjax(mj, self.content_loaded)
|
||||
self.connect_links()
|
||||
document.documentElement.style.overflow = 'hidden'
|
||||
window.addEventListener('scroll', debounce(self.update_cfi, 1000))
|
||||
|
7
src/pyj/read_book/mathjax.pyj
Normal file
7
src/pyj/read_book/mathjax.pyj
Normal file
@ -0,0 +1,7 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __python__ import hash_literals
|
||||
|
||||
def apply_mathjax(mathjax_files):
|
||||
pass
|
||||
|
@ -26,6 +26,8 @@ def load_resources(db, book, root_name, previous_resources, proceed):
|
||||
if not pending_resources.length:
|
||||
for k in previous_resources:
|
||||
v'delete previous_resources[k]'
|
||||
if book.manifest.files[root_name].has_maths:
|
||||
return load_mathjax(db, book, ans, proceed)
|
||||
proceed(ans)
|
||||
return
|
||||
name = pending_resources.shift()
|
||||
@ -63,10 +65,26 @@ def load_resources(db, book, root_name, previous_resources, proceed):
|
||||
|
||||
do_one()
|
||||
|
||||
mathjax_data = None
|
||||
|
||||
def load_mathjax(db, book, resource_data, proceed):
|
||||
if mathjax_data is None:
|
||||
db.get_mathjax_files(def(data):
|
||||
nonlocal mathjax_data
|
||||
mathjax_data = data
|
||||
resource_data['..mathjax-files..'] = data
|
||||
proceed(resource_data)
|
||||
)
|
||||
else:
|
||||
resource_data['..mathjax-files..'] = mathjax_data
|
||||
proceed(resource_data)
|
||||
|
||||
def finalize_resources(book, root_name, resource_data):
|
||||
blob_url_map = Object.create(None)
|
||||
root_data = None
|
||||
link_pat = create_link_pat(book)
|
||||
mathjax = resource_data['..mathjax-files..']
|
||||
v'delete resource_data["..mathjax-files.."]'
|
||||
|
||||
# Resolve the non virtualized resources immediately
|
||||
for name in resource_data:
|
||||
@ -142,7 +160,7 @@ def finalize_resources(book, root_name, resource_data):
|
||||
for name in resolved:
|
||||
v'delete resource_data[name]'
|
||||
|
||||
return root_data
|
||||
return root_data, mathjax
|
||||
|
||||
js_types = set('text/javascript text/ecmascript application/javascript application/ecmascript'.split(' '))
|
||||
resource_tag_names = {'script':'src', 'link':'href', 'img':'src', 'image':'xlink:href'}
|
||||
|
Loading…
x
Reference in New Issue
Block a user