add check to only run script on root svg
This commit is contained in:
parent
1dc45b64a6
commit
070b50a6e2
1 changed files with 5 additions and 2 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
const svgEl = document.querySelector("svg");
|
const svgEl = document.querySelector("svg");
|
||||||
|
const svgID = "d2-svg";
|
||||||
|
svgEl.setAttribute("id", svgID);
|
||||||
|
if (document.documentElement.getAttribute("id") !== svgID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let width = parseInt(svgEl.getAttribute("width"), 10);
|
let width = parseInt(svgEl.getAttribute("width"), 10);
|
||||||
let height = parseInt(svgEl.getAttribute("height"), 10);
|
let height = parseInt(svgEl.getAttribute("height"), 10);
|
||||||
let ratio;
|
let ratio;
|
||||||
|
|
@ -10,9 +15,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
} else if (height > window.innerHeight) {
|
} else if (height > window.innerHeight) {
|
||||||
ratio = window.innerHeight / height;
|
ratio = window.innerHeight / height;
|
||||||
}
|
}
|
||||||
// Scale svg fit to zoom
|
|
||||||
if (ratio) {
|
if (ratio) {
|
||||||
// body padding is 8px
|
|
||||||
svgEl.setAttribute("width", width * ratio - 16);
|
svgEl.setAttribute("width", width * ratio - 16);
|
||||||
svgEl.setAttribute("height", height * ratio - 16);
|
svgEl.setAttribute("height", height * ratio - 16);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue