From e76e13a64247b84a490a51f0ee9a6288f9e6f82e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 May 2017 17:44:10 +0530 Subject: [PATCH] DRYer --- src/pyj/read_book/view.pyj | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 36342e8ae6..f6e21f06ee 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -52,13 +52,17 @@ add_extra_css(def(): ) -def bottom_margin(sd): - sz = sd.get('margin_bottom', 20) +def margin_elem(sd, which, id, onclick): + sz = sd.get(which, 20) fsz = min(max(0, sz - 6), 12) - return E.div( - style=f'height:{sz}px; overflow: hidden; font-size:{fsz}px; width:100%; padding: 0; display: flex; justify-content: space-between; align-items: center', id='book-bottom-margin', + ans = E.div( + style=f'height:{sz}px; overflow: hidden; font-size:{fsz}px; width:100%; padding: 0; display: flex; justify-content: space-between; align-items: center', + id=id, E.div(), E.div() ) + if onclick: + ans.addEventListener('click', onclick) + return ans class View: @@ -77,9 +81,9 @@ class View: E.div(style='flex-grow: 2; display:flex; align-items: stretch', # container for iframe and its overlay left_margin, E.div(style='flex-grow:2; display:flex; align-items:stretch; flex-direction: column', # container for top and bottom margins - E.div(style='height:{}px; overflow: hidden; width:100%; padding: 0; cursor: pointer'.format(sd.get('margin_top', 20)), id='book-top-margin', onclick=self.top_margin_clicked), + margin_elem(sd, 'margin_top', 'book-top-margin', self.top_margin_clicked), E.iframe(id=iframe_id, seamless=True, sandbox='allow-popups allow-scripts', style='flex-grow: 2', allowfullscreen='true'), - bottom_margin(sd), + margin_elem(sd, 'margin_bottom', 'book-bottom-margin'), ), right_margin, E.div(style='position: absolute; top:0; left:0; width: 100%; pointer-events:none; display:none', id='book-search-overlay'), # search overlay