Skip to content

Commit

Permalink
Add resizer script
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodwyer committed Sep 4, 2024
1 parent f17318c commit 588f8b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions airlock/templates/file_browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
<script type="text/javascript" src="{% static 'htmx-1.9.10.min.js' %}"></script>
{% django_htmx_script %}
<script src="{% static 'assets/file_browser/index.js' %}"></script>
{% vite_asset "assets/src/scripts/resizer.js" %}
{% endblock %}
40 changes: 40 additions & 0 deletions assets/src/scripts/resizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function setBrowserHeight() {
const iframe = document.querySelector("iframe");
if (iframe) {
const iframeTop = iframe.getBoundingClientRect()["top"];
iframe.style.height = `${window.innerHeight - iframeTop}px`;
}

const table = document.getElementById("selected-contents");
if (table) {
const tableTop = table.getBoundingClientRect()["top"];
table.style.height = `${window.innerHeight - tableTop}px`;
table.classList.add("overflow-auto");
console.log({ table });
}
}

function setTreeHeight() {
const iframe = document.getElementById("tree-container");
if (iframe) {
const iframeTop = iframe.getBoundingClientRect()["top"];
iframe.style.height = `${window.innerHeight - iframeTop}px`;
}
}

document.documentElement.classList.remove("min-h-screen");
document.documentElement.classList.add("h-screen");

document.body.classList.remove("min-h-screen");
document.body.classList.add("h-screen");

document.querySelector("main")?.classList.add("overflow-hidden");

new ResizeObserver(() => {
setBrowserHeight();
setTreeHeight();
}).observe(document.documentElement);

document.body.addEventListener("htmx:afterSettle", () => {
return setBrowserHeight();
});
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
rollupOptions: {
input: {
main: "assets/src/scripts/main.js",
resizer: "assets/src/scripts/resizer.js",
},
},
},
Expand Down

0 comments on commit 588f8b8

Please sign in to comment.