Fix loading of non-virtualized resources when html files are not in the book root

This commit is contained in:
Kovid Goyal 2019-10-16 06:16:33 +05:30
parent ac036ccf1b
commit 7ca139a210
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 3 deletions

View File

@ -201,7 +201,7 @@ class PopupIframeBoss:
window.URL.revokeObjectURL(self.blob_url_map[name])
document.body.style.removeProperty('font-family')
root_data, self.mathjax, self.blob_url_map = finalize_resources(self.book, data.name, data.resource_data)
self.resource_urls = unserialize_html(root_data, self.content_loaded, self.show_only_footnote)
self.resource_urls = unserialize_html(root_data, self.content_loaded, self.show_only_footnote, data.name)
def on_clear(self, data):
clear(document.head)

View File

@ -175,7 +175,7 @@ class IframeBoss:
window.URL.revokeObjectURL(self.blob_url_map[name])
document.body.style.removeProperty('font-family')
root_data, self.mathjax, self.blob_url_map = finalize_resources(self.book, data.name, data.resource_data)
self.resource_urls = unserialize_html(root_data, self.content_loaded)
self.resource_urls = unserialize_html(root_data, self.content_loaded, None, data.name)
def on_scroll_to_frac(self, data):
self.to_scroll_fraction(data.frac)

View File

@ -225,7 +225,7 @@ def process_stack(stack, tag_map, ns_map, load_required, onload, resource_urls):
for v'var i = node.length - 1; i >= 1; i--': # noqa: unused-local
stack.push(v'[node[i], elem]')
def unserialize_html(serialized_data, proceed, postprocess_dom):
def unserialize_html(serialized_data, proceed, postprocess_dom, root_name):
nonlocal hide_tooltips
tag_map = serialized_data.tag_map
tree = serialized_data.tree
@ -241,6 +241,13 @@ def unserialize_html(serialized_data, proceed, postprocess_dom):
document.head.appendChild(
E.style(type='text/css', 'html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important }')
)
if runtime.is_standalone_viewer and root_name:
if root_name.indexOf('/') > -1:
base = window.location.pathname.rpartition('/')[0]
base = f'{window.location.protocol}//{window.location.hostname}{base}/' + root_name
document.head.appendChild(E.base(href=base))
# Default stylesheet
if not runtime.is_standalone_viewer:
# for the standalone viewer the default font family is set