From a9446714eac5c848d17691417d15f2b97caa381c Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 7 Aug 2022 16:54:48 +0400 Subject: [PATCH] Viewer respects the --urlRootLocation option --- static/viewer.html | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/static/viewer.html b/static/viewer.html index 22e8599e7..0da1f40e1 100644 --- a/static/viewer.html +++ b/static/viewer.html @@ -59,12 +59,20 @@ // // iframe url: the URL to be loaded in the viewer iframe. + function getRootLocation() { + const p = location.pathname; + return p.slice(0, p.length - '/viewer'.length); + } + + const root = getRootLocation(); + const blankPageUrl = `${root}/skin/blank.html`; + function userUrl2IframeUrl(url) { if ( url == '' ) { - return '/skin/blank.html'; + return blankPageUrl; } - return `/content/${url}`; + return `${root}/content/${url}`; } function getBookFromUserUrl(url) { @@ -125,10 +133,12 @@ } function iframeUrl2UserUrl(url) { - if ( url == '/skin/blank.html' ) { + if ( url == blankPageUrl ) { return ''; } + url = url.slice(root.length); + return url.split('/').slice(2).join('/'); }