This update adds many features:
It adds more objects, including objects with image backgrounds.
The size of the object can be changed with key presses, with the text scrolling to fit the new size.
The object can be moved with the mouse.
A popup displays the code, so it can be pasted into a new HTML document.
On a key press the page can be reset.
A rounded border can be created.
Here is an example of a key resized object with a rounded image border:
Here is a popup with the code. The first line has the new position and size:
In this case the object was not moved after resizing, so there are no new position values.
To try click here
Here is the code:
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head profile=”http://gmpg.org/xfn/11″>
<title>Heart</title>
<style>
body {margin-left:0;margin-right:0;font:normal normal 700 18px Arial;}
a{ text-decoration: }:link { color: rgb(0, 0, 255) }:visited {color :rgb(100, 0,100) }:hover { }:active { }
input{width: 100px}
#ch1{width: 15px}
</style>
</head>
<body>
<di id=”frame” style=”position: absolute; top: 0; width: 100%; height: 100%; left: 0; “></di>
<di id=”cp” style = “position: absolute; left: 50%; margin-left: -35%; top: 10px; height: 500px; width: 70%; background: #eeeeee; white-space: pre-wrap; padding: 0 0 0 20px”>
<select id=”func” name=”func” onchange=’go();’><option >Choose Object</option><option >heart</option><option >sunburst</option></option><option >leaf</option><option >pumpkin</option><option >bird</option><option >butterfly</option><option >gingerbread</option></select> <input type=”text” id=”width” name=”width” value=”width” /> <input type=”text” id=”height” name=”height” value=”height” /> <input type=”text” id=”left” name=”left” value=”left” /> <input type=”text” id=”top” name=”top” value=”top” /> Object BKG<input type=’color’ id=’color1′ value= simple color /> <input type=”checkbox” id=”ch1″ name=”ch1″ value=” ” />rounded
<textarea id=”ta1″ name=”ta1″ rows = “25” cols = “98”></textarea>
<textarea id=”ta2″ name=”ta2″ style=”position: absolute; visibility: hidden; left: 20px; top: 20px; width: 70%; height: 60%”></textarea>
</di>
var tp = “”; var wd = “”; var ht = “”; var pd = “”; var pd1 = 0; var pd2 = 0; var pd3 = 0; var pd4 = 0; var lft = screen.width/2 + “px”; var clr = “”;
var objwd = 500; var objht = 500; var lft2 = screen.width/2; var tp2 = 20; var ob = “”; var wd2 = “”; var ht2 = “”; var tp2a = “”; var lft2a = “”; var marg2 = “”;
var txt = “”; var mv = false; var txt2 = “”; var mvd = false;
var posX;var posY;
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.ondblclick = getMouse2;
document.onmousemove = getMouseXY;
document.onkeyup = key;
function key(e) {
if (e.keyCode == 27) {
location.reload();
}
if (e.keyCode == 18) {
txt = txt.replace(wd2, document.getElementById(“obj1”).style.width);
txt = txt.replace(ht2, document.getElementById(“obj1”).style.height);
txt = txt.replace(lft2a, document.getElementById(“obj1”).style.left);
txt = txt.replace(tp2a, document.getElementById(“obj1”).style.top);
if (mvd) txt = txt.replace(marg2, “0”);
txt = txt.replace(txt2, document.getElementById(“obj1”).innerHTML);
document.getElementById(“ta2”).style.visibility = “visible”;
document.getElementById(“ta2″).value = objwd + ” ” + objht + ” ” + posX + ” ” + (posY – 22 + “\n\n” + txt);
mv = false;
document.getElementById(“obj1”).style.visibility = “hidden”;
document.getElementById(“ta2”).focus();
document.getElementById(“ta2”).select();
}
if (e.keyCode == 39) {
objwd += 4;
lft2 -= 2;
document.getElementById(“obj1”).style.left = lft2 + “px”;
document.getElementById(“obj1”).style.width = objwd + “px”;
document.getElementById(“obj1”).style.height = objht + “px”;
if (ob == “heart” || ob == “sunburst” || ob == “leaf”) {
wd = (objwd – pd2 – pd4)+ “px”;
document.getElementById(“heart”).style.width = wd;
document.getElementById(“im”).style.width = “100%”;
}
}
if (e.keyCode == 37) {
objwd -= 4;
lft2 += 2;
document.getElementById(“obj1”).style.left = lft2 + “px”;
document.getElementById(“obj1”).style.width = objwd + “px”;
document.getElementById(“obj1”).style.height = objht + “px”;
if (ob == “heart” || ob == “sunburst” || ob == “leaf”) {
wd = (objwd – pd2 – pd4)+ “px”;
document.getElementById(“heart”).style.width = wd;
document.getElementById(“im”).style.width = “100%”;
}
}
if (e.keyCode == 40) {
objht -= 4;
tp2 += 2;
document.getElementById(“obj1”).style.top= tp2 + “px”;
document.getElementById(“obj1”).style.width = objwd + “px”;
document.getElementById(“obj1”).style.height = objht + “px”;
if (ob == “heart” || ob == “sunburst” || ob == “leaf”) {
ht = (objht – pd1) + “px”;
document.getElementById(“heart”).style.height = ht;
document.getElementById(“im”).style.width = “100%”;
}
}
if (e.keyCode == 38) {
objht += 4;
tp2 -= 2;
document.getElementById(“obj1”).style.top= tp2 + “px”;
document.getElementById(“obj1”).style.width = objwd + “px”;
document.getElementById(“obj1”).style.height = objht + “px”;
if (ob == “heart” || ob == “sunburst” || ob == “leaf”) {
ht = (objht – pd1) + “px”;
document.getElementById(“heart”).style.height = ht;
document.getElementById(“im”).style.width = “100%”;
}
}
}
function getMouse2(e) {
if (! mv) {
mv = true;
} else {
mv = false;
}
}
function getMouseXY(e) {
if (mv) {
mvd = true;
document.getElementById(“obj1”).style.marginLeft = “0”;
if (IE) {
posX = event.clientX + document.body.scrollLeft;
posY = event.clientY + document.body.scrollTop;
}
else {
posX = e.pageX -10;
posY = e.pageY – 50;
}
lft2 = posX;
document.getElementById(“obj1”).style.left = posX + “px”;
document.getElementById(“obj1”).style.top = posY + “px”;
}
objmarg = 0;
}
function go() {
mv = false;
ob = document.getElementById(“func”).value;
if (document.getElementById(“top”).value != “top”) document.getElementById(“frame”).style.top = parseInt(document.getElementById(“top”).value) + “px”;
if (document.getElementById(“ta1”).value != “”) txt = document.getElementById(“ta1”).value;
// document.getElementById(“cp”).style.visibility = “hidden”;
if (ob == “heart”) heartobj(“heartobj.gif”, “#ff5588” );
if (ob == “sunburst”) heartobj(“sunburstobj.gif”, “#ffffcc”);
if (ob == “leaf”) heartobj(“leafobj.gif”, “#ffffcc”,);
if (ob == “pumpkin”) pumpkinobj(“pumpkin-bk.png”, “#ffdd99”);
if (ob == “bird”) pumpkinobj(“robinbk.png”, “#eeeeee”);
if (ob == “butterfly”) pumpkinobj(“butterflybk.png”, “#eeffe8”);
if (ob == “gingerbread”) pumpkinobj(“gingerbreadbk.png”, “#ffcc99”);
document.getElementById(“cp”).style.visibility = “hidden”;
}
function heartobj(imag, bkgd) {
if (txt == “” && ob == “heart”) txt = “This is a test to see about the creation of a heart shaped object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
if (txt == “” && ob == “sunburst”) txt = “This is a test to see about the creation of a sunburst shaped object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
if (txt == “” && ob == “leaf”) txt = “This is a test to see about the creation of a leaf bordered object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
if (document.getElementById(“color1”).value == “#000000”) document.getElementById(“color1”).value = bkgd;
if (document.getElementById(“width”).value != “width”) objwd = parseInt(document.getElementById(“width”).value);
if (document.getElementById(“height”).value != “height”) objht = parseInt(document.getElementById(“height”).value); var objmarg = -objwd/2;
if (ob == “heart”) pd1 = objht / 10 + 30; pd2 = objwd / 10; pd3 = 0; pd4 = objwd / 10;
if (ob == “sunburst”) pd1 = objht / 3.2; pd2 = objwd / 10; pd3 = 0; pd4 = objwd / 10;
if (ob == “leaf”) pd1 = .1*objht + 10; pd2 = .1 *objwd +10; pd3 = 0; pd4 = .1*objwd + 10;
wd = (objwd – pd2 – pd4)+ “px”; tp = “20px”; ht = (objht – pd1) + “px”; pd = pd1 + “px ” + pd2 + “px ” + pd3 + “px ” + pd4 + “px”;
clr = document.getElementById(“color1”).value;
if (document.getElementById(“left”).value != “left”) {
lft = document.getElementById(“left”).value + “px”;
lft2 = parseInt(document.getElementById(“left”).value);
objmarg = 0;
}
document.getElementById(“frame”).innerHTML += ” + txt + ‘ ‘;
txt2 = document.getElementById(“obj1”).innerHTML;
txt = document.getElementById(“frame”).innerHTML;
wd2 = document.getElementById(“obj1”).style.width;
ht2 = document.getElementById(“obj1”).style.height;
lft2a = document.getElementById(“obj1”).style.left;
tp2a = document.getElementById(“obj1”).style.top;
marg2 = document.getElementById(“obj1”).style.marginLeft;
}
function pumpkinobj(imag, bkgd) {
objmarg = -objwd/2;
if (document.getElementById(“color1”).value == “#000000” && ob == “pumpkin”) document.getElementById(“color1”).value = bkgd;
if (document.getElementById(“color1”).value == “#000000” && ob == “bird”) document.getElementById(“color1”).value = bkgd;
if (document.getElementById(“color1”).value == “#000000” && ob == “butterfly”) document.getElementById(“color1”).value = bkgd;
if (document.getElementById(“color1”).value == “#000000” && ob == “gingerbread”) document.getElementById(“color1”).value = bkgd;
if (document.getElementById(“width”).value != “width”) objwd = parseInt(document.getElementById(“width”).value);
if (document.getElementById(“height”).value != “height”) objht = parseInt(document.getElementById(“height”).value);
if (document.getElementById(“left”).value != “left”) {
lft = document.getElementById(“left”).value + “px”;
objmarg = 0;
}
clr = document.getElementById(“color1”).value;
if (txt == “” && ob == “pumpkin”) txt = “This is a test to see about the creation of a pumpkin bordered object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
if (txt == “” && ob == “bird”) txt = “This is a test to see about the creation of a bird bordered object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
if (txt == “” && ob == “butterfly”) txt = “This is a test to see about the creation of a butterfly bordered object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
if (txt == “” && ob == “gingerbread”) txt = “This is a test to see about the creation of a gingerbread bordered object to be used in HTML. I will continue entering text until I get to where I want to go.
There will now be a break and the text will continue further.”;
document.getElementById(“frame”).innerHTML += ” + txt + ”;
if (document.getElementById(“ch1”).checked) {
document.getElementById(“obj1”).style.borderRadius = “30px 30px 30px 30px”;
}
txt2 = document.getElementById(“obj1”).innerHTML;
txt = document.getElementById(“frame”).innerHTML;
wd2 = document.getElementById(“obj1”).style.width;
ht2 = document.getElementById(“obj1”).style.height;
lft2a = document.getElementById(“obj1”).style.left;
tp2a = document.getElementById(“obj1”).style.top;
marg2 = document.getElementById(“obj1”).style.marginLeft;
}
</body></html>
mouse and key listeners are initiated:
var posX;var posY;
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.ondblclick = getMouse2;
document.onmousemove = getMouseXY;
document.onkeyup = key;
Arrow keys are used for resizing. The left arrow reduces the width:
if (e.keyCode == 37) {
objwd -= 4;
lft2 += 2;
document.getElementById(“obj1”).style.left = lft2 + “px”;
document.getElementById(“obj1”).style.width = objwd + “px”;
document.getElementById(“obj1”).style.height = objht + “px”;
if (ob == “heart” || ob == “sunburst” || ob == “leaf”) {
wd = (objwd – pd2 – pd4)+ “px”;
document.getElementById(“heart”).style.width = wd;
document.getElementById(“im”).style.width = “100%”;
}
}
To keep from changing the relative position, the left is simultaneously changed with the width;
The other arrow keys work similarly.
On hitting the alt key, a string, txt receives the new size and position values and if the object has been moved, the centering value is removed:
if (e.keyCode == 18) {
txt = txt.replace(wd2, document.getElementById(“obj1”).style.width);
txt = txt.replace(ht2, document.getElementById(“obj1”).style.height);
txt = txt.replace(lft2a, document.getElementById(“obj1”).style.left);
txt = txt.replace(tp2a, document.getElementById(“obj1”).style.top);
if (mvd) txt = txt.replace(marg2, “0”);
txt = txt.replace(txt2, document.getElementById(“obj1”).innerHTML);
document.getElementById(“ta2”).style.visibility = “visible”;
document.getElementById(“ta2″).value = objwd + ” ” + objht + ” ” + posX + ” ” + (posY – 22 + “\n\n” + txt);
mv = false;
document.getElementById(“obj1”).style.visibility = “hidden”;
document.getElementById(“ta2”).focus();
document.getElementById(“ta2”).select();
}
The popup is made visible and given the new values.
The function getMouse2(e), called by a double click, toggles the movement of the object:
document.ondblclick = getMouse2;
function getMouse2(e) {
if (! mv) {
mv = true;
} else {
mv = false;
}
}
If mv is true the object is moved by changing the mouse position; dragging is not necessary:
function getMouseXY(e) {
if (mv) {
mvd = true;
document.getElementById(“obj1”).style.marginLeft = “0”;
if (IE) {
posX = event.clientX + document.body.scrollLeft;
posY = event.clientY + document.body.scrollTop;
}
else {
posX = e.pageX -10;
posY = e.pageY – 50;
}
lft2 = posX;
document.getElementById(“obj1”).style.left = posX + “px”;
document.getElementById(“obj1”).style.top = posY + “px”;
}
objmarg = 0;
}
The moving continues until there is another double click.
As before, clicking the button starts the drawing.