VML drawing board ② script--vmlgraph.js, xmltool.js_php basics

Source: Internet
Author: User
Tags abs visibility

Script
*************
* Vmlgraph.js
*************
var xo=0;
var yo=0;
var ox=80;
var oy=20;
var dx=0;
var dy=0;
var drawkey = false;
var ItemID = 0;
var shapeitemnum = 0;
var shapeitemx = 0;
var shapeitemy = 0;
var curveitemnum = 0;
var nodedelete = false;
var toolbarnum = 2; Preset tool number
var gradientx =-1;

function cursor (k) {
XO = Event.clientx-ox;
yo = Event.clienty-oy;
if (k && xo>=0 && yo>=0)
oxy.innerhtml = xo+ "," +YO;
Else
oxy.innerhtml = "";
if (Drawkey) {
Paint ();
view.innerhtml = tree (canvas.documentelement,0);
}
}

function Setovercolor (v) {
if (! Nodedelete) return;
V.mycolor = V.strokecolor;
if (V.strokecolor = = "Red")
V.strokecolor= ' #000000 ';
Else
V.strokecolor= ' #ff0000 ';
}
function Setoutcolor (v) {
if (! Nodedelete) return;
V.strokecolor = V.mycolor;
view.innerhtml = tree (canvas.documentelement,0);
}
function Deletenode (v) {
if (! Nodedelete) return;
var id = v.id;
For (I=0;i<canvas.selectnodes ("/*//*"). length;i++) {
var node = canvas.selectnodes ("/*//*") [i];
if (Node.getattribute ("id") = = ID) {
Canvas.documentelement.childnodes[0].removechild (node);
view.innerhtml = tree (canvas.documentelement,0);
Return
}
}
}

function setelement (node) {
Node.setattribute ("id") = ItemID;
Node.setattribute ("mycolor") = "#";
Node.setattribute ("onMouseOver") = "Setovercolor (this)";
Node.setattribute ("onmouseout") = "Setoutcolor (this)";
Node.setattribute ("onClick") = "Deletenode (this)";

var Subobjfield = canvas.createelement ("V:stroke");
Subobjfield.setattribute ("color") = Color1.fillcolor;
Subobjfield.setattribute ("dashstyle") = Dashstyle.dashstyle;
Node.appendchild (Subobjfield);
if (textbox.style.visibility = = "visible" && txt.value.length) {
var Subobjfield = canvas.createelement ("V:path");
Subobjfield.setattribute ("Textpathok") = "true";
Node.appendchild (Subobjfield);
var Subobjfield = canvas.createelement ("V:textpath");
Subobjfield.setattribute ("on") = "true";
Subobjfield.setattribute ("string") = Txt.value;
Subobjfield.setattribute ("style") = "font:normal normal normal 16pt ' Arial black '";
Node.appendchild (Subobjfield);
}
Canvas.documentelement.childnodes[0].appendchild (node);
}

function Mouse_down () {
Drawkey = true;
DX = XO;
dy = yo;
itemid++;
if (toolbarnum!= 7) shapeitemnum = 0;
Switch (toolbarnum) {
Case 3:
var objfield = canvas.createelement ("V:line");
Objfield.setattribute ("from") = xo+ "," +YO;
Objfield.setattribute ("to") = xo+ "," +YO;
Return setelement (Objfield);
Case 4:
if (Curveitemnum = = 0) {
Curveitemnum = 1;
var objfield = canvas.createelement ("V:curve");
Objfield.setattribute ("from") = xo+ "," +YO;
Objfield.setattribute ("to") = xo+ "," +YO;
Objfield.setattribute ("control1") = xo+ "," +YO;
Objfield.setattribute ("control2") = xo+ "," +YO;
var Subobjfield = canvas.createelement ("V:fill");
Subobjfield.setattribute ("opacity") = 0;
Objfield.appendchild (Subobjfield);
Return setelement (Objfield);
}
Return
Case 9:
var objfield = canvas.createelement ("V:polyline");
Objfield.setattribute ("points") = xo+ "," +yo+ "" +xo+ "," +yo ";
var Subobjfield = canvas.createelement ("V:fill");
Subobjfield.setattribute ("opacity") = 0;
Objfield.appendchild (Subobjfield);
Return setelement (Objfield);
Case 7:
if (Shapeitemnum = = 0) {
var objfield = canvas.createelement ("V:shape");
Objfield.setattribute ("style") = "width:500;" height:309 ";
Objfield.setattribute ("path") = "M" +xo+ "," +yo+ "L" +xo+ "," +YO;
Shapeitemx = XO;
Shapeitemy = yo;
}else {
Objfield = Canvas.documentelement.childnodes[0].lastchild;
Objfield.setattribute ("path") = Objfield.getattribute ("path") + "+xo+", "+YO;"
Return
}
shapeitemnum++;
Break
Case 5:
var objfield = canvas.createelement ("V:rect");
Break
Case 6:
var objfield = canvas.createelement ("V:roundrect");
Objfield.setattribute ("arcsize") = 0.2;
Break
Case 8:
var objfield = canvas.createelement ("V:oval");
Break
Case 10:
s = "";
s = tree (canvas.documentelement,1);
view.innerhtml = s;
Return
Defaule:
Drawkey = false;
Return
}
if (objfield) {
if (Toolbarnum!= 7)
Objfield.setattribute ("style") = "Left:" +xo+; Top: "+yo+"; width:0; height:0; ";
var Subobjfield = canvas.createelement ("V:fill");
Subobjfield.setattribute ("opacity") = gradientbar.opacity;
Subobjfield.setattribute ("angle") = Gradientbar.angle;
Subobjfield.setattribute ("type") = Gradientbar.type;
Subobjfield.setattribute ("color") = GradientBar.color.value;
Subobjfield.setattribute ("color2") = GradientBar.color2.value;
Subobjfield.setattribute ("colors") = GradientBar.colors.value;
Subobjfield.setattribute ("focusposition") = Gradientbar.focusposition;
Objfield.appendchild (Subobjfield);
Return setelement (Objfield);
}
Return
}

