Commit f032ff7a by Dmitry Baranovskiy

1.2.6

• Improved events handling
• Fix rounded rect in IE
• Added xmlns & version (bug 96)
parent 0e2399dc
This source diff could not be displayed because it is too large. You can view the blob instead.
/*! /*!
* Raphael 1.2.5 - JavaScript Vector Library * Raphael 1.2.6 - JavaScript Vector Library
* *
* Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com) * Copyright (c) 2008 - 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.
...@@ -31,25 +31,26 @@ window.Raphael = (function () { ...@@ -31,25 +31,26 @@ window.Raphael = (function () {
apply = "apply", apply = "apply",
concat = "concat", concat = "concat",
E = "", E = "",
events = ["click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"], S = " ",
events = "click dblclick mousedown mousemove mouseout mouseover mouseup".split(S),
has = "hasOwnProperty", has = "hasOwnProperty",
isit = /^\[object\s+|\]$/gi, isit = /^\[object\s+|\]$/gi,
join = "join", join = "join",
length = "length", length = "length",
proto = "prototype", proto = "prototype",
lowerCase = String[proto].toLowerCase, lowerCase = String[proto].toLowerCase,
mmax = Math.max, math = Math,
mmin = Math.min, mmax = math.max,
mmin = math.min,
nu = "number", nu = "number",
toString = "toString", toString = "toString",
objectToString = Object[proto][toString], objectToString = Object[proto][toString],
paper = {}, paper = {},
pow = Math.pow, pow = math.pow,
push = "push", push = "push",
rg = /^(?=[\da-f]$)/, rg = /^(?=[\da-f]$)/,
ISURL = /^url\(['"]?([^\)]+)['"]?\)$/i, ISURL = /^url\(['"]?([^\)]+)['"]?\)$/i,
round = Math.round, round = math.round,
S = " ",
setAttribute = "setAttribute", setAttribute = "setAttribute",
split = "split", split = "split",
toFloat = parseFloat, toFloat = parseFloat,
...@@ -58,7 +59,7 @@ window.Raphael = (function () { ...@@ -58,7 +59,7 @@ window.Raphael = (function () {
availableAttrs = {"clip-rect": "0 0 10e9 10e9", 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 10e9 10e9", 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 = {"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 = {"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.2.5"; R.version = "1.2.6";
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");
R.svg = !(R.vml = R.type == "VML"); R.svg = !(R.vml = R.type == "VML");
R._id = 0; R._id = 0;
...@@ -525,14 +526,14 @@ window.Raphael = (function () { ...@@ -525,14 +526,14 @@ window.Raphael = (function () {
a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) { a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
// for more information of where this math came from visit: // for more information of where this math came from visit:
// http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
var PI = Math.PI, var PI = math.PI,
_120 = PI * 120 / 180, _120 = PI * 120 / 180,
rad = PI / 180 * (+angle || 0), rad = PI / 180 * (+angle || 0),
res = [], res = [],
xy, xy,
rotate = cacher(function (x, y, rad) { rotate = cacher(function (x, y, rad) {
var X = x * Math.cos(rad) - y * Math.sin(rad), var X = x * math.cos(rad) - y * math.sin(rad),
Y = x * Math.sin(rad) + y * Math.cos(rad); Y = x * math.sin(rad) + y * math.cos(rad);
return {x: X, y: Y}; return {x: X, y: Y};
}); });
if (!recursive) { if (!recursive) {
...@@ -542,20 +543,20 @@ window.Raphael = (function () { ...@@ -542,20 +543,20 @@ window.Raphael = (function () {
xy = rotate(x2, y2, -rad); xy = rotate(x2, y2, -rad);
x2 = xy.x; x2 = xy.x;
y2 = xy.y; y2 = xy.y;
var cos = Math.cos(PI / 180 * angle), var cos = math.cos(PI / 180 * angle),
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 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) *
Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))), math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
cx = k * rx * y / ry + (x1 + x2) / 2, cx = k * rx * y / ry + (x1 + x2) / 2,
cy = k * -ry * x / rx + (y1 + y2) / 2, cy = k * -ry * x / rx + (y1 + y2) / 2,
f1 = Math.asin((y1 - cy) / ry), f1 = math.asin((y1 - cy) / ry),
f2 = Math.asin((y2 - cy) / ry); f2 = math.asin((y2 - cy) / ry);
f1 = x1 < cx ? PI - f1 : f1; f1 = x1 < cx ? PI - f1 : f1;
f2 = x2 < cx ? PI - f2 : f2; f2 = x2 < cx ? PI - f2 : f2;
...@@ -574,21 +575,21 @@ window.Raphael = (function () { ...@@ -574,21 +575,21 @@ window.Raphael = (function () {
cy = recursive[3]; cy = recursive[3];
} }
var df = f2 - f1; var df = f2 - f1;
if (Math.abs(df) > _120) { if (math.abs(df) > _120) {
var f2old = f2, var f2old = f2,
x2old = x2, x2old = x2,
y2old = y2; y2old = y2;
f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1); f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
x2 = cx + rx * Math.cos(f2); x2 = cx + rx * math.cos(f2);
y2 = cy + ry * Math.sin(f2); y2 = cy + ry * math.sin(f2);
res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]); res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
} }
df = f2 - f1; df = f2 - f1;
var c1 = Math.cos(f1), var c1 = math.cos(f1),
s1 = Math.sin(f1), s1 = math.sin(f1),
c2 = Math.cos(f2), c2 = math.cos(f2),
s2 = Math.sin(f2), s2 = math.sin(f2),
t = Math.tan(df / 4), t = math.tan(df / 4),
hx = 4 / 3 * rx * t, hx = 4 / 3 * rx * t,
hy = 4 / 3 * ry * t, hy = 4 / 3 * ry * t,
m1 = [x1, y1], m1 = [x1, y1],
...@@ -633,13 +634,13 @@ window.Raphael = (function () { ...@@ -633,13 +634,13 @@ window.Raphael = (function () {
var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x), var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
b = 2 * (c1x - p1x) - 2 * (c2x - c1x), b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
c = p1x - c1x, c = p1x - c1x,
t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a, t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a, t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
y = [p1y, p2y], y = [p1y, p2y],
x = [p1x, p2x], x = [p1x, p2x],
dot; dot;
!isFinite(t1) && (t1 = .5); math.abs(t1) > 1e12 && (t1 = .5);
!isFinite(t2) && (t2 = .5); math.abs(t2) > 1e12 && (t2 = .5);
if (t1 > 0 && t1 < 1) { if (t1 > 0 && t1 < 1) {
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
x[push](dot.x); x[push](dot.x);
...@@ -653,10 +654,10 @@ window.Raphael = (function () { ...@@ -653,10 +654,10 @@ window.Raphael = (function () {
a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y); a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
b = 2 * (c1y - p1y) - 2 * (c2y - c1y); b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
c = p1y - c1y; c = p1y - c1y;
t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a; t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a; t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
!isFinite(t1) && (t1 = .5); math.abs(t1) > 1e12 && (t1 = .5);
!isFinite(t2) && (t2 = .5); math.abs(t2) > 1e12 && (t2 = .5);
if (t1 > 0 && t1 < 1) { if (t1 > 0 && t1 < 1) {
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
x[push](dot.x); x[push](dot.x);
...@@ -940,7 +941,7 @@ window.Raphael = (function () { ...@@ -940,7 +941,7 @@ window.Raphael = (function () {
fx = toFloat(_fx); fx = toFloat(_fx);
fy = toFloat(_fy); fy = toFloat(_fy);
if (pow(fx - .5, 2) + pow(fy - .5, 2) > .25) { if (pow(fx - .5, 2) + pow(fy - .5, 2) > .25) {
fy = Math.sqrt(.25 - pow(fx - .5, 2)) + .5; fy = math.sqrt(.25 - pow(fx - .5, 2)) + .5;
} }
} }
return E; return E;
...@@ -952,8 +953,8 @@ window.Raphael = (function () { ...@@ -952,8 +953,8 @@ window.Raphael = (function () {
if (isNaN(angle)) { if (isNaN(angle)) {
return null; return null;
} }
var vector = [0, 0, Math.cos(angle * Math.PI / 180), Math.sin(angle * Math.PI / 180)], var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
max = 1 / (mmax(Math.abs(vector[2]), Math.abs(vector[3])) || 1); max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
vector[2] *= max; vector[2] *= max;
vector[3] *= max; vector[3] *= max;
if (vector[2] < 0) { if (vector[2] < 0) {
...@@ -1550,8 +1551,12 @@ window.Raphael = (function () { ...@@ -1550,8 +1551,12 @@ window.Raphael = (function () {
var cnvs = paper.canvas; var cnvs = paper.canvas;
paper.width = width || 512; paper.width = width || 512;
paper.height = height || 342; paper.height = height || 342;
cnvs[setAttribute]("width", paper.width); $(cnvs, {
cnvs[setAttribute]("height", paper.height); xmlns: "http://www.w3.org/2000/svg",
version: 1.1,
width: paper.width,
height: paper.height
});
if (container == 1) { if (container == 1) {
cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px"; cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
doc.body[appendChild](cnvs); doc.body[appendChild](cnvs);
...@@ -1842,7 +1847,7 @@ window.Raphael = (function () { ...@@ -1842,7 +1847,7 @@ window.Raphael = (function () {
fx = toFloat(fx); fx = toFloat(fx);
fy = toFloat(fy); fy = toFloat(fy);
if (pow(fx - .5, 2) + pow(fy - .5, 2) > .25) { if (pow(fx - .5, 2) + pow(fy - .5, 2) > .25) {
fy = Math.sqrt(.25 - pow(fx - .5, 2)) + .5; fy = math.sqrt(.25 - pow(fx - .5, 2)) + .5;
} }
fxfy = fx + S + fy; fxfy = fx + S + fy;
} }
...@@ -2034,15 +2039,26 @@ window.Raphael = (function () { ...@@ -2034,15 +2039,26 @@ window.Raphael = (function () {
(os.width != w + "px") && (os.width = w + "px"); (os.width != w + "px") && (os.width = w + "px");
(os.height != h + "px") && (os.height = h + "px"); (os.height != h + "px") && (os.height = h + "px");
var arcsize = (+params.r || 0) / mmin(w, h); var arcsize = (+params.r || 0) / mmin(w, h);
if (this.type == "rect" && this.arcsize != arcsize && (arcsize || this.arcsize)) { if (this.type == "rect" && this.arcsize.toFixed(4) != arcsize.toFixed(4) && (arcsize || this.arcsize)) {
// We should replace element with the new one // We should replace element with the new one
var o = createNode(arcsize ? "roundrect" : "rect"); var o = createNode("roundrect"),
a = {},
i = 0,
ii = this.events[length];
o.arcsize = arcsize; o.arcsize = arcsize;
o.raphael = this;
this.Group[appendChild](o); this.Group[appendChild](o);
this.node.parentNode.removeChild(this.node); this.Group.removeChild(this.node);
this.node = o; this[0] = this.node = o;
this.arcsize = arcsize; this.arcsize = arcsize;
this.attr(this.attrs); for (var i in attr) {
a[i] = attr[i];
}
delete a.scale;
this.attr(a);
if (this.events) for (; i < ii; i++) {
this.events[i].unbind = addEvent(this.node, this.events[i].name, this.events[i].f, this);
}
} }
} }
}; };
...@@ -2362,7 +2378,7 @@ window.Raphael = (function () { ...@@ -2362,7 +2378,7 @@ window.Raphael = (function () {
// rest // rest
// Safari or Chrome (WebKit) rendering bug workaround method // Safari or Chrome (WebKit) rendering bug workaround method
if ({"Apple Computer, Inc.": 1, "Google Inc.": 1}[navigator.vendor] && !(navigator.userAgent.indexOf("Version/4.0") + 1)) { if ((/^Apple|^Google/).test(navigator.vendor) && !(navigator.userAgent.indexOf("Version/4.0") + 1)) {
paper.safari = function () { paper.safari = function () {
var rect = this.rect(-99, -99, this.width + 99, this.height + 99); var rect = this.rect(-99, -99, this.width + 99, this.height + 99);
setTimeout(function () {rect.remove();}); setTimeout(function () {rect.remove();});
...@@ -2394,19 +2410,6 @@ window.Raphael = (function () { ...@@ -2394,19 +2410,6 @@ window.Raphael = (function () {
obj.detachEvent("on" + type, f); obj.detachEvent("on" + type, f);
return true; return true;
}; };
if (type == "mouseover") {
obj.attachEvent("onmouseenter", f);
return function () {
obj.detachEvent("onmouseenter", f);
return detacher();
};
} else if (type == "mouseout") {
obj.attachEvent("onmouseleave", f);
return function () {
obj.detachEvent("onmouseleave", f);
return detacher();
};
}
return detacher; return detacher;
}; };
} }
...@@ -2415,30 +2418,30 @@ window.Raphael = (function () { ...@@ -2415,30 +2418,30 @@ window.Raphael = (function () {
(function (eventName) { (function (eventName) {
Element[proto][eventName] = function (fn) { Element[proto][eventName] = function (fn) {
if (R.is(fn, "function")) { if (R.is(fn, "function")) {
this.events = this.events || {}; this.events = this.events || [];
this.events[eventName] = this.events[eventName] || {}; this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node, eventName, fn, this)});
this.events[eventName][fn] = this.events[eventName][fn] || [];
this.events[eventName][fn][push](addEvent(this.shape || this.node, eventName, fn, this));
} }
return this; return this;
}; };
Element[proto]["un" + eventName] = function (fn) { Element[proto]["un" + eventName] = function (fn) {
var e = this.events; var events = this.events,
e && l = events[length];
e[eventName] && while (l--) if (events[l].name == eventName && events[l].f == fn) {
e[eventName][fn] && events[l].unbind();
e[eventName][fn][length] && events.splice(l, 1);
e[eventName][fn].shift()() && !events.length && delete this.events;
!e[eventName][fn][length] && return this;
delete e[eventName][fn]; }
return this; return this;
}; };
})(events[i]); })(events[i]);
} }
Element[proto].hover = function (f_in, f_out) { Element[proto].hover = function (f_in, f_out) {
return this.mouseover(f_in).mouseout(f_out); return this.mouseover(f_in).mouseout(f_out);
}; };
Element[proto].unhover = function (f_in, f_out) {
return this.unmouseover(f_in).unmouseout(f_out);
};
paper.circle = function (x, y, r) { paper.circle = function (x, y, r) {
return theCircle(this, x || 0, y || 0, r || 0); return theCircle(this, x || 0, y || 0, r || 0);
}; };
...@@ -2463,9 +2466,16 @@ window.Raphael = (function () { ...@@ -2463,9 +2466,16 @@ window.Raphael = (function () {
return new Set(itemsArray); return new Set(itemsArray);
}; };
paper.setSize = setSize; paper.setSize = setSize;
function scaleToString() {
return this.x + S + this.y;
};
Element[proto].scale = function (x, y, cx, cy) { Element[proto].scale = function (x, y, cx, cy) {
if (x == null && y == null) { if (x == null && y == null) {
return {x: this._.sx, y: this._.sy, toString: function () { return this.x + S + this.y; }}; return {
x: this._.sx,
y: this._.sy,
toString: scaleToString
};
} }
y = y || x; y = y || x;
!+y && (y = x); !+y && (y = x);
...@@ -2482,8 +2492,8 @@ window.Raphael = (function () { ...@@ -2482,8 +2492,8 @@ window.Raphael = (function () {
ky = y / this._.sy; ky = y / this._.sy;
cx = (+cx || cx == 0) ? cx : rcx; cx = (+cx || cx == 0) ? cx : rcx;
cy = (+cy || cy == 0) ? cy : rcy; cy = (+cy || cy == 0) ? cy : rcy;
var dirx = ~~(x / Math.abs(x)), var dirx = ~~(x / math.abs(x)),
diry = ~~(y / Math.abs(y)), diry = ~~(y / math.abs(y)),
s = this.node.style, s = this.node.style,
ncx = cx + (rcx - cx) * kx, ncx = cx + (rcx - cx) * kx,
ncy = cy + (rcy - cy) * ky; ncy = cy + (rcy - cy) * ky;
...@@ -2496,11 +2506,11 @@ window.Raphael = (function () { ...@@ -2496,11 +2506,11 @@ window.Raphael = (function () {
newx = ncx - neww / 2, newx = ncx - neww / 2,
newy = ncy - newh / 2; newy = ncy - newh / 2;
this.attr({ this.attr({
width: neww,
height: newh, height: newh,
r: newr,
width: neww,
x: newx, x: newx,
y: newy, y: newy
r: newr
}); });
break; break;
case "circle": case "circle":
...@@ -2621,7 +2631,7 @@ window.Raphael = (function () { ...@@ -2621,7 +2631,7 @@ window.Raphael = (function () {
} }
var p = .3, var p = .3,
s = p / 4; s = p / 4;
return pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1; return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
}, },
bounce: function (n) { bounce: function (n) {
var s = 7.5625, var s = 7.5625,
...@@ -2942,6 +2952,7 @@ window.Raphael = (function () { ...@@ -2942,6 +2952,7 @@ window.Raphael = (function () {
while (i--) { while (i--) {
this.items[i].insertAfter(el); this.items[i].insertAfter(el);
} }
return this;
}; };
Set[proto].getBBox = function () { Set[proto].getBBox = function () {
var x = [], var x = [],
......
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