diff --git a/src/pyj/dom.pyj b/src/pyj/dom.pyj index 3ca575aa8c..be926a2ca4 100644 --- a/src/pyj/dom.pyj +++ b/src/pyj/dom.pyj @@ -92,6 +92,15 @@ def element(elem_id, child_selector): ans = ans.querySelector(child_selector) return ans +def selector(id_selector, *args): + ans = '#' + id_selector + for x in args: + ans += ' ' + x + return ans + +def rule(id_selector, *args, **kw): + return build_rule(selector(id_selector, *args), **kw) + def unique_id(prefix): prefix = prefix or 'auto-id' unique_id.counts[prefix] = num = (unique_id.counts[prefix] or 0) + 1 diff --git a/src/pyj/read_book/prefs/font_size.pyj b/src/pyj/read_book/prefs/font_size.pyj index 0b8743f8bf..e1277cc938 100644 --- a/src/pyj/read_book/prefs/font_size.pyj +++ b/src/pyj/read_book/prefs/font_size.pyj @@ -2,8 +2,10 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal from __python__ import hash_literals, bound_methods -from dom import unique_id, set_css, add_extra_css, build_rule +from dom import unique_id, set_css, add_extra_css, rule, element from elementmaker import E +from gettext import gettext as _ +from widgets import create_button from book_list.globals import get_session_data, get_boss from book_list.theme import get_color @@ -11,8 +13,9 @@ CONTAINER = unique_id('font-size-prefs') QUICK = unique_id('quick') add_extra_css(def(): - style = build_rule('#' + QUICK + ' li.current', background_color=get_color('window-background2')) - style += build_rule('#' + QUICK + ' li:hover', background_color=get_color('window-background2')) + style = rule(QUICK, 'li.current', background_color=get_color('window-background2')) + style += rule(QUICK, 'li:hover', background_color=get_color('window-background2')) + style += rule(CONTAINER, 'a:hover', color='red') return style ) @@ -27,10 +30,20 @@ def set_quick_size(ev): sz = int(li.dataset.sz) change_font_size(sz) +def set_custom_size(ev): + sz = int(element(CONTAINER, 'input').value) + change_font_size(sz) + +def show_custom_size(ev): + c = element(CONTAINER) + for child in c.childNodes: + child.style.display = 'none' + c.lastChild.style.display = 'block' + def create_font_size_panel(container, close): container.appendChild(E.div(id=CONTAINER, style='margin:15vh auto; max-width: 500px; border-radius: 8px; border: solid 1px currentColor; padding:1ex 1rem', - onclick=def(ev): ev.preventDefault(), ev.stopPropagation + onclick=def(ev): ev.preventDefault(), ev.stopPropagation() )) container = container.lastChild container.style.backgroundColor = get_color('window-background') @@ -42,5 +55,19 @@ def create_font_size_panel(container, close): quick.appendChild(set_css(E.li('Aa', title='{} px'.format(sz), class_='current' if cfs is sz else '', data_sz=str(sz), onclick=def(ev):set_quick_size(ev), close();), display='inline-block', font_size=sz + 'px', padding='5px', cursor='pointer', border_radius='2px')) + container.appendChild(E.div( + E.a(_('Custom size'), href='javascript:void', onclick=show_custom_size, style='cursor:pointer'), + style='text-align: right; color: blue; font-size: smaller; margin-top: 2ex' + )) + + container.appendChild(E.div(style='display:none', + E.div(E.label(_('Font size (pixels):'), '\xa0', E.input(type='number', min=8, max=60, step=1, value=str(sd.get('base_font_size'))))), + E.div(style='text-align:right; margin-top:1ex; display:flex; justify-content: flex-end', + create_button(_('OK'), 'check', def(): set_custom_size(), close();), E.span('\xa0'), + create_button(_('Cancel'), action=close) + ))) + + + def develop(container): create_font_size_panel(container, def():pass;)