function Mouse_up () {
Drawkey = false;
if (Curveitemnum > 0) curveitemnum++;
if (Curveitemnum > 3) curveitemnum = 0;
if (Toolbarnum = = 7) {
if (Math.Abs (XO-SHAPEITEMX) < 2 && Math.Abs (Yo-shapeitemy) < 2) {
Shapeitemnum = 0;
Element = Canvas.documentelement.childnodes[0].lastchild;
var regerp =/[0-9]+,[0-9]+$/
var str = element.getattribute ("path");
Element.setattribute ("path") = Str.replace (Regerp, "x e");
view.innerhtml = tree (canvas.documentelement,0);
}
}
}

function Paint () {
Element = Canvas.documentelement.childnodes[0].lastchild;
var x0,y0,x1,y1;
x0 = Math.min (Dx,xo);
y0 = Math.min (dy,yo);
X1 = Math.max (DX,XO);
Y1 = Math.max (dy,yo);
var box = "Left:" +x0+; Top: "+y0+"; Width: "+ (x1-x0) +"; Height: "+ (Y1-Y0) +";
Switch (toolbarnum) {
Case 4:
if (Curveitemnum ==2) {
Element.setattribute ("control1") = xo+ "," +YO;
Element.setattribute ("control2") = Element.getattribute ("to");
Break
}
if (Curveitemnum ==3) {
Element.setattribute ("control2") = xo+ "," +YO;
Break
}
Case 3:
Element.setattribute ("to") = xo+ "," +YO;
Break
Case 7:
var regerp =/[0-9]+,[0-9]+$/
var str = element.getattribute ("path");
Element.setattribute ("path") = Str.replace (regerp,xo+ "," +yo);
Break
Case 5:
Case 6:
Case 8:
var regerp =/left.+height:[0-9]+;/
var str = element.getattribute ("style");
Element.setattribute ("style") = Str.replace (Regerp,box);
Break
Case 9:
var regerp =/[0-9]+,[0-9]+$/
var str = Element.getattribute ("points");
Element.setattribute ("points") = str+ "" +xo+ "," +YO;
Break
Defaule:
Break
}

}

function init () {
Tool_box_refresh (); Tool Bar Initial
view.innerhtml = tree (canvas.documentelement); Plot Area initial
color.innerhtml = Tree (tools.selectnodes ("*/colorbar") [0]); Color selection Initial
linebox.innerhtml = Tree (tools.selectnodes ("*/linebox") [0]); Line Style Selection Initial
gradientbox.innerhtml = Tree (tools.selectnodes ("*/gradient") [0]); Filling selection Initial
}

Draw Toolbar
function Tool_box_refresh () {
var buffer = "";
var i;
For (I=0;i<tools.selectnodes ("*/toolbar"). length;i++) {
var node = tools.selectnodes ("*/toolbar") [i];
var id = node.getattribute ("id");
Node.childnodes[0].setattribute ("onClick") = "Tool_box_select (" +id+ ", This.title)";
var Node1 = node.selectnodes ("*/v:rect") [0];
if (id = = Toolbarnum) {
Node1.setattribute ("fillcolor") = "#ffcccc"
Node1.setattribute ("strokecolor") = "#ff0000"
}else {
Node1.setattribute ("fillcolor") = "#ffffff"
Node1.setattribute ("strokecolor") = "#000000"
}
Buffer + = tree (node.childnodes[0]);
}
toolbox.innerhtml = buffer;
}

