@@ -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 = `[](${ 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