⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vml.js

📁 js基本操作
💻 JS
📖 第 1 页 / 共 3 页
字号:
					if(parent.childNodes[i] == this.rawNode){						before = parent.childNodes[i+1];						break;					}				}			}			parent.removeChild(this.rawNode);		}		this.rawNode.arcsize = r;		if(parent){			if(before){				parent.insertBefore(this.rawNode, before);			}else{				parent.appendChild(this.rawNode);			}		}		return this.setTransform(this.matrix);	// self	}});dojo.gfx.Rect.nodeType = "roundrect"; // use a roundrect so the stroke join type is respecteddojo.declare("dojo.gfx.Ellipse", dojo.gfx.shape.Ellipse, {	// summary: an ellipse shape (VML)	attachShape: function(rawNode){		// summary: builds an ellipse shape from a Node.		// rawNode: Node: an VML node		var style = this.rawNode.style;		var rx = parseInt(style.width ) / 2;		var ry = parseInt(style.height) / 2;		var o = dojo.gfx.makeParameters(dojo.gfx.defaultEllipse, {			cx: parseInt(style.left) + rx,			cy: parseInt(style.top ) + ry,			rx: rx,			ry: ry		});		return o;	// dojo.gfx.shape.Ellipse	},	setShape: function(newShape){		// summary: sets an ellipse shape object (VML)		// newShape: Object: an ellipse shape object		var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		var style = this.rawNode.style;		style.left   = (shape.cx - shape.rx).toFixed();		style.top    = (shape.cy - shape.ry).toFixed();		style.width  = (shape.rx * 2).toFixed();		style.height = (shape.ry * 2).toFixed();		return this.setTransform(this.matrix);	// self	}});dojo.gfx.Ellipse.nodeType = "oval";dojo.declare("dojo.gfx.Circle", dojo.gfx.shape.Circle, {	// summary: a circle shape (VML)	attachShape: function(rawNode){		// summary: builds a circle shape from a Node.		// rawNode: Node: an VML node		var style = this.rawNode.style;		var r = parseInt(style.width) / 2;		var o = dojo.gfx.makeParameters(dojo.gfx.defaultCircle, {			cx: parseInt(style.left) + r,			cy: parseInt(style.top)  + r,			r:  r		});		return o;	// dojo.gfx.shape.Circle	},	setShape: function(newShape){		// summary: sets a circle shape object (VML)		// newShape: Object: a circle shape object		var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		var style = this.rawNode.style;		style.left   = (shape.cx - shape.r).toFixed();		style.top    = (shape.cy - shape.r).toFixed();		style.width  = (shape.r * 2).toFixed();		style.height = (shape.r * 2).toFixed();		return this;	// self	}});dojo.gfx.Circle.nodeType = "oval";dojo.declare("dojo.gfx.Line", dojo.gfx.shape.Line,	function(rawNode){		if(rawNode) rawNode.setAttribute("dojoGfxType", "line");	}, {	// summary: a line shape (VML)	attachShape: function(rawNode){		// summary: builds a line shape from a Node.		// rawNode: Node: an VML node		var p = rawNode.path.v.match(dojo.gfx.pathRegExp);		var shape = {};		do{			if(p.length < 7 || p[0] != "m" || p[3] != "l" || p[6] != "e") break;			shape.x1 = parseInt(p[1]);			shape.y1 = parseInt(p[2]);			shape.x2 = parseInt(p[4]);			shape.y2 = parseInt(p[5]);		}while(false);		return dojo.gfx.makeParameters(dojo.gfx.defaultLine, shape);	// dojo.gfx.shape.Line	},	setShape: function(newShape){		// summary: sets a line shape object (VML)		// newShape: Object: a line shape object		var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		this.rawNode.path.v = "m" + shape.x1.toFixed() + " " + shape.y1.toFixed() +			"l" + shape.x2.toFixed() + " " + shape.y2.toFixed() + "e";		return this.setTransform(this.matrix);	// self	}});dojo.gfx.Line.nodeType = "shape";dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline,	function(rawNode){		if(rawNode) rawNode.setAttribute("dojoGfxType", "polyline");	}, {	// summary: a polyline/polygon shape (VML)		attachShape: function(rawNode){		// summary: builds a polyline/polygon shape from a Node.		// rawNode: Node: an VML node		var shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true);		var p = rawNode.path.v.match(dojo.gfx.pathRegExp);		do{			if(p.length < 3 || p[0] != "m") break;			var x = parseInt(p[0]);			var y = parseInt(p[1]);			if(isNaN(x) || isNaN(y)) break;			shape.points.push({x: x, y: y});			if(p.length < 6 || p[3] != "l") break;			for(var i = 4; i < p.length; i += 2){				x = parseInt(p[i]);				y = parseInt(p[i + 1]);				if(isNaN(x) || isNaN(y)) break;				shape.points.push({x: x, y: y});			}		}while(false);		return shape;	// dojo.gfx.shape.Polyline	},	setShape: function(points, closed){		// summary: sets a polyline/polygon shape object (SVG)		// points: Object: a polyline/polygon shape object		// closed: Boolean?: if true, close the polyline explicitely		if(points && points instanceof Array){			// branch			// points: Array: an array of points			this.shape = dojo.gfx.makeParameters(this.shape, { points: points });			if(closed && this.shape.points.length) this.shape.points.push(this.shape.points[0]);		}else{			this.shape = dojo.gfx.makeParameters(this.shape, points);		}		this.bbox = null;		var attr = [];		var p = this.shape.points;		if(p.length > 0){			attr.push("m");			attr.push(p[0].x.toFixed());			attr.push(p[0].y.toFixed());			if(p.length > 1){				attr.push("l");				for(var i = 1; i < p.length; ++i){					attr.push(p[i].x.toFixed());					attr.push(p[i].y.toFixed());				}			}		}		attr.push("e");		this.rawNode.path.v = attr.join(" ");		return this.setTransform(this.matrix);	// self	}});dojo.gfx.Polyline.nodeType = "shape";dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {	// summary: an image (VML)		getEventSource: function() {		// summary: returns a Node, which is used as 		//	a source of events for this shape		return this.rawNode ? this.rawNode.firstChild : null;	// Node	},	attachShape: function(rawNode){		// summary: builds an image shape from a Node.		// rawNode: Node: an VML node		var shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);		shape.src = rawNode.firstChild.src;		return shape;	// dojo.gfx.shape.Image	},	setShape: function(newShape){		// summary: sets an image shape object (VML)		// newShape: Object: an image shape object		var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		var firstChild = this.rawNode.firstChild;        firstChild.src = shape.src;        if(shape.width || shape.height){			firstChild.style.width  = shape.width;			firstChild.style.height = shape.height;        }		return this.setTransform(this.matrix);	// self	},	setStroke: function(){		// summary: ignore setting a stroke style		return this;	// self	},	setFill: function(){		// summary: ignore setting a fill style		return this;	// self	},	attachStroke: function(rawNode){		// summary: ignore attaching a stroke style		return null;	},	attachFill: function(rawNode){		// summary: ignore attaching a fill style		return null;	},	attachTransform: function(rawNode) {		// summary: deduces a transformation matrix from a Node.		// rawNode: Node: an VML node		var matrix = {};		if(rawNode){			var m = rawNode.filters["DXImageTransform.Microsoft.Matrix"];			matrix.xx = m.M11;			matrix.xy = m.M12;			matrix.yx = m.M21;			matrix.yy = m.M22;			matrix.dx = m.Dx;			matrix.dy = m.Dy;		}		return dojo.gfx.matrix.normalize(matrix);	// dojo.gfx.matrix.Matrix	},	_applyTransform: function() {		var matrix = this._getRealMatrix();		if(!matrix) return this;		with(this.rawNode.filters["DXImageTransform.Microsoft.Matrix"]){			M11 = matrix.xx;			M12 = matrix.xy;			M21 = matrix.yx;			M22 = matrix.yy;			Dx  = matrix.dx;			Dy  = matrix.dy;		}		return this;	}});dojo.gfx.Image.nodeType = "image";dojo.gfx.path._calcArc = function(alpha){	var cosa  = Math.cos(alpha);	var sina  = Math.sin(alpha);	// return a start point, 1st and 2nd control points, and an end point	var p2 = {x: cosa + (4 / 3) * (1 - cosa), y: sina - (4 / 3) * cosa * (1 - cosa) / sina};	return {		s:  {x: cosa, y: sina},		c1: p2,		c2: {x: p2.x, y: -p2.y},		e:  {x: cosa, y: -sina}	};};dojo.declare("dojo.gfx.Path", dojo.gfx.path.Path,	function(rawNode){		if(rawNode) rawNode.setAttribute("dojoGfxType", "path");		this.vmlPath = "";		this.lastControl = {};	}, {	// summary: a path shape (VML)	_updateWithSegment: function(segment){		// summary: updates the bounding box of path with new segment		// segment: Object: a segment		var last = dojo.lang.shallowCopy(this.last);		dojo.gfx.Path.superclass._updateWithSegment.apply(this, arguments);		// add a VML path segment		var path = this[this.renderers[segment.action]](segment, last);		if(typeof(this.vmlPath) == "string"){			this.vmlPath += path.join("");		}else{			this.vmlPath = this.vmlPath.concat(path);		}		if(typeof(this.vmlPath) == "string"){			this.rawNode.path.v = this.vmlPath + " e";		}	},	attachShape: function(rawNode){		// summary: builds a path shape from a Node.		// rawNode: Node: an VML node		var shape = dojo.lang.shallowCopy(dojo.gfx.defaultPath, true);		var p = rawNode.path.v.match(dojo.gfx.pathRegExp);		var t = [], skip = false;		for(var i = 0; i < p.length; ++p){			var s = p[i];			if(s in this._pathVmlToSvgMap) {				skip = false;				t.push(this._pathVmlToSvgMap[s]);			} else if(!skip){				var n = parseInt(s);				if(isNaN(n)){					skip = true;				}else{					t.push(n);				}			}		}		if(t.length) shape.path = t.join(" ");		return shape;	// dojo.gfx.path.Path	},	setShape: function(newShape){		// summary: forms a path using a shape (VML)		// newShape: Object: an VML path string or a path object (see dojo.gfx.defaultPath)		this.vmlPath = [];		this.lastControl = {};		dojo.gfx.Path.superclass.setShape.apply(this, arguments);		this.vmlPath = this.vmlPath.join("");		this.rawNode.path.v = this.vmlPath + " e";		return this;	},	_pathVmlToSvgMap: {m: "M", l: "L", t: "m", r: "l", c: "C", v: "c", qb: "Q", x: "z", e: ""},	// VML-specific segment renderers	renderers: {		M: "_moveToA", m: "_moveToR", 		L: "_lineToA", l: "_lineToR", 		H: "_hLineToA", h: "_hLineToR", 		V: "_vLineToA", v: "_vLineToR", 		C: "_curveToA", c: "_curveToR", 		S: "_smoothCurveToA", s: "_smoothCurveToR", 		Q: "_qCurveToA", q: "_qCurveToR", 		T: "_qSmoothCurveToA", t: "_qSmoothCurveToR", 		A: "_arcTo", a: "_arcTo", 		Z: "_closePath", z: "_closePath"	},	_addArgs: function(path, args, from, upto){		if(typeof(upto) == "undefined"){			upto = args.length;		}		if(typeof(from) == "undefined"){			from = 0;		}		for(var i = from; i < upto; ++i){			path.push(" ");			path.push(args[i].toFixed());		}	},	_addArgsAdjusted: function(path, last, args, from, upto){		if(typeof(upto) == "undefined"){			upto = args.length;		}		if(typeof(from) == "undefined"){			from = 0;		}		for(var i = from; i < upto; i += 2){			path.push(" ");			path.push((last.x + args[i]).toFixed());			path.push(" ");			path.push((last.y + args[i + 1]).toFixed());		}	},	_moveToA: function(segment){		var p = [" m"];		var n = segment.args;		var l = n.length;		if(l == 2){			this._addArgs(p, n);		}else{			this._addArgs(p, n, 0, 2);			p.push(" l");			this._addArgs(p, n, 2);		}		this.lastControl = {};		return p;	},	_moveToR: function(segment, last){		var p = ["x" in last ? " t" : " m"];		var n = segment.args;		var l = n.length;		if(l == 2){			this._addArgs(p, n);		}else{			this._addArgs(p, n, 0, 2);			p.push(" r");			this._addArgs(p, n, 2);		}		this.lastControl = {};		return p;	},	_lineToA: function(segment){		var p = [" l"];		this._addArgs(p, segment.args);		this.lastControl = {};		return p;	},	_lineToR: function(segment){		var p = [" r"];		this._addArgs(p, segment.args);		this.lastControl = {};		return p;	},	_hLineToA: function(segment, last){		var p = [" l"];		var n = segment.args;		var l = n.length;		var y = " " + last.y.toFixed();		for(var i = 0; i < l; ++i){			p.push(" ");			p.push(n[i].toFixed());			p.push(y);		}		this.lastControl = {};		return p;	},	_hLineToR: function(segment){		var p = [" r"];		var n = segment.args;		var l = n.length;		for(var i = 0; i < l; ++i){			p.push(" ");			p.push(n[i].toFixed());			p.push(" 0");		}		this.lastControl = {};		return p;	},	_vLineToA: function(segment, last){		var p = [" l"];		var n = segment.args;		var l = n.length;		var x = " " + last.x.toFixed();		for(var i = 0; i < l; ++i){			p.push(x);			p.push(" ");			p.push(n[i].toFixed());		}		this.lastControl = {};		return p;	},	_vLineToR: function(segment){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -