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 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;
}
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
}
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.