vml.js

来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 1,011 行 · 第 1/3 页

JS
1,011
字号
}, setShape:function (newShape) {
	var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);
	this.bbox = null;
	var style = this.rawNode.style;
	style.left = shape.x.toFixed();
	style.top = shape.y.toFixed();
	style.width = (typeof (shape.width) == "string" && shape.width.indexOf("%") >= 0) ? shape.width : shape.width.toFixed();
	style.height = (typeof (shape.width) == "string" && shape.height.indexOf("%") >= 0) ? shape.height : shape.height.toFixed();
	var r = Math.min(1, (shape.r / Math.min(parseFloat(shape.width), parseFloat(shape.height)))).toFixed(8);
	var parent = this.rawNode.parentNode;
	var before = null;
	if (parent) {
		if (parent.lastChild != this.rawNode) {
			for (var i = 0; i < parent.childNodes.length; ++i) {
				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);
}});
dojo.gfx.Rect.nodeType = "roundrect";
dojo.declare("dojo.gfx.Ellipse", dojo.gfx.shape.Ellipse, {attachShape:function (rawNode) {
	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;
}, setShape:function (newShape) {
	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);
}});
dojo.gfx.Ellipse.nodeType = "oval";
dojo.declare("dojo.gfx.Circle", dojo.gfx.shape.Circle, {attachShape:function (rawNode) {
	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;
}, setShape:function (newShape) {
	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;
}});
dojo.gfx.Circle.nodeType = "oval";
dojo.declare("dojo.gfx.Line", dojo.gfx.shape.Line, function (rawNode) {
	if (rawNode) {
		rawNode.setAttribute("dojoGfxType", "line");
	}
}, {attachShape:function (rawNode) {
	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);
}, setShape:function (newShape) {
	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);
}});
dojo.gfx.Line.nodeType = "shape";
dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline, function (rawNode) {
	if (rawNode) {
		rawNode.setAttribute("dojoGfxType", "polyline");
	}
}, {attachShape:function (rawNode) {
	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;
}, setShape:function (points, closed) {
	if (points && points instanceof Array) {
		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);
}});
dojo.gfx.Polyline.nodeType = "shape";
dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {getEventSource:function () {
	return this.rawNode ? this.rawNode.firstChild : null;
}, attachShape:function (rawNode) {
	var shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);
	shape.src = rawNode.firstChild.src;
	return shape;
}, setShape:function (newShape) {
	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);
}, setStroke:function () {
	return this;
}, setFill:function () {
	return this;
}, attachStroke:function (rawNode) {
	return null;
}, attachFill:function (rawNode) {
	return null;
}, attachTransform:function (rawNode) {
	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);
}, _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);
	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 = {};
}, {_updateWithSegment:function (segment) {
	var last = dojo.lang.shallowCopy(this.last);
	dojo.gfx.Path.superclass._updateWithSegment.apply(this, arguments);
	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) {
	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;
}, setShape:function (newShape) {
	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:""}, 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");
	}

⌨️ 快捷键说明

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