diff --git a/src/pyj/book_list/home.pyj b/src/pyj/book_list/home.pyj index 6417a357db..129f952c3f 100644 --- a/src/pyj/book_list/home.pyj +++ b/src/pyj/book_list/home.pyj @@ -6,6 +6,7 @@ from dom import ensure_id from elementmaker import E from session import get_interface_data from gettext import gettext as _ +from utils import conditional_timeout from book_list.globals import get_db from book_list.top_bar import create_top_bar @@ -13,12 +14,10 @@ from book_list.ui import set_default_panel_handler, show_panel def show_recent(): + container = this db = get_db() if not db.initialized: - window.setTimeout(show_recent.bind(this), 5) - return - container = document.getElementById(this) - if not container: + conditional_timeout(container.id, 5, show_recent) return @@ -31,7 +30,7 @@ def init(container_id): recent = E.div(style='display:none') recent_container_id = ensure_id(recent) container.appendChild(recent) - window.setTimeout(show_recent.bind(recent_container_id), 5) + conditional_timeout(recent_container_id, 5, show_recent) # Choose library cl = E.div( diff --git a/src/pyj/utils.pyj b/src/pyj/utils.pyj index 3bb8fe40a1..e89131886d 100644 --- a/src/pyj/utils.pyj +++ b/src/pyj/utils.pyj @@ -162,6 +162,13 @@ def uniq(vals): ans.push(x) return ans +def conditional_timeout(elem_id, timeout, func): + def ct_impl(): + elem = document.getElementById(elem_id) + if elem: + func.call(elem) + window.setTimeout(ct_impl, timeout) + if __name__ is '__main__': from pythonize import strings strings()