From a067cd6b6450496fd5c15f6ad83fdc97dd3ef9f9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 28 Mar 2016 12:57:41 +0530 Subject: [PATCH] Make resize event available to the read book widget as well --- src/pyj/book_list/boss.pyj | 7 ++++++- src/pyj/book_list/ui.pyj | 2 -- src/pyj/read_book/ui.pyj | 3 +++ src/pyj/read_book/view.pyj | 16 ++++++++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/pyj/book_list/boss.pyj b/src/pyj/book_list/boss.pyj index 586c134f2a..49657a1b5c 100644 --- a/src/pyj/book_list/boss.pyj +++ b/src/pyj/book_list/boss.pyj @@ -7,7 +7,7 @@ from elementmaker import E from modals import error_dialog, create_modal_container from gettext import gettext as _ from widgets import get_widget_css -from utils import parse_url_params +from utils import parse_url_params, debounce from book_list.globals import get_session_data, set_boss, set_current_query from book_list.theme import get_color @@ -47,6 +47,11 @@ class Boss: setTimeout(def(): window.onpopstate = self.onpopstate.bind(self) , 0) # We do this after event loop ticks over to avoid catching popstate events that some browsers send on page load + window.addEventListener('resize', debounce(self.on_resize.bind(self), 250)) + + def on_resize(self): + self.ui.on_resize() + self.read_ui.on_resize() def apply_mode(self, mode): mode = mode or self.current_mode diff --git a/src/pyj/book_list/ui.pyj b/src/pyj/book_list/ui.pyj index 223f5feea1..48feafd520 100644 --- a/src/pyj/book_list/ui.pyj +++ b/src/pyj/book_list/ui.pyj @@ -9,7 +9,6 @@ from book_list.item_list import ItemsView, create_item from book_list.prefs import PrefsPanel from book_list.book_details import BookDetailsPanel from gettext import gettext as _ -from utils import debounce from modals import error_dialog, ajax_progress_dialog class BarState: @@ -96,7 +95,6 @@ class UI: self.panels = [self.books_view, self.items_view, self.search_panel, self.prefs_panel, self.book_details_panel] self.panel_map = {self.ROOT_PANEL: UIState(create_book_view_top_bar_state(self.books_view), main_panel=self.books_view)} self.current_panel = self.ROOT_PANEL - window.addEventListener('resize', debounce(self.on_resize.bind(self), 250)) num_of_libraries = len(interface_data.library_map) actions = [ diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index ad75b0139e..137d97c35a 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -47,6 +47,9 @@ class ReadUI: )) self.view = View(container.lastChild, self) + def on_resize(self): + self.view.on_resize() + def show_stack(self, name): ans = None for w in self.stacked_widgets: diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index f0e6f6431a..2a37f9f230 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -28,10 +28,15 @@ class View: self.ui = ui self.loaded_resources = {} container.appendChild( - E.iframe( - id=iframe_id, - seamless=True, - sandbox='allow-popups allow-scripts', + E.div(style='width: 100vw; height: 100vh; overflow: hidden; display: flex; align-items: stretch', + E.div(style='display: flex; flex-direction: column; align-items: stretch; flex-grow:2', + E.iframe( + id=iframe_id, + seamless=True, + sandbox='allow-popups allow-scripts', + style='flex-grow: 2', + ) + ) ) ) self.src_doc = None @@ -94,6 +99,9 @@ class View: def on_iframe_error(self, data): self.ui.show_error((data.title or _('There was an error processing the book')), data.msg, data.details) + def on_resize(self): + pass + def show_loading(self, title): return # TODO: Implement this