diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 5a0575e03b..f5da2b3cdc 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -351,8 +351,9 @@ def render_book(container_id, book_id): )) container = c.lastChild.firstChild read_button = create_button(_('Read'), 'book', read_book.bind(None, book_id), _('Read this book')) - download_button = create_button(_('Download'), 'cloud-download', download_book.bind(None, book_id), - _('Download this book in the {} format').format(preferred_format(book_id))) + fmt = preferred_format(book_id) + download_button = create_button(_('Download'), 'cloud-download', download_url(book_id, fmt), + _('Download this book in the {} format').format(fmt), download_filename=f'{metadata.title}.{fmt.toLowerCase()}') row = E.div(read_button, '\xa0\xa0\xa0', download_button, style='margin-bottom: 1ex') if not metadata.formats or not metadata.formats.length: row.style.display = 'none' diff --git a/src/pyj/widgets.pyj b/src/pyj/widgets.pyj index 2df100ac26..c9305156b0 100644 --- a/src/pyj/widgets.pyj +++ b/src/pyj/widgets.pyj @@ -9,14 +9,19 @@ from book_list.theme import get_color # Button {{{ -def create_button(text, icon=None, action=None, tooltip=None, highlight=False): +def create_button(text, icon=None, action=None, tooltip=None, highlight=False, download_filename=None): ic = '' if icon: ic = svgicon(icon) text = '\xa0' + text ans = E.a(ic, E.span(text), class_='calibre-push-button', href='javascript: void(0)', title=tooltip or '') + if download_filename and v'"download" in ans': + ans.setAttribute('download', download_filename) if action is not None: - ans.addEventListener('click', def(event): event.preventDefault(), action(event);) + if jstype(action) is 'string': + ans.setAttribute('href', action) + else: + ans.addEventListener('click', def(event): event.preventDefault(), action(event);) if highlight: set_css(ans, font_size='larger', font_weight='bold') return ans