Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriTimoz committed Apr 23, 2024
1 parent 996f5a3 commit fe58138
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
14 changes: 1 addition & 13 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
<title>Document</title>
<link rel="stylesheet" href="/styles/colors.css" />
<link rel="stylesheet" href="/styles/search.css" />
<link rel="stylesheet" href="https://unpkg.com/iv-viewer/dist/iv-viewer.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.11.6/viewer.min.css" integrity="sha512-za6IYQz7tR0pzniM/EAkgjV1gf1kWMlVJHBHavKIvsNoUMKWU99ZHzvL6lIobjiE2yKDAKMDSSmcMAxoiWgoWA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="autocomplete folded-autocomplete">
<input id="query-input" type="text" name="query" placeholder="Cheat sheet">
</div>
<iframe id="viewer" src="/sheets/base-r.pdf"></iframe>
<iframe id="viewer" src="/sheets/base-r.pdf" allowfullscreen></iframe>
<div id="imageContainer" style="display: none;">
<img id="imageViewer" src="" alt="Image">
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.11.6/viewer.min.js" integrity="sha512-EC3CQ+2OkM+ZKsM1dbFAB6OGEPKRxi6EDRnZW9ys8LghQRAq6cXPUgXCCujmDrXdodGXX9bqaaCRtwj4h4wgSQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="/scripts/load_toc.js"></script>
<script src="/scripts/autocomplete.js"></script>
<script>
Expand All @@ -39,15 +36,6 @@
}
});

document.querySelector('iframe').addEventListener('load', function() {
const iframe = this;
const originalSrc = iframe.src;
setInterval(() => {
if (iframe.contentWindow.location.href !== originalSrc) {
iframe.contentWindow.location.href = originalSrc;
}
}, 100);
});
</script>
</body>
</html>
15 changes: 4 additions & 11 deletions ui/scripts/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ function autocomplete(inp, arr) {
});
}

let viewer = null;
function updatePath(query) {
function updatePath(query, first=false) {
// Get current path
let currentPath = localStorage.getItem('lastPath');
if (currentPath == query) return;
if (currentPath == query && !first) return;

let newSrc = "/sheets/" + query;
let oldPath = document.getElementById("viewer");
Expand All @@ -182,16 +181,10 @@ function updatePath(query) {
let newPath = document.createElement("iframe");
newPath.setAttribute("id", "viewer");
newPath.setAttribute("src", newSrc);
newPath.setAttribute("allow", "fullscreen");

oldPath.parentNode.replaceChild(newPath, oldPath);
} else {
viewer = new Viewer(document.getElementById('imageViewer'), {
inline: true,
viewed() {
viewer.zoomTo(2);
},
});
viewer.show();
oldPath.style.display = "none";
document.getElementById("imageContainer").style.display = "flex";
document.getElementById("imageViewer").src = newSrc;
Expand All @@ -205,6 +198,6 @@ window.addEventListener('load_sheets', function(sheets) {
autocomplete(document.getElementById("query-input"), SHEETS);
let lastPath = localStorage.getItem('lastPath');
if (lastPath) {
updatePath(lastPath);
updatePath(lastPath, true);
}
});

0 comments on commit fe58138

Please sign in to comment.