JSFiddle - React, Tailwind, and code Playground
by lid0
HTML
<!-- add to playground to allow tracking of changes.
//<DO NOT REMOVE>
parent.parent.postMessage(parent.location.hash,"*")
//</DO NOT REMOVE>
-->
<!--
After making changes to the playground.
click on "Copy Link" and paste/replace the content in the Template tag below
-->
<template...
CSS
.sfcContainer {
position: fixed;
top: 0px;
display: block;
width: 100%;
height: 25px;
background: #5a9faa;
}
.sfcLink {
top: 0px;
z-index: 100;
background: black;
color: white;
padding: 5px;
}
.sfcLink2 {
left: 0px;
top: 30px;
}
.sfcLink:hover {
background: #696969;
}
body {
margin: 0;
padding: 0;
height: 100%;
}
iframe {
margin-top: 20px;
;
width: 100%;
height: 95vh;
}
JavaScript
// NOTHING TO CHANGE HERE
// SEE HTML SECTION
// author liblib
var codeEl = document.getElementById('code');
var frm1 = document.getElementById("frm1")
function getCode() {
var codeFromTemplate = codeEl.innerHTML.trim();
if (codeFromTemplate[0] == "#") {
return "https://sfc.vuejs.org/" + codeFromTemplate
} else if (codeFromTemplate.startsWith("https://")) {
return codeFromTemplate;
} else {
alert("invalid code in template")
}
}
var sfcLink = document.getElementById("sfcLink")
var sfcLink2 = document.getElementById("sfcLink2")
sfcLink.addEventListener('click', function(evt) {
evt.preventDefault();
copyToClipboard(sfcLink.href)
alert("new playground link was copied to clipboard. dont forget to update template in js fiddle.")
sfcLink.innerHTML += " [copied to clipboard]"
setTimeout(function() {
sfcLink.innerHTML = "Link (edits " + changes + ")"
}, 700)
})
sfcLink2.addEventListener('click', function(evt) {
alert("DSADAS")
window.open(sfcLink.href, "_blank")
});
function refreshLink() {
if (changes > 0) {
sfcLink.innerHTML = "Link (edits " + changes + ")"
} else {
sfcLink.innerHTML = "Copy Link"
}
}
window.addEventListener("message", function(evt) {
//console.log(evt)
changes++;
codeEl.innerHTML = evt
sfcLink.href = "https://sfc.vuejs.org/" + evt.data
refreshLink()
})
var code = getCode()
frm1.src = code;
var changes = -1
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
// Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
return window.clipboardData.setData("Text", text);
} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge.
...