Skip to content
Snippets Groups Projects
Commit 71131d3e authored by Dominic Meiser's avatar Dominic Meiser Committed by Thomas Schneider
Browse files

Make iframe previews clickable

And thanks JavaScript and iframes for being so annoying.
parent c3656e32
No related branches found
No related tags found
1 merge request!3A bunch of design stuff
...@@ -217,6 +217,7 @@ main { ...@@ -217,6 +217,7 @@ main {
.preview { .preview {
width: 15rem; width: 15rem;
cursor: pointer;
} }
img { img {
......
import './main.less'; import './main.less';
console.log("Hello World");
function onInputHandler(event: Event) { function onInputHandler(event: Event) {
const preview = document.getElementById('preview') as HTMLIFrameElement; const preview = document.getElementById('preview') as HTMLIFrameElement;
const previewDoc = preview.contentDocument as Document; const previewDoc = preview.contentDocument as Document;
...@@ -12,9 +10,30 @@ function onInputHandler(event: Event) { ...@@ -12,9 +10,30 @@ function onInputHandler(event: Event) {
window.addEventListener("load", () => { window.addEventListener("load", () => {
if (document.getElementById('preview')) { if (document.getElementById('preview')) {
for (let el of document.getElementsByClassName('input-dispatch')) { for (const el of document.getElementsByClassName('input-dispatch')) {
console.log(el); console.log(el);
el.addEventListener('input', onInputHandler); el.addEventListener('input', onInputHandler);
} }
for (const op of document.querySelectorAll('.option .preview')) {
console.log(op);
const input_id = (op as HTMLElement).dataset.for;
if (!input_id) {
console.error("Missing data-for attribute for", op);
continue;
}
const input = document.getElementById(input_id);
if (!input || input === null) {
console.error("Unable to find input for", op);
continue;
}
const handler = (_: Event) => {
console.log("clicked");
(input as HTMLInputElement).checked = true;
};
op.addEventListener('click', handler);
(op as HTMLIFrameElement).contentDocument?.addEventListener('click', handler);
}
} }
}); });
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
class="preview option-border" class="preview option-border"
src="{{ url_for('instance.sample_html', template=t.name) }}" src="{{ url_for('instance.sample_html', template=t.name) }}"
id="template-preview:{{ t.name }}" id="template-preview:{{ t.name }}"
data-for="template:{{ t.name }}"
> >
</iframe> </iframe>
<label for="template:{{ t.name }}" class="preview-label"> <label for="template:{{ t.name }}" class="preview-label">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment