mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make the top bar API id free
This commit is contained in:
parent
ff12d0be17
commit
4875060c50
@ -22,8 +22,8 @@ def show_recent():
|
||||
|
||||
|
||||
def init(container_id):
|
||||
create_top_bar(container_id, run_animation=True)
|
||||
container = document.getElementById(container_id)
|
||||
create_top_bar(container, run_animation=True)
|
||||
interface_data = get_interface_data()
|
||||
|
||||
# Recent books
|
||||
|
@ -26,8 +26,7 @@ add_extra_css(def():
|
||||
return style
|
||||
)
|
||||
|
||||
def create_markup(container_id):
|
||||
container = document.getElementById(container_id)
|
||||
def create_markup(container):
|
||||
for i in range(2):
|
||||
bar = E.div(
|
||||
class_=CLASS_NAME,
|
||||
@ -43,12 +42,11 @@ def create_markup(container_id):
|
||||
)
|
||||
container.appendChild(bar)
|
||||
|
||||
def get_bars(container_id):
|
||||
container = document.getElementById(container_id)
|
||||
def get_bars(container):
|
||||
return container.getElementsByClassName(CLASS_NAME)
|
||||
|
||||
def set_left_data(container_id, title='calibre', icon='heart', action=None, tooltip='', run_animation=False, title_action=None, title_tooltip=None):
|
||||
bars = get_bars(container_id)
|
||||
def set_left_data(container, title='calibre', icon='heart', action=None, tooltip='', run_animation=False, title_action=None, title_tooltip=None):
|
||||
bars = get_bars(container)
|
||||
if icon is 'heart':
|
||||
if not tooltip:
|
||||
tooltip = _('Donate to support calibre development')
|
||||
@ -77,19 +75,19 @@ def set_left_data(container_id, title='calibre', icon='heart', action=None, tool
|
||||
a = a.nextSibling
|
||||
a.addEventListener('click', def(event): event.preventDefault(), title_action();)
|
||||
|
||||
def set_title(container_id, text):
|
||||
bars = get_bars(container_id)
|
||||
def set_title(container, text):
|
||||
bars = get_bars(container)
|
||||
for bar in bars:
|
||||
bar.firstChild.firstChild.nextSibling.textContent = text
|
||||
|
||||
def create_top_bar(container_id, **kw):
|
||||
create_markup(container_id)
|
||||
set_left_data(container_id, **kw)
|
||||
def create_top_bar(container, **kw):
|
||||
create_markup(container)
|
||||
set_left_data(container, **kw)
|
||||
|
||||
def add_button(container_id, icon, action=None, tooltip=''):
|
||||
def add_button(container, icon, action=None, tooltip=''):
|
||||
if not icon:
|
||||
raise ValueError('An icon must be specified')
|
||||
bars = get_bars(container_id)
|
||||
bars = get_bars(container)
|
||||
for i, bar in enumerate(bars):
|
||||
right = bar.firstChild.nextSibling
|
||||
right.appendChild(E.a(
|
||||
@ -103,8 +101,8 @@ def add_button(container_id, icon, action=None, tooltip=''):
|
||||
event.preventDefault(), action()
|
||||
)
|
||||
|
||||
def set_button_visibility(container_id, icon, visible):
|
||||
for bar in get_bars(container_id):
|
||||
def set_button_visibility(container, icon, visible):
|
||||
for bar in get_bars(container):
|
||||
right = bar.firstChild.nextSibling
|
||||
elem = right.querySelector(f'[data-button-icon="{icon}"]')
|
||||
if elem:
|
||||
|
@ -157,7 +157,7 @@ def create_books_list(container):
|
||||
container.appendChild(E.div()), container.appendChild(E.div())
|
||||
apply_view_mode(get_session_data().get('view_mode'))
|
||||
create_more_button(container.lastChild)
|
||||
add_button(container.parentNode.id, icon='sort-amount-desc', action=show_panel.bind(None, 'book_list^sort'), tooltip=_('Sort Books'))
|
||||
add_button(container.parentNode, icon='sort-amount-desc', action=show_panel.bind(None, 'book_list^sort'), tooltip=_('Sort Books'))
|
||||
|
||||
|
||||
def check_for_books_loaded():
|
||||
@ -189,7 +189,7 @@ def init(container_id):
|
||||
container = document.getElementById(container_id)
|
||||
lid = container.dataset.library_id = url_books_query().library_id
|
||||
title = interface_data.library_map[lid]
|
||||
create_top_bar(container_id, title=title, action=back, icon='home')
|
||||
create_top_bar(container, title=title, action=back, icon='home')
|
||||
container.appendChild(E.div())
|
||||
container.lastChild.appendChild(E.div(_('Loading books from the {} calibre library, please wait...').format(title), style='margin: 1ex 1em'))
|
||||
conditional_timeout(container_id, 5, check_for_books_loaded)
|
||||
@ -215,7 +215,8 @@ def create_sort_panel(container_id):
|
||||
if not library_data.sortable_fields:
|
||||
show_panel('book_list', replace=True)
|
||||
return
|
||||
create_top_bar(container_id, title=_('Sort books by…'), action=back, icon='close')
|
||||
container = document.getElementById(container_id)
|
||||
create_top_bar(container, title=_('Sort books by…'), action=back, icon='close')
|
||||
items = []
|
||||
csf, csf_order = current_sorted_field()
|
||||
new_sort_order = 'desc' if csf_order is 'asc' else 'asc'
|
||||
@ -230,7 +231,6 @@ def create_sort_panel(container_id):
|
||||
else:
|
||||
action = change_sort.bind(None, field, None)
|
||||
items.push(create_item(name, subtitle=subtitle, icon=icon_name, action=action))
|
||||
container = document.getElementById(container_id)
|
||||
container.appendChild(E.div())
|
||||
create_item_list(container.lastChild, items, _('Change how the list of books is sorted'))
|
||||
# }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user