forked from lin-midas-pages/common_pages
Made image placement much more flexible and avoid logging errors
This commit is contained in:
1 parent
b29bec4430
commit
7ddf65a3b6
3 files changed
+62
-21
No files matched your search
@@ -28,15 +28,43 @@ build step is needed.
|
||||
|
||||
## Beamline_elements
|
||||
|
||||
To show an image of the beamline next to the table on the Beamline_elements page,
|
||||
simply have the installation routine place an image called
|
||||
Beamline_overview_bottom.png or Beamline_overview_right.png next to
|
||||
Beamline_elements.html (Beamline_overview_bottom.png will be placed on the
|
||||
bottom of the table, Beamline_overview_right.png will be placed to its right).
|
||||
It is possible to show an image to the right or to the bottom of the table in
|
||||
the Beamline_elements page by providing a custom beamline_overview_images.json
|
||||
manifest file (it is recommended to automate this as part of the
|
||||
installation routine). The default beamline_overview_images.json looks like
|
||||
this:
|
||||
|
||||
```json
|
||||
{
|
||||
}
|
||||
```
|
||||
To put an image to the right of the table, the custom file should like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"right": "image_to_the_right",
|
||||
}
|
||||
```
|
||||
|
||||
Similarily, for an image at the bottom:
|
||||
|
||||
```json
|
||||
{
|
||||
"bottom": "image_at_the_bottom",
|
||||
}
|
||||
```
|
||||
|
||||
And for both right and bottom:
|
||||
|
||||
```json
|
||||
{
|
||||
"right": "image_to_the_right",
|
||||
"bottom": "image_at_the_bottom",
|
||||
}
|
||||
```
|
||||
|
||||
The [VMS pages repository](https://gitea.psi.ch/lin-midas-pages/vms_pages)
|
||||
has an example (beamline image in pages/Beamline_overview_bottom.png, which is placed
|
||||
next to Beamline_elements.html by CMakeLists.txt).
|
||||
has an example.
|
||||
|
||||
## Contact
|
||||
|
||||
|
||||
@@ -940,30 +940,41 @@
|
||||
|
||||
}
|
||||
|
||||
// Image hooks on the right and on the bottom of the table
|
||||
// Add an image only if the manifest says it exists
|
||||
fetch("optional_images.json")
|
||||
.then(response => response.json())
|
||||
.then(images => {
|
||||
|
||||
addOptionalImage(
|
||||
"beamlineOverviewHookRight",
|
||||
images.right,
|
||||
"Beamline overview"
|
||||
);
|
||||
|
||||
addOptionalImage(
|
||||
"beamlineOverviewHookBottom",
|
||||
images.bottom,
|
||||
"Beamline overview"
|
||||
);
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
// No optional images configured
|
||||
});
|
||||
|
||||
|
||||
function addOptionalImage(hookId, filename, alt = "") {
|
||||
const hook = document.getElementById(hookId);
|
||||
if (!hook) return;
|
||||
if (!hook || !filename) return;
|
||||
|
||||
const img = new Image();
|
||||
img.src = filename;
|
||||
img.alt = alt;
|
||||
|
||||
img.onload = () => hook.appendChild(img);
|
||||
img.onerror = () => {}; // Optional image not installed
|
||||
img.onerror = () => {}; // Safety fallback
|
||||
}
|
||||
|
||||
addOptionalImage(
|
||||
"beamlineOverviewHookRight",
|
||||
"Beamline_overview_right.png",
|
||||
"Beamline overview"
|
||||
);
|
||||
|
||||
addOptionalImage(
|
||||
"beamlineOverviewHookBottom",
|
||||
"Beamline_overview_bottom.png",
|
||||
"Beamline overview"
|
||||
);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
Reference in new issue
Block a user