From 6091131e957bc6c5151b8065d68002c6f3f7e0be Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Thu, 28 Jul 2022 09:42:11 -0600 Subject: [PATCH] feat(demo): add html output to demo site --- src/demo/css/style.css | 2 +- src/demo/index.php | 25 +++++++++++++++++++------ src/demo/js/script.js | 13 ++++++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/demo/css/style.css b/src/demo/css/style.css index 1b628c8d..fa633e18 100644 --- a/src/demo/css/style.css +++ b/src/demo/css/style.css @@ -238,7 +238,7 @@ input:focus:invalid { border-radius: 2px; } -.output .md { +.output .code-container { background: var(--border); border-radius: 6px; padding: 12px 16px; diff --git a/src/demo/index.php b/src/demo/index.php index 1aa54cf1..1d86dec3 100644 --- a/src/demo/index.php +++ b/src/demo/index.php @@ -114,14 +114,27 @@ function gtag() { Show border -

Markdown

-
- +
+

Markdown

+
+ +
+ +
- +
+

HTML

+
+ +
+ + +
diff --git a/src/demo/js/script.js b/src/demo/js/script.js index f30e3587..32b251e3 100644 --- a/src/demo/js/script.js +++ b/src/demo/js/script.js @@ -23,7 +23,7 @@ let preview = { ], // update the preview update: function () { - const copyButton = document.querySelector(".copy-button"); + const copyButtons = document.querySelectorAll(".copy-button"); // get parameter values from all .param elements const params = Array.from(document.querySelectorAll(".param:not([data-index])")).reduce( (acc, next) => { @@ -40,7 +40,7 @@ let preview = { const lineInputs = Array.from(document.querySelectorAll(".param[data-index]")); // disable copy button if any line contains semicolon if (lineInputs.some((el) => el.value.indexOf(";") >= 0)) { - return copyButton.disabled = "true"; + return copyButtons.forEach((el) => el.disabled = true); } // add lines to parameters params.lines = lineInputs @@ -61,8 +61,10 @@ let preview = { const demoImageURL = `/?${query}`; const repoLink = "https://git.io/typing-svg"; const md = `[![Typing SVG](${imageURL})](${repoLink})`; + const html = `Typing SVG`; // don't update if nothing has changed const mdElement = document.querySelector(".md code"); + const htmlElement = document.querySelector(".html code"); const image = document.querySelector(".output img"); if (mdElement.innerText === md) { return; @@ -70,10 +72,11 @@ let preview = { // update image preview image.src = demoImageURL; image.classList.add("loading"); - // update markdown + // update markdown and html mdElement.innerText = md; + htmlElement.innerText = html; // disable copy button if no lines are filled in - copyButton.disabled = !params.lines.length; + copyButtons.forEach((el) => el.disabled = !params.lines.length); }, addLine: function () { const parent = document.querySelector(".lines"); @@ -166,7 +169,7 @@ let clipboard = { copy: function (el) { // create input box to copy from const input = document.createElement("input"); - input.value = document.querySelector(".md code").innerText; + input.value = el.parentElement.querySelector("code").innerText; document.body.appendChild(input); // select all input.select();