Fix popup footnotes not working in viewer

This commit is contained in:
Kovid Goyal 2019-08-08 23:18:03 +05:30
parent 45fa8525ba
commit 332f1e7e63
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 5 deletions

View File

@ -58,13 +58,14 @@ class Messenger:
class IframeWrapper:
def __init__(self, handlers, iframe, entry_point, bootstrap_text):
def __init__(self, handlers, iframe, entry_point, bootstrap_text, srcdoc):
self.messenger = Messenger()
self.iframe_id = ensure_id(iframe, 'content-iframe')
self.needs_init = True
self.ready = False
self.encrypted_communications = False
self.srcdoc_created = False
self.constructor_srcdoc = srcdoc
self.entry_point = entry_point
self.bootstrap_text = bootstrap_text
self.handlers = {k: handlers[k] for k in handlers}
@ -90,7 +91,7 @@ class IframeWrapper:
}
self.iframe.srcdoc = LOADING_DOC.replace(r, def(match, field): return data[field];)
else:
self.iframe.srcdoc = '<div>\xa0</div>'
self.iframe.srcdoc = self.constructor_srcdoc or '<div>\xa0</div>'
self.srcdoc_created = True
def init(self):

View File

@ -7,6 +7,7 @@ from gettext import gettext as _
from dom import add_extra_css, build_rule, clear, svgicon
from iframe_comm import IframeWrapper
from read_book.globals import runtime
from read_book.resources import load_resources
CLASS_NAME = 'book-content-popup-container'
@ -56,7 +57,10 @@ class ContentPopupOverlay:
'error': self.view.on_iframe_error,
'content_loaded': self.on_content_loaded,
}
self.iframe_wrapper = IframeWrapper(handlers, iframe, 'read_book.footnotes', _('Loading data, please wait...'))
entry_point = None if runtime.is_standalone_viewer else 'read_book.footnotes'
self.iframe_wrapper = IframeWrapper(
handlers, iframe, entry_point, _('Loading data, please wait...'),
'<div id="calibre-viewer-footnote-iframe">\xa0</div>')
self.pending_load = None
@property
@ -106,7 +110,7 @@ class ContentPopupOverlay:
def cb(resource_data):
self.loaded_resources = resource_data
done_callback(resource_data)
load_resources(self.view.ui.db, self.view.book, name, self.loaded_resources, cb)
load_resources(self.view.book, name, self.loaded_resources, cb)
def show_footnote(self, data):
self.current_footnote_data = data

View File

@ -17,6 +17,7 @@ from read_book.db import new_book
from read_book.globals import runtime, ui_operations
from read_book.iframe import main as iframe_main
from read_book.view import View
from read_book.footnotes import main as footnotes_main
from session import session_defaults
from utils import encode_query_with_path
from viewer.constants import FAKE_HOST, FAKE_PROTOCOL
@ -250,5 +251,9 @@ if window is window.top:
set_css(document.body, background_color=get_color('window-background'), color=get_color('window-foreground'))
else:
# iframe
iframe_main()
div = document.getElementById('calibre-viewer-footnote-iframe')
if div:
footnotes_main()
else:
iframe_main()
window.calibre_translations_data = v'undefined'