Content server: Allow opening entries in the book list in a new tab via middle click/right click

This commit is contained in:
Kovid Goyal 2017-12-29 11:33:32 +05:30
parent 0c01357f8b
commit ca24b8a55c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 12 additions and 11 deletions

View File

@ -22,7 +22,7 @@ def cover_grid_css():
align_content='flex-start', user_select='none', overflow='hidden', margin_top=f'{margin / 2}{margin_unit}') align_content='flex-start', user_select='none', overflow='hidden', margin_top=f'{margin / 2}{margin_unit}')
# Container for an individual cover # Container for an individual cover
sel += ' > div' sel += ' > a'
ans += build_rule( ans += build_rule(
sel, margin=f'{margin}{margin_unit}', display='flex', align_content='flex-end', align_items='flex-end', justify_content='space-around', sel, margin=f'{margin}{margin_unit}', display='flex', align_content='flex-end', align_items='flex-end', justify_content='space-around',
max_width=THUMBNAIL_MAX_WIDTH+'px', max_height=THUMBNAIL_MAX_HEIGHT+'px', cursor='pointer', max_width=THUMBNAIL_MAX_WIDTH+'px', max_height=THUMBNAIL_MAX_HEIGHT+'px', cursor='pointer',
@ -61,13 +61,13 @@ def on_img_load(img, load_type):
)) ))
set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px') set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px')
def create_item(book_id, metadata, create_image, show_book_details): def create_item(book_id, metadata, create_image, show_book_details, href):
authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown') authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown')
img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load)
tooltip = _('{} by {}').format(metadata.title, authors) tooltip = _('{} by {}').format(metadata.title, authors)
img.setAttribute('alt', tooltip) img.setAttribute('alt', tooltip)
img.dataset.title, img.dataset.authors = metadata.title, authors img.dataset.title, img.dataset.authors = metadata.title, authors
ans = E.div(img, onclick=show_book_details, title=tooltip) ans = E.a(img, onclick=show_book_details, title=tooltip, href=href)
return ans return ans
def append_item(container, item): def append_item(container, item):

View File

@ -263,7 +263,7 @@ def on_img_load(img, load_type):
set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px') set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px')
def create_item(book_id, metadata, create_image, show_book_details): def create_item(book_id, metadata, create_image, show_book_details, href):
template = get_interface_data().custom_list_template or default_template() template = get_interface_data().custom_list_template or default_template()
text_data = render_template_text(template, book_id, metadata) text_data = render_template_text(template, book_id, metadata)
text_data.style.flexGrow = '10' text_data.style.flexGrow = '10'
@ -278,9 +278,9 @@ def create_item(book_id, metadata, create_image, show_book_details):
height = template.height height = template.height
if jstype(height) is 'number': if jstype(height) is 'number':
height += 'px' height += 'px'
ans = E.div( ans = E.a(
style=f'height:{height}; display: flex', style=f'height:{height}; display: flex',
class_=ITEM_CLASS, class_=ITEM_CLASS, href=href
) )
if template.thumbnail: if template.thumbnail:
h = template.thumbnail_height h = template.thumbnail_height

View File

@ -69,7 +69,7 @@ def sandbox_css():
return sandbox_css.ans return sandbox_css.ans
def create_item(book_id, metadata, create_image, show_book_details): def create_item(book_id, metadata, create_image, show_book_details, href):
authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown') authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown')
img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load)
img.setAttribute('alt', _('{} by {}').format(metadata.title, authors)) img.setAttribute('alt', _('{} by {}').format(metadata.title, authors))
@ -103,7 +103,7 @@ def create_item(book_id, metadata, create_image, show_book_details):
), ),
comments, comments,
) )
ans = E.div(img_div, right, ans = E.a(img_div, right, href=href,
style=f'height:{THUMBNAIL_MAX_HEIGHT}px; display: flex', style=f'height:{THUMBNAIL_MAX_HEIGHT}px; display: flex',
class_=ITEM_CLASS, class_=ITEM_CLASS,
) )

View File

@ -33,7 +33,7 @@ from book_list.search import (
init as init_search_panel, set_apply_search, tb_config_panel_handler init as init_search_panel, set_apply_search, tb_config_panel_handler
) )
from book_list.top_bar import add_button, create_top_bar from book_list.top_bar import add_button, create_top_bar
from book_list.ui import set_panel_handler, show_panel from book_list.ui import query_as_href, set_panel_handler, show_panel
from dom import add_extra_css, build_rule, clear, ensure_id, set_css from dom import add_extra_css, build_rule, clear, ensure_id, set_css
from modals import error_dialog from modals import error_dialog
from session import get_interface_data from session import get_interface_data
@ -99,7 +99,8 @@ def show_subsequent_panel(name, query=None, replace=False):
show_panel(name, query, replace) show_panel(name, query, replace)
def show_book_details(book_id): def on_book_click(book_id, evt):
evt.preventDefault()
show_subsequent_panel('book_details', {'book_id':book_id}) show_subsequent_panel('book_details', {'book_id':book_id})
@ -112,7 +113,7 @@ def render_id(book_id):
book_list_data.shown_book_ids.add(book_id) book_list_data.shown_book_ids.add(book_id)
if l < book_list_data.shown_book_ids.length: if l < book_list_data.shown_book_ids.length:
metadata = book_metadata(book_id) metadata = book_metadata(book_id)
ans = book_list_data.render_book(book_id, metadata, create_image, show_book_details.bind(None, book_id)) ans = book_list_data.render_book(book_id, metadata, create_image, on_book_click.bind(None, book_id), query_as_href({'book_id': book_id + ''}, 'book_details'))
ans.classList.add(ITEM_CLASS_NAME) ans.classList.add(ITEM_CLASS_NAME)
ans.dataset.bookId = str(book_id) ans.dataset.bookId = str(book_id)
return ans return ans