Spaces:
Running
Running
Update index.js
Browse filesaspect ratio match the one of the code bloc
index.js
CHANGED
|
@@ -24,11 +24,12 @@
|
|
| 24 |
var gifUrl = getScriptQueryParam("gif_url");
|
| 25 |
var plyUrl = getScriptQueryParam("ply_url");
|
| 26 |
|
| 27 |
-
//
|
| 28 |
-
//
|
|
|
|
| 29 |
var aspectParam = getScriptQueryParam("aspect");
|
| 30 |
-
var aspectPercent = "100%"; // default: 1:1 aspect ratio
|
| 31 |
if (aspectParam) {
|
|
|
|
| 32 |
if (aspectParam.indexOf(":") !== -1) {
|
| 33 |
var parts = aspectParam.split(":");
|
| 34 |
var w = parseFloat(parts[0]);
|
|
@@ -42,6 +43,14 @@
|
|
| 42 |
aspectPercent = (100 / aspectValue) + "%";
|
| 43 |
}
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
// Optional parameters for zoom and rotation limits.
|
|
|
|
| 24 |
var gifUrl = getScriptQueryParam("gif_url");
|
| 25 |
var plyUrl = getScriptQueryParam("ply_url");
|
| 26 |
|
| 27 |
+
// Determine the aspect ratio.
|
| 28 |
+
// Default aspect: 1:1 (i.e. 100% padding-bottom)
|
| 29 |
+
var aspectPercent = "100%";
|
| 30 |
var aspectParam = getScriptQueryParam("aspect");
|
|
|
|
| 31 |
if (aspectParam) {
|
| 32 |
+
// Expected format: "width:height" (e.g. "16:9") or a decimal number.
|
| 33 |
if (aspectParam.indexOf(":") !== -1) {
|
| 34 |
var parts = aspectParam.split(":");
|
| 35 |
var w = parseFloat(parts[0]);
|
|
|
|
| 43 |
aspectPercent = (100 / aspectValue) + "%";
|
| 44 |
}
|
| 45 |
}
|
| 46 |
+
} else {
|
| 47 |
+
// If no aspect parameter is provided, compute the aspect ratio from the parent element.
|
| 48 |
+
var parentContainer = document.currentScript.parentNode;
|
| 49 |
+
var containerWidth = parentContainer.offsetWidth;
|
| 50 |
+
var containerHeight = parentContainer.offsetHeight;
|
| 51 |
+
if (containerWidth > 0 && containerHeight > 0) {
|
| 52 |
+
aspectPercent = (containerHeight / containerWidth * 100) + "%";
|
| 53 |
+
}
|
| 54 |
}
|
| 55 |
|
| 56 |
// Optional parameters for zoom and rotation limits.
|