Add caption to output
This commit is contained in:
parent
1fc9460074
commit
32ed10cbe7
59
index.html
59
index.html
@ -6,8 +6,10 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
max-width: 70em;
|
max-width: 50em;
|
||||||
|
margin: 1.5em auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
@ -22,6 +24,15 @@
|
|||||||
width: 10em;
|
width: 10em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vanish {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#print [id^=caption-] {
|
||||||
|
text-align: center;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
#print {
|
#print {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
@ -59,7 +70,8 @@
|
|||||||
to 3.
|
to 3.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
The target <strong>will not</strong> fit on US letter paper if <em>Actual distance</em> is more than ~35% of <em>Simulated distance</em>.
|
The target <strong>will not</strong> fit on US letter paper if <em>Actual distance</em> is more than ~35% of
|
||||||
|
<em>Simulated distance</em>.
|
||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>
|
<p>
|
||||||
@ -68,6 +80,13 @@
|
|||||||
<p>
|
<p>
|
||||||
<label>Actual distance<input id="actual-range" type="number" value="3"></label>
|
<label>Actual distance<input id="actual-range" type="number" value="3"></label>
|
||||||
</p>
|
</p>
|
||||||
|
<fieldset id="caption-settings">
|
||||||
|
<legend>Caption</legend>
|
||||||
|
<label><input type="radio" name="caption-pos" value="none" checked>None</label>
|
||||||
|
<label><input type="radio" name="caption-pos" value="above">Above</label>
|
||||||
|
<label><input type="radio" name="caption-pos" value="below">Below</label>
|
||||||
|
<p><label>Text<input id="caption-input"></label></p>
|
||||||
|
</fieldset>
|
||||||
<fieldset role="radiogroup" id="target-styles">
|
<fieldset role="radiogroup" id="target-styles">
|
||||||
<legend>Target style</legend>
|
<legend>Target style</legend>
|
||||||
|
|
||||||
@ -91,8 +110,11 @@
|
|||||||
<button id="print-button">Print</button>
|
<button id="print-button">Print</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="print">
|
<div id="print">
|
||||||
|
<h1 id="caption-above"></h1>
|
||||||
<img class="target">
|
<img class="target">
|
||||||
|
<h1 id="caption-below"></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -104,7 +126,7 @@
|
|||||||
const updateScale = () => {
|
const updateScale = () => {
|
||||||
let scale = actualRange.value / simulatedRange.value;
|
let scale = actualRange.value / simulatedRange.value;
|
||||||
target.style.width = target.naturalWidth * scale + "mm";
|
target.style.width = target.naturalWidth * scale + "mm";
|
||||||
}
|
};
|
||||||
simulatedRange.addEventListener("change", updateScale);
|
simulatedRange.addEventListener("change", updateScale);
|
||||||
actualRange.addEventListener("change", updateScale);
|
actualRange.addEventListener("change", updateScale);
|
||||||
target.addEventListener("load", updateScale);
|
target.addEventListener("load", updateScale);
|
||||||
@ -117,10 +139,39 @@
|
|||||||
target.src = src;
|
target.src = src;
|
||||||
};
|
};
|
||||||
|
|
||||||
document.querySelectorAll("#target-styles label").forEach((label) => {
|
document.querySelectorAll("#target-styles label").forEach(label => {
|
||||||
label.addEventListener("change", updateTargetStyle);
|
label.addEventListener("change", updateTargetStyle);
|
||||||
});
|
});
|
||||||
updateTargetStyle();
|
updateTargetStyle();
|
||||||
|
|
||||||
|
let captionInput = document.getElementById("caption-input");
|
||||||
|
let captionAbove = document.getElementById("caption-above");
|
||||||
|
let captionBelow = document.getElementById("caption-below");
|
||||||
|
const updateCaptionPosition = () => {
|
||||||
|
let value = document.querySelector("#caption-settings input[name=caption-pos]:checked").value;
|
||||||
|
captionInput.disabled = value === "none";
|
||||||
|
|
||||||
|
if (value === "above") {
|
||||||
|
captionAbove.classList.remove("vanish");
|
||||||
|
captionBelow.classList.add("vanish");
|
||||||
|
} else if (value === "below") {
|
||||||
|
captionAbove.classList.add("vanish");
|
||||||
|
captionBelow.classList.remove("vanish");
|
||||||
|
} else {
|
||||||
|
captionAbove.classList.add("vanish");
|
||||||
|
captionBelow.classList.add("vanish");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const updateCaptionText = () => {
|
||||||
|
captionAbove.innerText = captionBelow.innerText = captionInput.value;
|
||||||
|
}
|
||||||
|
document.querySelectorAll("#caption-settings input[name=caption-pos]").forEach(radio => {
|
||||||
|
radio.addEventListener("change", updateCaptionPosition);
|
||||||
|
});
|
||||||
|
captionInput.addEventListener("change", updateCaptionText);
|
||||||
|
captionInput.addEventListener("keydown", updateCaptionText);
|
||||||
|
updateCaptionText();
|
||||||
|
updateCaptionPosition();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user