mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server: Allow opening entries in the book list in a new tab via middle click/right click
This commit is contained in:
parent
0c01357f8b
commit
ca24b8a55c
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user