mirror of
https://github.com/jstrieb/urlpages.git
synced 2024-12-22 13:52:15 +01:00
Clean up a bit
This commit is contained in:
parent
96449d541c
commit
9f3580396e
3 changed files with 64 additions and 37 deletions
|
@ -1,19 +1,13 @@
|
|||
/* 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);
|
||||
/**
|
||||
* editor/editor.js: the main code that runs what is referred to as the "editor"
|
||||
* in the documentation
|
||||
*/
|
||||
|
||||
document.getElementById("css").value = data["css"];
|
||||
document.getElementById("javascript").value = data["js"];
|
||||
document.getElementById("html").value = data["html"];
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
/***
|
||||
* Helper functions
|
||||
***/
|
||||
|
||||
/* Return the HTML string for the page */
|
||||
function getHTML(data) {
|
||||
|
@ -47,28 +41,10 @@ function getViewLink(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 = encodeURIComponent(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 download link
|
||||
document.getElementById("downloadLink").href = `data:text/html,${html}`
|
||||
|
||||
// Update the <iframe> to display the generated page
|
||||
window.frames[0].location.replace(`data:text/html,${html}`);
|
||||
}
|
||||
/***
|
||||
* Button press functions
|
||||
***/
|
||||
|
||||
|
||||
/* Set the TinyUrl form hidden 'url' field to the view URL */
|
||||
|
@ -104,3 +80,49 @@ function showCopyCodePrompt() {
|
|||
|
||||
window.prompt("Copy to clipboard: ", html)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Main procedure functions
|
||||
***/
|
||||
|
||||
/* 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();
|
||||
}
|
||||
|
||||
|
||||
/* 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 = encodeURIComponent(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 download link
|
||||
document.getElementById("downloadLink").href = `data:text/html,${html}`
|
||||
|
||||
// Update the <iframe> to display the generated page
|
||||
window.frames[0].location.replace(`data:text/html,${html}`);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
<form action="http://tinyurl.com/create.php" method="get" target="_blank">
|
||||
<input type="hidden" id="source" name="source" value="indexpage">
|
||||
<input type="hidden" name="url" id="url" />
|
||||
<button onclick="setCodeUrl()">Get Short Link to Editor</button>
|
||||
<button onclick="setViewUrl()">Get Short Link to Publish</button>
|
||||
<button onclick="setCodeUrl()">Short Link to Editor</button>
|
||||
<button onclick="setViewUrl()">Short Link to Publish</button>
|
||||
</form>
|
||||
<button><a id="getLinkLink" href="" target="_blank">Get Link to Publish</a></button>
|
||||
<button><a id="getLinkLink" href="" target="_blank">Long Link to Publish</a></button>
|
||||
<button onclick="showCopyCodePrompt()">Copy Code</button>
|
||||
<button><a id="downloadLink" href="" target="_blank" download="export.html">Download Code</a></button>
|
||||
</div>
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
<!-- index.html: Referred to as the "main page" in documentation -->
|
||||
|
||||
<noscript>JavaScript is required to convert the URL into a usable web page.</noscript>
|
||||
|
||||
<script type="text/javascript">
|
||||
if (window.location.hash) {
|
||||
// Try to get page data from the URL if possible
|
||||
var hash = window.location.hash.slice(1);
|
||||
var data = atob(hash);
|
||||
document.write(decodeURIComponent(data));
|
||||
} else {
|
||||
// Otherwise redirect to the editor
|
||||
window.location.replace("./editor");
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue