mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make the download button a direct download link
This commit is contained in:
parent
8ee6f735d2
commit
b0e2cb8452
@ -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'
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user