Wassup all, I'd like to share with you this script that I wrote. It's taken me about 20 minutes, but I think it's pretty cool (coming from a JS noob like myself)
Here, just copy and paste this into notepad, name it *.html, and open it in a browser. Don't use the source. The instructions and little generator is there also.
Oh yeah, the script is sort of a like a CMS auto-updating thing. I don't know how to describe it, take a look
Code:
<style type="text/css">
body {background:#000000;color:#ffffff;font-family:Arial;}
.editable {background:#888888;padding:10px;outline:none;border:2px dashed #ff0000;width:300px;margin:0px auto;}
h1 {text-align:center;}
</style>
<script type="text/javascript">
function updateit() {
var userInput = document.getElementById('demobox').innerHTML;
document.getElementById('examplefield').innerHTML = userInput;
document.getElementById('examplefield2').value = userInput;
}
setInterval("updateit()",1);
function updateit2() {
var toShow = document.getElementById('dS').value;
if (toShow=="tag"){document.getElementById('userCode').innerHTML = "<script type=\"text/javascript\"><br />function updateit() {<br />var userInput = document.getElementById('demobox').innerHTML;<br />document.getElementById('examplefield').innerHTML = userInput;<br />}<br />setInterval(\"updateit()\",1);<br /></script><br /><div id=\"demobox\" class=\"editable\" onclick=\"javascript: this.contentEditable='true';this.style.border='2px solid #ff0000';void 0;\" onblur=\"javascript: this.style.border='none';\">Click inside this Div and edit me!</div><br /><i><!---The following HTML is optional, displays contents of editable DIV---></i><br /><b id=\"examplefield\"></b>";}
else if (toShow=="input"){document.getElementById('userCode').innerHTML = "<script type=\"text/javascript\"><br />function updateit() {<br />var userInput = document.getElementById('demobox').innerHTML;<br />document.getElementById('examplefield2').value = userInput;<br />}<br />setInterval(\"updateit()\",1);<br /></script><br /><div id=\"demobox\" class=\"editable\" onclick=\"javascript: this.contentEditable='true';this.style.border='2px solid #ff0000';void 0;\" onblur=\"javascript: this.style.border='none';\">Click inside this Div and edit me!</div><br /><i><!---The following HTML is optional, displays contents of editable DIV---></i><br /><input type=\"text\" id=\"examplefield2\" />";}
else {document.getElementById('userCode').innerHTML = "Your JavaScript code will appear here!";}
}
</script>
<div style="width:90%;background:#111111;padding:30px;margin:0px auto;">
<h1>Demo</h1>
<div id="demobox" class="editable" onclick="javascript: this.contentEditable='true';this.style.border='2px solid #ff0000';void 0;" onblur="javascript: this.style.border='2px dashed #ff0000';">Click inside this Div and edit me!</div>
<h1>Usage Example</h1>
<p>For this to be actually USEFUL in a CMS, you can easily grab the contents of it by doing this:</p>
<em>Start typing in the above box and the content below will change automatically!</em>
<hr /><br />Regular Tag: <b id="examplefield"></b><br />
Input box (Stretched): <input type="text" style="width:700px;" id="examplefield2" /> <em>Try typing '&' into the DIV above, it escapes it for you, too!</em>
<p>A good note is that you can also not let the user edit the input box, as you can see above. Try to type in that ↑, you can't! The input box refreshes itself every 0.001 (or something) seconds!</p>
<h1>Get the code!</h1>
<p>Want it? You can have it! Below is the relevant code you'll need to make this work for your site!</p>
<select id="dS">
<option value="none" disabled="disabled"> -- Select One -- </option>
<option value="tag">Regular Tag</option>
<option value="input">Input Box (Form)</option>
</select><input type="button" onclick="updateit2()" value="Get Code" />
<p id="userCode">Your JavaScript code will appear here!</p>
</div>
Hope you like it ! 
|