mirror of
https://github.com/jstrieb/urlpages.git
synced 2025-03-15 13:04:33 +01:00
Separate into index, script, and style file
This commit is contained in:
parent
60a3aa13d4
commit
ad4abcf43c
3 changed files with 114 additions and 116 deletions
67
editor/editor.js
Normal file
67
editor/editor.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* Run once when the page is loaded */
|
||||
function initialize() {
|
||||
// Get page data from the URL and load it into the boxes
|
||||
if (window.location.hash) {
|
||||
var b64 = window.location.hash.slice(1);
|
||||
var json = window.atob(b64);
|
||||
var data = JSON.parse(json);
|
||||
|
||||
document.getElementById("css").value = data["css"];
|
||||
document.getElementById("javascript").value = data["js"];
|
||||
document.getElementById("html").value = data["html"];
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/* Return the HTML string for the page */
|
||||
function getHTML(data) {
|
||||
// Generate an HTML page from the contents of each <textarea>
|
||||
var pageData =
|
||||
`
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
${data["css"]}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
${data["js"]}
|
||||
</scr` +
|
||||
// This has to be broken up because otherwise it is recognized as the main document's end script tag
|
||||
`ipt>
|
||||
</head>
|
||||
<body>
|
||||
${data["html"]}
|
||||
</body>
|
||||
`;
|
||||
|
||||
return pageData;
|
||||
}
|
||||
|
||||
|
||||
/* Return a link to view the page */
|
||||
function getViewLink(pageData) {
|
||||
return `../#${window.btoa(encodeURIComponent(pageData))}`;
|
||||
}
|
||||
|
||||
|
||||
/* Run each time a key is pressed on a text box */
|
||||
function update() {
|
||||
var data = {
|
||||
"css" : document.getElementById("css").value,
|
||||
"js" : document.getElementById("javascript").value,
|
||||
"html" : document.getElementById("html").value
|
||||
};
|
||||
|
||||
var html = getHTML(data);
|
||||
|
||||
// Save encoded page data to the URL
|
||||
window.location.hash = "#" + window.btoa(JSON.stringify(data));
|
||||
|
||||
// Update the URL for the "Get Link" button
|
||||
document.getElementById("getLinkLink").href = getViewLink(html);
|
||||
|
||||
// Update the <iframe> to display the generated page
|
||||
window.frames[0].location.replace(`data:text/html,${encodeURIComponent(html)}`);
|
||||
}
|
|
@ -2,126 +2,14 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Create and edit URL pages</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0px;
|
||||
box-sizing: border-box;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#textboxes {
|
||||
height: 40%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: none;
|
||||
width: 33.3333%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 60%;
|
||||
}
|
||||
|
||||
textarea, iframe {
|
||||
border: 0.5px solid;
|
||||
}
|
||||
|
||||
a, button {
|
||||
background: black;
|
||||
color: limegreen;
|
||||
text-decoration: none;
|
||||
padding: 2px 5px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#buttons {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
/* Run once when the page is loaded */
|
||||
function initialize() {
|
||||
// Get page data from the URL and load it into the boxes
|
||||
if (window.location.hash) {
|
||||
var b64 = window.location.hash.slice(1);
|
||||
var json = window.atob(b64);
|
||||
var data = JSON.parse(json);
|
||||
|
||||
document.getElementById("css").value = data["css"];
|
||||
document.getElementById("javascript").value = data["js"];
|
||||
document.getElementById("html").value = data["html"];
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/* Return the HTML string for the page */
|
||||
function getHTML(data) {
|
||||
// Generate an HTML page from the contents of each <textarea>
|
||||
var pageData =
|
||||
`
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
${data["css"]}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
${data["js"]}
|
||||
</scr` +
|
||||
// This has to be broken up because otherwise it is recognized as the main document's end script tag
|
||||
`ipt>
|
||||
</head>
|
||||
<body>
|
||||
${data["html"]}
|
||||
</body>
|
||||
`;
|
||||
|
||||
return pageData;
|
||||
}
|
||||
|
||||
|
||||
/* Return a link to view the page */
|
||||
function getViewLink(pageData) {
|
||||
return `../#${window.btoa(encodeURIComponent(pageData))}`
|
||||
}
|
||||
|
||||
|
||||
/* Run each time a key is pressed on a text box */
|
||||
function update() {
|
||||
var data = {
|
||||
"css" : document.getElementById("css").value,
|
||||
"js" : document.getElementById("javascript").value,
|
||||
"html" : document.getElementById("html").value
|
||||
};
|
||||
|
||||
var html = getHTML(data);
|
||||
|
||||
// Save encoded page data to the URL
|
||||
window.location.hash = "#" + window.btoa(JSON.stringify(data));
|
||||
|
||||
// Update the URL for the "Get Link" button
|
||||
document.getElementById("getLinkLink").href = getViewLink(html);
|
||||
|
||||
// Update the <iframe> to display the generated page
|
||||
window.frames[0].location.replace(`data:text/html,${encodeURIComponent(html)}`);
|
||||
}
|
||||
</script>
|
||||
<link rel="stylesheet" type="text/css" href="main.css">
|
||||
<script src="editor.js" type="text/javascript"></script>
|
||||
</head>
|
||||
|
||||
<body onload="initialize()">
|
||||
<div id="textboxes" onkeyup="update()">
|
||||
<!-- Unfortunately having these <textarea>s on one line is actually necessary to remove a tiny amount of horizontal space between them -->
|
||||
<!-- Unfortunately having these <textarea>s on one line is actually necessary
|
||||
to remove a tiny amount of horizontal space between them -->
|
||||
<textarea id="html" placeholder="HTML" rows="9"></textarea><textarea id="css" placeholder="CSS" rows="9"></textarea><textarea id="javascript" placeholder="JavaScript" rows="9"></textarea>
|
||||
</div>
|
||||
|
||||
|
|
43
editor/main.css
Normal file
43
editor/main.css
Normal file
|
@ -0,0 +1,43 @@
|
|||
* {
|
||||
margin: 0px;
|
||||
box-sizing: border-box;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#textboxes {
|
||||
height: 40%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: none;
|
||||
width: 33.3333%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 60%;
|
||||
}
|
||||
|
||||
textarea, iframe {
|
||||
border: 0.5px solid;
|
||||
}
|
||||
|
||||
a, button {
|
||||
background: black;
|
||||
color: limegreen;
|
||||
text-decoration: none;
|
||||
padding: 2px 5px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#buttons {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue