Skip to content

Commit 440dd6c

Browse files
authored
feat(demo): add html output to demo site (#114)
1 parent 274274a commit 440dd6c

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/demo/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ input:focus:invalid {
238238
border-radius: 2px;
239239
}
240240

241-
.output .md {
241+
.output .code-container {
242242
background: var(--border);
243243
border-radius: 6px;
244244
padding: 12px 16px;

src/demo/index.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,27 @@ function gtag() {
114114
Show border
115115
</label>
116116

117-
<h2>Markdown</h2>
118-
<div class="md">
119-
<code></code>
117+
<div>
118+
<h2>Markdown</h2>
119+
<div class="code-container md">
120+
<code></code>
121+
</div>
122+
123+
<button class="copy-button btn tooltip" onclick="clipboard.copy(this);" onmouseout="tooltip.reset(this);" disabled>
124+
Copy To Clipboard
125+
</button>
120126
</div>
121127

122-
<button class="copy-button btn tooltip" onclick="clipboard.copy(this);" onmouseout="tooltip.reset(this);" disabled>
123-
Copy To Clipboard
124-
</button>
128+
<div>
129+
<h2>HTML</h2>
130+
<div class="code-container html">
131+
<code></code>
132+
</div>
133+
134+
<button class="copy-button btn tooltip" onclick="clipboard.copy(this);" onmouseout="tooltip.reset(this);" disabled>
135+
Copy To Clipboard
136+
</button>
137+
</div>
125138
</div>
126139
</div>
127140

src/demo/js/script.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let preview = {
2323
],
2424
// update the preview
2525
update: function () {
26-
const copyButton = document.querySelector(".copy-button");
26+
const copyButtons = document.querySelectorAll(".copy-button");
2727
// get parameter values from all .param elements
2828
const params = Array.from(document.querySelectorAll(".param:not([data-index])")).reduce(
2929
(acc, next) => {
@@ -40,7 +40,7 @@ let preview = {
4040
const lineInputs = Array.from(document.querySelectorAll(".param[data-index]"));
4141
// disable copy button if any line contains semicolon
4242
if (lineInputs.some((el) => el.value.indexOf(";") >= 0)) {
43-
return copyButton.disabled = "true";
43+
return copyButtons.forEach((el) => el.disabled = true);
4444
}
4545
// add lines to parameters
4646
params.lines = lineInputs
@@ -61,19 +61,22 @@ let preview = {
6161
const demoImageURL = `/?${query}`;
6262
const repoLink = "https://git.io/typing-svg";
6363
const md = `[![Typing SVG](${imageURL})](${repoLink})`;
64+
const html = `<a href="${repoLink}"><img src="${imageURL}" alt="Typing SVG" /></a>`;
6465
// don't update if nothing has changed
6566
const mdElement = document.querySelector(".md code");
67+
const htmlElement = document.querySelector(".html code");
6668
const image = document.querySelector(".output img");
6769
if (mdElement.innerText === md) {
6870
return;
6971
}
7072
// update image preview
7173
image.src = demoImageURL;
7274
image.classList.add("loading");
73-
// update markdown
75+
// update markdown and html
7476
mdElement.innerText = md;
77+
htmlElement.innerText = html;
7578
// disable copy button if no lines are filled in
76-
copyButton.disabled = !params.lines.length;
79+
copyButtons.forEach((el) => el.disabled = !params.lines.length);
7780
},
7881
addLine: function () {
7982
const parent = document.querySelector(".lines");
@@ -166,7 +169,7 @@ let clipboard = {
166169
copy: function (el) {
167170
// create input box to copy from
168171
const input = document.createElement("input");
169-
input.value = document.querySelector(".md code").innerText;
172+
input.value = el.parentElement.querySelector("code").innerText;
170173
document.body.appendChild(input);
171174
// select all
172175
input.select();

0 commit comments

Comments
 (0)