diff --git a/src/pyj/book_list/router.pyj b/src/pyj/book_list/router.pyj index 74c4bb3b46..ce55879d00 100644 --- a/src/pyj/book_list/router.pyj +++ b/src/pyj/book_list/router.pyj @@ -76,4 +76,10 @@ def back(): if history_count > 0: window.history.back() else: - push_state({}, replace=True) + cq = get_current_query() + handler = mode_handlers[cq.mode] or default_mode_handler + if handler.back_from_current: + q = handler.back_from_current(cq) + else: + q = {} + push_state(q, replace=True) diff --git a/src/pyj/book_list/ui.pyj b/src/pyj/book_list/ui.pyj index e32a1bb3cb..81e501e815 100644 --- a/src/pyj/book_list/ui.pyj +++ b/src/pyj/book_list/ui.pyj @@ -7,7 +7,7 @@ from elementmaker import E from book_list.constants import book_list_container_id from book_list.globals import get_current_query -from book_list.router import push_state, back as router_back +from book_list.router import push_state from book_list.library_data import current_library_id @@ -44,10 +44,6 @@ def currently_showing_panel(): c = document.getElementById(book_list_container_id) return c.dataset.panel -def number_of_subpanels(): - c = document.getElementById(book_list_container_id) - return c.lastChild.childNodes.length - def show_panel(panel, query_data, replace=False): query = {k:query_data[k] for k in query_data} @@ -59,29 +55,19 @@ def show_panel(panel, query_data, replace=False): push_state(query, replace=replace) -def close_subpanel(): - c = document.getElementById(book_list_container_id).lastChild - panel_to_remove = c.lastChild - if panel_to_remove: - c.remove(panel_to_remove) - if c.lastChild: - c.lastChild.style.display = 'block' - else: - c.style.display = 'none' - - -def back(): - if number_of_subpanels() > 0: - return close_subpanel() - router_back() - - def apply_url_state(state): panel = state.panel or 'home' c = document.getElementById(book_list_container_id) clear(c) c.appendChild(E.div()) - c.appendChild(E.div(style='display:none')) c.dataset.panel = panel handler = panel_handlers[panel] or default_panel_handler handler(ensure_id(c.firstChild, 'panel')) + + +apply_url_state.back_from_current = def back_from_current(current_query): + q = current_query + if q.panel and '^' in q.panel: + q = {k:q[k] for k in q} + q.panel = q.panel.rpartition('^')[0] + return q diff --git a/src/pyj/book_list/views.pyj b/src/pyj/book_list/views.pyj index 18de96495b..f45809546a 100644 --- a/src/pyj/book_list/views.pyj +++ b/src/pyj/book_list/views.pyj @@ -11,7 +11,8 @@ from session import get_interface_data from book_list.globals import get_session_data from book_list.cover_grid import cover_grid_css, create_item as create_cover_grid_item, init as init_cover_grid, append_item as cover_grid_append_item from book_list.top_bar import create_top_bar -from book_list.ui import back, set_panel_handler +from book_list.router import back +from book_list.ui import set_panel_handler from book_list.library_data import current_library_id, load_status, ensure_current_library_data, library_data ALLOWED_MODES = {'cover_grid'}