Commit 28c083fc by Dmitry Baranovskiy

Fiz for couple IE bugs, Set.clone added

parent a8d0f3fa
This source diff could not be displayed because it is too large. You can view the blob instead.
/*! /*!
* Raphael 1.3.0 - JavaScript Vector Library * Raphael 1.3.2 - JavaScript Vector Library
* *
* Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com) * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/ */
window.Raphael = (function () { Raphael = (function () {
var separator = /[, ]+/, var separator = /[, ]+/,
elements = /^(circle|rect|path|ellipse|text|image)$/, elements = /^(circle|rect|path|ellipse|text|image)$/,
has = "hasOwnProperty",
doc = document, doc = document,
win = window, win = window,
oldRaphael = { oldRaphael = {
was: "Raphael" in win, was: win[has]("Raphael"),
is: win.Raphael is: win.Raphael
}, },
R = function () { R = function () {
...@@ -36,7 +37,6 @@ window.Raphael = (function () { ...@@ -36,7 +37,6 @@ window.Raphael = (function () {
S = " ", S = " ",
split = "split", split = "split",
events = "click dblclick mousedown mousemove mouseout mouseover mouseup"[split](S), events = "click dblclick mousedown mousemove mouseout mouseover mouseup"[split](S),
has = "hasOwnProperty",
join = "join", join = "join",
length = "length", length = "length",
proto = "prototype", proto = "prototype",
...@@ -61,7 +61,7 @@ window.Raphael = (function () { ...@@ -61,7 +61,7 @@ window.Raphael = (function () {
availableAttrs = {"clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0}, availableAttrs = {"clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
availableAnimAttrs = {along: "along", "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu}, availableAnimAttrs = {along: "along", "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
rp = "replace"; rp = "replace";
R.version = "1.3.0"; R.version = "1.3.2";
R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML"); R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
if (R.type == "VML") { if (R.type == "VML") {
var d = document.createElement("div"); var d = document.createElement("div");
...@@ -298,6 +298,8 @@ window.Raphael = (function () { ...@@ -298,6 +298,8 @@ window.Raphael = (function () {
delete this.start; delete this.start;
}; };
// path utilities // path utilities
var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig;
R.parsePathString = cacher(function (pathString) { R.parsePathString = cacher(function (pathString) {
if (!pathString) { if (!pathString) {
return null; return null;
...@@ -308,12 +310,17 @@ window.Raphael = (function () { ...@@ -308,12 +310,17 @@ window.Raphael = (function () {
data = pathClone(pathString); data = pathClone(pathString);
} }
if (!data[length]) { if (!data[length]) {
(pathString + E)[rp](/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) { (pathString + E)[rp](pathCommand, function (a, b, c) {
var params = [], var params = [],
name = lowerCase.call(b); name = lowerCase.call(b);
c[rp](/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) { c[rp](pathValues, function (a, b) {
b && params[push](+b); b && params[push](+b);
}); });
if (name == "m" && params[length] > 2) {
data[push]([b][concat](params.splice(0, 2)));
name = "l";
b = b == "m" ? "l" : "L";
}
while (params[length] >= paramCounts[name]) { while (params[length] >= paramCounts[name]) {
data[push]([b][concat](params.splice(0, paramCounts[name]))); data[push]([b][concat](params.splice(0, paramCounts[name])));
if (!paramCounts[name]) { if (!paramCounts[name]) {
...@@ -573,8 +580,14 @@ window.Raphael = (function () { ...@@ -573,8 +580,14 @@ window.Raphael = (function () {
sin = math.sin(PI / 180 * angle), sin = math.sin(PI / 180 * angle),
x = (x1 - x2) / 2, x = (x1 - x2) / 2,
y = (y1 - y2) / 2; y = (y1 - y2) / 2;
rx = mmax(rx, math.abs(x)); // rx = mmax(rx, math.abs(x));
ry = mmax(ry, math.abs(y)); // ry = mmax(ry, math.abs(y));
var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
if (h > 1) {
h = math.sqrt(h);
rx = h * rx;
ry = h * ry;
}
var rx2 = rx * rx, var rx2 = rx * rx,
ry2 = ry * ry, ry2 = ry * ry,
k = (large_arc_flag == sweep_flag ? -1 : 1) * k = (large_arc_flag == sweep_flag ? -1 : 1) *
...@@ -632,6 +645,7 @@ window.Raphael = (function () { ...@@ -632,6 +645,7 @@ window.Raphael = (function () {
for (var i = 0, ii = res[length]; i < ii; i++) { for (var i = 0, ii = res[length]; i < ii; i++) {
newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
} }
// alert(newres);
return newres; return newres;
} }
}, },
...@@ -1077,7 +1091,7 @@ window.Raphael = (function () { ...@@ -1077,7 +1091,7 @@ window.Raphael = (function () {
hl[appendChild](node); hl[appendChild](node);
pn = hl; pn = hl;
} }
pn.setAttributeNS(o.Paper[proto].xlink, att, value); pn.setAttributeNS(o.paper.xlink, att, value);
break; break;
case "cursor": case "cursor":
node.style.cursor = value; node.style.cursor = value;
...@@ -1108,9 +1122,8 @@ window.Raphael = (function () { ...@@ -1108,9 +1122,8 @@ window.Raphael = (function () {
} }
break; break;
case "path": case "path":
if (value && o.type == "path") { if (o.type == "path") {
attrs.path = roundPath(pathToAbsolute(value)); $(node, {d: value ? attrs.path = roundPath(pathToAbsolute(value)) : "M0,0"});
$(node, {d: attrs.path});
} }
break; break;
case "width": case "width":
...@@ -1615,21 +1628,27 @@ window.Raphael = (function () { ...@@ -1615,21 +1628,27 @@ window.Raphael = (function () {
// VML // VML
if (R.vml) { if (R.vml) {
var path2vml = function (path) { var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
bites = /([clmz]),?([^clmz]*)/gi,
val = /-?[^,\s-]+/g,
path2vml = function (path) {
var total = /[ahqstv]/ig, var total = /[ahqstv]/ig,
command = pathToAbsolute; command = pathToAbsolute;
(path + E).match(total) && (command = path2curve); (path + E).match(total) && (command = path2curve);
total = /[clmz]/g; total = /[clmz]/g;
if (command == pathToAbsolute && !(path + E).match(total)) { if (command == pathToAbsolute && !(path + E).match(total)) {
var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
bites = /([clmz]),?([^clmz]*)/gi,
val = /-?[^,\s-]+/g;
var res = (path + E)[rp](bites, function (all, command, args) { var res = (path + E)[rp](bites, function (all, command, args) {
var vals = []; var vals = [],
isMove = lowerCase.call(command) == "m",
res = map[command];
args[rp](val, function (value) { args[rp](val, function (value) {
if (isMove && vals[length] == 2) {
res += vals + map[command == "m" ? "l" : "L"];
vals = [];
}
vals[push](round(value)); vals[push](round(value));
}); });
return map[command] + vals; return res + vals;
}); });
return res; return res;
} }
...@@ -1660,12 +1679,14 @@ window.Raphael = (function () { ...@@ -1660,12 +1679,14 @@ window.Raphael = (function () {
el.coordsize = this.coordsize; el.coordsize = this.coordsize;
el.coordorigin = this.coordorigin; el.coordorigin = this.coordorigin;
g[appendChild](el); g[appendChild](el);
var p = new Element(el, g, VML); var p = new Element(el, g, VML),
attr = {fill: "none", stroke: "#000"};
pathString && (attr.path = pathString);
p.isAbsolute = true; p.isAbsolute = true;
p.type = "path"; p.type = "path";
p.path = []; p.path = [];
p.Path = E; p.Path = E;
pathString && setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString}); setFillAndStroke(p, attr);
VML.canvas[appendChild](g); VML.canvas[appendChild](g);
return p; return p;
}; };
...@@ -2628,11 +2649,9 @@ window.Raphael = (function () { ...@@ -2628,11 +2649,9 @@ window.Raphael = (function () {
if (subpath && !subpaths.start) { if (subpath && !subpaths.start) {
point = R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], (length - len) / l); point = R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], (length - len) / l);
sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y]; sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
if (onlystart) { if (onlystart) return sp;
return sp;
}
subpaths.start = sp; subpaths.start = sp;
sp = ["M", point.x, point.y, "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join](); sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
len += l; len += l;
x = +p[5]; x = +p[5];
y = +p[6]; y = +p[6];
...@@ -2678,6 +2697,9 @@ window.Raphael = (function () { ...@@ -2678,6 +2697,9 @@ window.Raphael = (function () {
}; };
Element[proto].getSubpath = function (from, to) { Element[proto].getSubpath = function (from, to) {
if (this.type != "path") return; if (this.type != "path") return;
if (math.abs(this.getTotalLength() - to) < 1e-6) {
return getSubpathsAtLength(this.attrs.path, from).end;
}
var a = getSubpathsAtLength(this.attrs.path, to, 1); var a = getSubpathsAtLength(this.attrs.path, to, 1);
return from ? getSubpathsAtLength(a, from).end : a; return from ? getSubpathsAtLength(a, from).end : a;
}; };
...@@ -2747,7 +2769,7 @@ window.Raphael = (function () { ...@@ -2747,7 +2769,7 @@ window.Raphael = (function () {
var Now = +new Date; var Now = +new Date;
for (var l in animationElements) if (l != "length" && animationElements[has](l)) { for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
var e = animationElements[l]; var e = animationElements[l];
if (e.stop) { if (e.stop || e.el.removed) {
delete animationElements[l]; delete animationElements[l];
animationElements[length]--; animationElements[length]--;
continue; continue;
...@@ -3100,6 +3122,13 @@ window.Raphael = (function () { ...@@ -3100,6 +3122,13 @@ window.Raphael = (function () {
height: mmax[apply](0, h) - y height: mmax[apply](0, h) - y
}; };
}; };
Set[proto].clone = function (s) {
s = new Set;
for (var i = 0, ii = this.items[length]; i < ii; i++) {
s[push](this.items[i].clone());
}
return s;
};
R.registerFont = function (font) { R.registerFont = function (font) {
if (!font.face) { if (!font.face) {
...@@ -3198,17 +3227,8 @@ window.Raphael = (function () { ...@@ -3198,17 +3227,8 @@ window.Raphael = (function () {
return token || E; return token || E;
}; };
R.ninja = function () { R.ninja = function () {
var r = win.Raphael, u; oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael;
if (oldRaphael.was) { return R;
win.Raphael = oldRaphael.is;
} else {
try {
delete win.Raphael;
} catch (e) {
win.Raphael = u;
}
}
return r;
}; };
R.el = Element[proto]; R.el = Element[proto];
return R; return R;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment