mirror of https://github.com/kiwix/libkiwix.git
All of viewer initialization is done by setupViewer()
Before this change, some of the actions related to the initialization of the viewer were run in the global scope as a side effect of loading /skin/viewer.js. This change moves those actions into setupViewer().
This commit is contained in:
parent
37bf993759
commit
430bcb17c2
|
@ -30,7 +30,7 @@ function getBookFromUserUrl(url) {
|
||||||
return url.split('/')[0];
|
return url.split('/')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentBook = getBookFromUserUrl(location.hash.slice(1));
|
let currentBook = null;
|
||||||
let currentBookTitle = null;
|
let currentBookTitle = null;
|
||||||
|
|
||||||
const bookUIGroup = document.getElementById('kiwix_serve_taskbar_book_ui_group');
|
const bookUIGroup = document.getElementById('kiwix_serve_taskbar_book_ui_group');
|
||||||
|
@ -291,17 +291,15 @@ function setup_external_link_blocker() {
|
||||||
// End of external link blocking
|
// End of external link blocking
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
let viewerSetupComplete = false;
|
||||||
|
|
||||||
function on_content_load() {
|
function on_content_load() {
|
||||||
|
if ( viewerSetupComplete ) {
|
||||||
handle_content_url_change();
|
handle_content_url_change();
|
||||||
setup_external_link_blocker();
|
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) {
|
function htmlDecode(input) {
|
||||||
var doc = new DOMParser().parseFromString(input, "text/html");
|
var doc = new DOMParser().parseFromString(input, "text/html");
|
||||||
return doc.documentElement.textContent;
|
return doc.documentElement.textContent;
|
||||||
|
@ -397,6 +395,8 @@ function setupViewer() {
|
||||||
// has been settled.
|
// has been settled.
|
||||||
setTimeout(handle_visual_viewport_change, 0);
|
setTimeout(handle_visual_viewport_change, 0);
|
||||||
|
|
||||||
|
window.onresize = handle_visual_viewport_change;
|
||||||
|
|
||||||
const kiwixToolBarWrapper = document.getElementById('kiwixtoolbarwrapper');
|
const kiwixToolBarWrapper = document.getElementById('kiwixtoolbarwrapper');
|
||||||
if ( ! viewerSettings.toolbarEnabled ) {
|
if ( ! viewerSettings.toolbarEnabled ) {
|
||||||
return;
|
return;
|
||||||
|
@ -417,4 +417,12 @@ function setupViewer() {
|
||||||
if (document.body.clientWidth < 520) {
|
if (document.body.clientWidth < 520) {
|
||||||
setupAutoHidingOfTheToolbar();
|
setupAutoHidingOfTheToolbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentBook = getBookFromUserUrl(location.hash.slice(1));
|
||||||
|
updateCurrentBook(currentBook);
|
||||||
|
handle_location_hash_change();
|
||||||
|
|
||||||
|
window.onhashchange = handle_location_hash_change;
|
||||||
|
|
||||||
|
viewerSetupComplete = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ const ResourceCollection resources200Compressible{
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/taskbar.css" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/taskbar.css" },
|
||||||
{ STATIC_CONTENT, "/ROOT/skin/taskbar.css?cacheid=216d6b5d" },
|
{ STATIC_CONTENT, "/ROOT/skin/taskbar.css?cacheid=216d6b5d" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/viewer.js" },
|
{ 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" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf" },
|
||||||
{ STATIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf?cacheid=af705837" },
|
{ STATIC_CONTENT, "/ROOT/skin/fonts/Poppins.ttf?cacheid=af705837" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT/skin/fonts/Roboto.ttf" },
|
{ DYNAMIC_CONTENT, "/ROOT/skin/fonts/Roboto.ttf" },
|
||||||
|
@ -294,7 +294,7 @@ R"EXPECTEDRESULT( <img src="../skin/download.png?
|
||||||
/* url */ "/ROOT/viewer",
|
/* url */ "/ROOT/viewer",
|
||||||
R"EXPECTEDRESULT( <link type="text/css" href="./skin/taskbar.css?cacheid=216d6b5d" rel="Stylesheet" />
|
R"EXPECTEDRESULT( <link type="text/css" href="./skin/taskbar.css?cacheid=216d6b5d" rel="Stylesheet" />
|
||||||
<link type="text/css" href="./skin/css/autoComplete.css?cacheid=08951e06" rel="Stylesheet" />
|
<link type="text/css" href="./skin/css/autoComplete.css?cacheid=08951e06" rel="Stylesheet" />
|
||||||
<script type="text/javascript" src="./skin/viewer.js?cacheid=ab5374c5" defer></script>
|
<script type="text/javascript" src="./skin/viewer.js?cacheid=33265688" defer></script>
|
||||||
<script type="text/javascript" src="./skin/autoComplete.min.js?cacheid=1191aaaf"></script>
|
<script type="text/javascript" src="./skin/autoComplete.min.js?cacheid=1191aaaf"></script>
|
||||||
const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";
|
const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";
|
||||||
<label for="kiwix_button_show_toggle"><img src="./skin/caret.png?cacheid=22b942b4" alt=""></label>
|
<label for="kiwix_button_show_toggle"><img src="./skin/caret.png?cacheid=22b942b4" alt=""></label>
|
||||||
|
|
Loading…
Reference in New Issue