mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get back and forward working in the standalone viewer
This commit is contained in:
parent
a4f1b54421
commit
1102216d9f
@ -20,7 +20,7 @@ from read_book.iframe import main as iframe_main
|
|||||||
from read_book.view import View
|
from read_book.view import View
|
||||||
from read_book.footnotes import main as footnotes_main
|
from read_book.footnotes import main as footnotes_main
|
||||||
from session import session_defaults
|
from session import session_defaults
|
||||||
from utils import encode_query_with_path
|
from utils import encode_query_with_path, parse_url_params
|
||||||
from viewer.constants import FAKE_HOST, FAKE_PROTOCOL
|
from viewer.constants import FAKE_HOST, FAKE_PROTOCOL
|
||||||
|
|
||||||
|
|
||||||
@ -118,7 +118,17 @@ def update_url_state(replace):
|
|||||||
if bookpos:
|
if bookpos:
|
||||||
query = {'bookpos': bookpos}
|
query = {'bookpos': bookpos}
|
||||||
query = encode_query_with_path(query)
|
query = encode_query_with_path(query)
|
||||||
window.history.pushState(None, '', query)
|
if replace:
|
||||||
|
window.history.replaceState(None, '', query)
|
||||||
|
else:
|
||||||
|
window.history.pushState(None, '', query)
|
||||||
|
|
||||||
|
|
||||||
|
def on_pop_state():
|
||||||
|
if view and view.currently_showing:
|
||||||
|
data = parse_url_params()
|
||||||
|
if data.bookpos and data.bookpos.startswith('epubcfi(/'):
|
||||||
|
view.goto_bookpos(data.bookpos)
|
||||||
|
|
||||||
|
|
||||||
def show_error(title, msg, details):
|
def show_error(title, msg, details):
|
||||||
@ -280,6 +290,9 @@ if window is window.top:
|
|||||||
document.body.style.fontFamily = get_font_family()
|
document.body.style.fontFamily = get_font_family()
|
||||||
document.head.appendChild(E.style(get_widget_css()))
|
document.head.appendChild(E.style(get_widget_css()))
|
||||||
set_css(document.body, background_color=get_color('window-background'), color=get_color('window-foreground'))
|
set_css(document.body, background_color=get_color('window-background'), color=get_color('window-foreground'))
|
||||||
|
setTimeout(def():
|
||||||
|
window.onpopstate = on_pop_state
|
||||||
|
, 0) # We do this after event loop ticks over to avoid catching popstate events that some browsers send on page load
|
||||||
else:
|
else:
|
||||||
# iframe
|
# iframe
|
||||||
div = document.getElementById('calibre-viewer-footnote-iframe')
|
div = document.getElementById('calibre-viewer-footnote-iframe')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user