Tool selection
function Tool_box_select (v,t) {
var key = Toolbarnum;
Toolbarnum = v;
Tool_box_refresh ();
Hooke ();
if (v = = 7) {
if (key = = 7 && shapeitemnum > 0) {
Element = Canvas.documentelement.childnodes[0].lastchild;
var str = element.getattribute ("path");
Element.setattribute ("path") = str + "x e";
view.innerhtml = tree (canvas.documentelement,0);
Shapeitemnum = 0;
}
}
if (v = = 10)
if (textbox.style.visibility = = "hidden")
textbox.style.visibility = "visible";
Else
textbox.style.visibility = "hidden";
Nodedelete = false;
if (v = = 1) {
Nodedelete = true;
view.innerhtml = tree (canvas.documentelement,0);
}
}

Color selection
var setcolorkey = Color1;
function SetColor (c) {
var setcolorkey = Color1;
Setcolorkey.fillcolor = C;
}

function Gradientcolor (v) {
V.fillcolor = Color1.fillcolor;
Gradientrefresh ();
Return
var m = tools.documentElement.selectNodes ("/*/gradient//v:shape"). Length;
var node = tools.documentElement.selectNodes ("/*/gradient//v:shape");
for (i=0;i<m;i++) {
if (Node[i].getattribute ("id") = = v.id)
Node[i].setattribute ("fillcolor") = Color1.fillcolor;
}
Gradientrefresh ();
}
function Gradientpoint (v) {
if (Gradientx < 0)
Gradientx = Xo-508-parseint (v.style.left);
n = xo-508-gradientx;
if (n < 8) n = 8;
if (n > 108) n = 108;
V.style.left = n;
Gradientrefresh ();
}
function Anglepoint (v) {
Angle.style.left = Math.floor ((xo-516)/25) *25+8;
Gradientrefresh ();
}
function Opacitypoint (v) {
Opacity.style.left = Math.floor ((xo-516)/25) *25+8;
Gradientrefresh ();
}
function Settype (v) {
if (V.style.bordercolor = "BLACK")
V.style.bordercolor = "Red";
Else
V.style.bordercolor = "BLACK";
Gradientrefresh ();
}
function Setgradientx () {
Gradientx =-1;
}

function Gradientrefresh () {
var m = (parseint (gradient4.style.left)-parseint (gradient1.style.left));
var n1 = (parseint (gradient2.style.left)-parseint (gradient1.style.left))/m*100;
var N2 = (parseint (gradient3.style.left)-parseint (gradient1.style.left))/m*100;
GradientBar.color.value = Gradient1.fillcolor;
GradientBar.color2.value = Gradient4.fillcolor;
if (Type3.style.borderColor = "BLACK")
GradientBar.colors.value = ",";
Else
GradientBar.colors.value = n1 + "%" + Gradient2.fillcolor + "," + n2 + "%" + gradient3.fillcolor;
if (Type1.style.borderColor = "BLACK")
Gradientbar.type = "SOLID";
Else
Gradientbar.type = "gradient";
if (Type2.style.borderColor = = "Red")
Gradientbar.type = "Gradientradial";
N1 = (parseint (focus1.style.left) -8)/m*100;
N2 = (parseint (focus2.style.left) -8)/m*100;
GradientBar.focusposition.value = n1 + "%," + n2 + "%";
Gradientbar.angle = (parseint (angle.style.left)-8) * 3.6;
Gradientbar.opacity = (parseint (opacity.style.left) -8)/M
}

*************
* Xmltool.js
*************

Transferring XML documents to the server
function SaveXML ()
{
var XmlHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "server.php", false); Use server.asp when using ASP
Xmlhttp.setrequestheader ("Contrn-type", "Text/xml");
Xmlhttp.setrequestheader ("Contrn-charset", "gb2312");

Xmlhttp.send (Tree (canvas.documentelement));
var s = xmlhttp.responsetext;
minview.innerhtml = S.replace (/width:500; Height:300/, "width:120; Height:72 ")
if (XmlHTTP.responseText.indexOf ("Error:")!=-1) {
alert (Xmlhttp.responsetext);
}
}

Traversing XML objects, parsing the core function set of XML
function tree (element,debug) {
var buffer = "";
var node = "";
if (Element.nodetype!= 3) {
node = Element;
Buffer + + onelement (element,debug);
}
if (Element.nodetype = 3)
Buffer + + ondata (Element);
if (element.haschildnodes) {
for (Var i=0;i<element.childnodes.length;i++) {
Buffer + = tree (Element.childnodes (i), debug);
}
}
if (node)
Buffer + + endelement (node,debug);
return buffer;
}

/***** the following three functions please modify *****/as needed
Traverse XML Object--node start
function Onelement (element,debug) {
var buffer = (debug?) "<": "<") + Element.nodename;
n = Element.attributes.length
if (n>0) {//If the node has parameters
for (Var i=0;i<n;i++)
Buffer + + element.attributes (i). Name + ' =\ ' + element.attributes (i). Value + ' ";
}
Buffer + = Debug? ">": ">";
return buffer;
}

Traverse XML Object--end of node
function EndElement (element,debug) {
Return (debug? "</": "</") + Element.nodename + (debug? "><br>": ">");
}

Traversing XML objects--node data
function OnData (Element) {
Return Element.nodevalue
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.