diff --git a/src/js/script.js b/src/js/script.js index 48dc9d1..18724da 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -18,11 +18,16 @@ let externalQuotesValue = document.querySelector(`.options__input:checked`).valu let quotes = getQuotes(); const buttonExample = document.querySelector(`.button-example`); +const textareaState = { + isExmaple: false, + value: `` +}; // Textarea Actions // ---------------------------------------- initTextarea.oninput = function () { + textareaState.value = this.value; getResults(); }; @@ -31,12 +36,16 @@ resultTextarea.oninput = function () { .replace(/background-image:\s{0,}url\(/, ``) .replace(/["']{0,}data:image\/svg\+xml,/, ``) .replace(/["']\);{0,}$/, ``); - initTextarea.value = decodeURIComponent(value); + + const decodedValue = decodeURIComponent(value); + textareaState.value = decodedValue; + initTextarea.value = decodedValue; getResults(); }; function getResults () { if (!initTextarea.value) { + resultTextarea.value = ``; resultCssTextarea.value = ``; resultDemo.setAttribute(`style`, ``); return; @@ -79,14 +88,21 @@ quotesInputs.forEach(input => { // ---------------------------------------- buttonExample.addEventListener(`click`, () => { - initTextarea.value = ` - - - - - - -`; + if (textareaState.isExmaple) { + initTextarea.value = textareaState.value; + textareaState.isExmaple = false; + } else { + initTextarea.value = ` + + + + + + + `; + textareaState.isExmaple = true; + } + getResults(); });