From ca24b8a55cb8a969bd78868ad25ef6a065bd8948 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 29 Dec 2017 11:33:32 +0530 Subject: [PATCH] Content server: Allow opening entries in the book list in a new tab via middle click/right click --- src/pyj/book_list/cover_grid.pyj | 6 +++--- src/pyj/book_list/custom_list.pyj | 6 +++--- src/pyj/book_list/details_list.pyj | 4 ++-- src/pyj/book_list/views.pyj | 7 ++++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pyj/book_list/cover_grid.pyj b/src/pyj/book_list/cover_grid.pyj index d361666223..6924cea81f 100644 --- a/src/pyj/book_list/cover_grid.pyj +++ b/src/pyj/book_list/cover_grid.pyj @@ -22,7 +22,7 @@ def cover_grid_css(): align_content='flex-start', user_select='none', overflow='hidden', margin_top=f'{margin / 2}{margin_unit}') # Container for an individual cover - sel += ' > div' + sel += ' > a' ans += build_rule( 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', @@ -61,13 +61,13 @@ def on_img_load(img, load_type): )) 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') img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) tooltip = _('{} by {}').format(metadata.title, authors) img.setAttribute('alt', tooltip) 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 def append_item(container, item): diff --git a/src/pyj/book_list/custom_list.pyj b/src/pyj/book_list/custom_list.pyj index 0cbf5d1b23..a909c6a015 100644 --- a/src/pyj/book_list/custom_list.pyj +++ b/src/pyj/book_list/custom_list.pyj @@ -263,7 +263,7 @@ def on_img_load(img, load_type): 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() text_data = render_template_text(template, book_id, metadata) text_data.style.flexGrow = '10' @@ -278,9 +278,9 @@ def create_item(book_id, metadata, create_image, show_book_details): height = template.height if jstype(height) is 'number': height += 'px' - ans = E.div( + ans = E.a( style=f'height:{height}; display: flex', - class_=ITEM_CLASS, + class_=ITEM_CLASS, href=href ) if template.thumbnail: h = template.thumbnail_height diff --git a/src/pyj/book_list/details_list.pyj b/src/pyj/book_list/details_list.pyj index aae8df26a3..a9a1369ff4 100644 --- a/src/pyj/book_list/details_list.pyj +++ b/src/pyj/book_list/details_list.pyj @@ -69,7 +69,7 @@ def sandbox_css(): 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') img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) img.setAttribute('alt', _('{} by {}').format(metadata.title, authors)) @@ -103,7 +103,7 @@ def create_item(book_id, metadata, create_image, show_book_details): ), comments, ) - ans = E.div(img_div, right, + ans = E.a(img_div, right, href=href, style=f'height:{THUMBNAIL_MAX_HEIGHT}px; display: flex', class_=ITEM_CLASS, ) diff --git a/src/pyj/book_list/views.pyj b/src/pyj/book_list/views.pyj index a44e64b110..1c7581d65b 100644 --- a/src/pyj/book_list/views.pyj +++ b/src/pyj/book_list/views.pyj @@ -33,7 +33,7 @@ from book_list.search import ( 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.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 modals import error_dialog from session import get_interface_data @@ -99,7 +99,8 @@ def show_subsequent_panel(name, query=None, replace=False): 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}) @@ -112,7 +113,7 @@ def render_id(book_id): book_list_data.shown_book_ids.add(book_id) if l < book_list_data.shown_book_ids.length: 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.dataset.bookId = str(book_id) return ans