diff --git a/static/skin/viewer.js b/static/skin/viewer.js index f9d9f3bbc..d4eeed8b8 100644 --- a/static/skin/viewer.js +++ b/static/skin/viewer.js @@ -30,7 +30,7 @@ function getBookFromUserUrl(url) { return url.split('/')[0]; } -let currentBook = getBookFromUserUrl(location.hash.slice(1)); +let currentBook = null; let currentBookTitle = null; const bookUIGroup = document.getElementById('kiwix_serve_taskbar_book_ui_group'); @@ -291,17 +291,15 @@ function setup_external_link_blocker() { // End of external link blocking //////////////////////////////////////////////////////////////////////////////// +let viewerSetupComplete = false; + function on_content_load() { - handle_content_url_change(); - setup_external_link_blocker(); + if ( viewerSetupComplete ) { + handle_content_url_change(); + setup_external_link_blocker(); + } } -window.onresize = handle_visual_viewport_change; -window.onhashchange = handle_location_hash_change; - -updateCurrentBook(currentBook); -handle_location_hash_change(); - function htmlDecode(input) { var doc = new DOMParser().parseFromString(input, "text/html"); return doc.documentElement.textContent; @@ -397,6 +395,8 @@ function setupViewer() { // has been settled. setTimeout(handle_visual_viewport_change, 0); + window.onresize = handle_visual_viewport_change; + const kiwixToolBarWrapper = document.getElementById('kiwixtoolbarwrapper'); if ( ! viewerSettings.toolbarEnabled ) { return; @@ -417,4 +417,12 @@ function setupViewer() { if (document.body.clientWidth < 520) { setupAutoHidingOfTheToolbar(); } + + currentBook = getBookFromUserUrl(location.hash.slice(1)); + updateCurrentBook(currentBook); + handle_location_hash_change(); + + window.onhashchange = handle_location_hash_change; + + viewerSetupComplete = true; } diff --git a/test/server.cpp b/test/server.cpp index a68ea3356..5c07b540e 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -69,7 +69,7 @@ const ResourceCollection resources200Compressible{ { DYNAMIC_CONTENT, "/ROOT/skin/taskbar.css" }, { STATIC_CONTENT, "/ROOT/skin/taskbar.css?cacheid=216d6b5d" }, { DYNAMIC_CONTENT, "/ROOT/skin/viewer.js" }, - { STATIC_CONTENT, "/ROOT/skin/viewer.js?cacheid=ab5374c5" }, + { STATIC_CONTENT, "/ROOT/skin/viewer.js?cacheid=33265688" }, { DYNAMIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf" }, { STATIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf?cacheid=af705837" }, { DYNAMIC_CONTENT, "/ROOT/skin/fonts/Roboto.ttf" }, @@ -294,7 +294,7 @@ R"EXPECTEDRESULT( - + const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";