From 07f5d2ecf2f3c9c060c06fd2661ef6cabfe8b1f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Nov 2017 23:57:00 +0530 Subject: [PATCH] Content server: Fix random book button on book details page multiplying. Fixes #1732493 [Multibpe "A random book" butons in the internet browser](https://bugs.launchpad.net/calibre/+bug/1732493) --- src/pyj/book_list/book_details.pyj | 5 +++-- src/pyj/book_list/top_bar.pyj | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 13ba75b8a5..24ab44fa1f 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -15,7 +15,7 @@ from book_list.library_data import ( ) from book_list.router import back, home, open_book from book_list.theme import get_color, get_font_size -from book_list.top_bar import add_button, create_top_bar, set_title +from book_list.top_bar import add_button, create_top_bar, set_title, clear_buttons from book_list.ui import query_as_href, set_panel_handler, show_panel from book_list.views import search_query_for from date import format_date @@ -443,9 +443,10 @@ def render_book(container_id, book_id): def add_top_bar_buttons(container_id): container = document.getElementById(container_id) if container: + clear_buttons(container) book_id = parse_url_params().book_id if book_id is '0': - add_button(container.parentNode, 'random', def(): fetch_metadata(container_id, 0);) + add_button(container, 'random', def(): fetch_metadata(container_id, 0);) add_button(container, 'ellipsis-v', action=show_subsequent_panel.bind(None, 'more_actions'), tooltip=_('More actions')) diff --git a/src/pyj/book_list/top_bar.pyj b/src/pyj/book_list/top_bar.pyj index e462fa918a..6229d07dff 100644 --- a/src/pyj/book_list/top_bar.pyj +++ b/src/pyj/book_list/top_bar.pyj @@ -101,6 +101,13 @@ def add_button(container, icon, action=None, tooltip=''): event.preventDefault(), action() ) +def clear_buttons(container): + bars = get_bars(container) + for i, bar in enumerate(bars): + right = bar.firstChild.nextSibling + clear(right) + + def set_button_visibility(container, icon, visible): for bar in get_bars(container): right = bar.firstChild.nextSibling