Embryo of iframe-based viewer

This commit is contained in:
Veloman Yunkan 2022-02-22 22:42:15 +04:00
parent dea674ef38
commit 4db443eca6
4 changed files with 71 additions and 3 deletions

View File

@ -553,7 +553,7 @@ std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& r
if (url == "/" )
return build_homepage(request);
if (isEndpointUrl(url, "skin"))
if (isEndpointUrl(url, "viewer") || isEndpointUrl(url, "skin"))
return handle_skin(request);
if (isEndpointUrl(url, "content"))
@ -720,12 +720,17 @@ std::unique_ptr<Response> InternalServer::handle_skin(const RequestContext& requ
printf("** running handle_skin\n");
}
auto resourceName = request.get_url().substr(1);
const bool isRequestForViewer = request.get_url() == "/viewer";
auto resourceName = isRequestForViewer
? "viewer.html"
: request.get_url().substr(1);
try {
auto response = ContentResponse::build(
*this,
getResource(resourceName),
getMimeTypeForFile(resourceName));
getMimeTypeForFile(resourceName),
/*isHomePage=*/false,
/*raw=*/true);
response->set_cacheable();
return std::move(response);
} catch (const ResourceNotFound& e) {

View File

@ -15,6 +15,8 @@ skin/fonts/Poppins.ttf
skin/fonts/Roboto.ttf
skin/block_external.js
skin/search_results.css
skin/blank.html
viewer.html
templates/search_result.html
templates/search_result.xml
templates/error.html

11
static/skin/blank.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blank page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
</body>
</html>

50
static/viewer.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ZIM Viewer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="margin:0">
<div id=taskbar style="background:#bbffbb">Taskbar</div>
<iframe id="content_iframe"
referrerpolicy="same-origin"
onload="handle_content_url_change()"
src="skin/blank.html" title="ZIM content" width="100%"
style="border:0px">
</iframe>
<script>
// Terminology
//
// user url: identifier of the page that has to be displayed in the viewer
// and that is used as the hash component of the viewer URL. For
// book resources the address url is {book}/{resource} .
//
// iframe url: the URL to be loaded in the viewer iframe.
function userUrl2IframeUrl(url) {
return `/content/${url}`;
}
function iframeUrl2UserUrl(url) {
return url.split('/').slice(2).join('/');
}
const cf = document.getElementById('content_iframe');
cf.src = userUrl2IframeUrl(window.location.hash.slice(1));
cf.height = window.visualViewport.height - cf.offsetTop - 4;
function handle_content_url_change() {
document.title = cf.contentDocument.title;
const iframeContentUrl = cf.contentWindow.location.pathname;
console.log('handle_content_url_change: ' + iframeContentUrl);
window.location.hash = iframeUrl2UserUrl(iframeContentUrl);
};
</script>
</body>
</html>