Commit 210ce212 by Tomas Alabes

v2.1.3

parent c47c0773
This source diff could not be displayed because it is too large. You can view the blob instead.
// ┌────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël 2.1.2 - JavaScript Vector Library │ \\
// │ Raphaël 2.1.3 - JavaScript Vector Library │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Copyright © 2008-2012 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
// │ Copyright © 2008-2012 Sencha Labs (http://sencha.com) │ \\
......@@ -505,7 +505,7 @@
| var c = paper.circle(10, 10, 10).attr({hue: .45});
| // or even like this:
| c.animate({hue: 1}, 1e3);
|
|
| // You could also create custom attribute
| // with multiple parameters:
| paper.customAttributes.hsb = function (h, s, b) {
......@@ -546,7 +546,7 @@
objectToString = Object.prototype.toString,
paper = {},
push = "push",
ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
ISURL = R._ISURL = /^url\(['"]?(.+?)['"]?\)$/i,
colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
......@@ -771,7 +771,7 @@
* Raphael.is
[ method ]
**
* Handfull replacement for `typeof` operator.
* Handful of replacements for `typeof` operator.
> Parameters
- o (…) any object or primitive
- type (string) name of the type, i.e. “string”, “function”, “number”, etc.
......@@ -847,7 +847,7 @@
**
* Transform angle to degrees
> Parameters
- deg (number) angle in radians
- rad (number) angle in radians
= (number) angle in degrees.
\*/
R.deg = function (rad) {
......@@ -1070,8 +1070,8 @@
if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
v = h.b;
s = h.s;
h = h.h;
o = h.o;
h = h.h;
}
h *= 360;
var R, G, B, X, C;
......@@ -2422,6 +2422,8 @@
pp[i].shift();
var pi = pp[i];
while (pi.length) {
pcoms1[i]="A"; // if created multiple C:s, their original seg is saved
p2 && (pcoms2[i]="A"); // the same as above
pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
}
pp.splice(i, 1);
......@@ -2437,12 +2439,40 @@
a1.y = path1[i][2];
ii = mmax(p.length, p2 && p2.length || 0);
}
};
},
pcoms1 = [], // path commands of original path p
pcoms2 = [], // path commands of original path p2
pfirst = "", // temporary holder for original path command
pcom = ""; // holder for previous path command of original path
for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
p[i] = processPath(p[i], attrs);
fixArc(p, i);
p2 && (p2[i] = processPath(p2[i], attrs2));
p2 && fixArc(p2, i);
p[i] && (pfirst = p[i][0]); // save current path command
if (pfirst != "C") // C is not saved yet, because it may be result of conversion
{
pcoms1[i] = pfirst; // Save current path command
i && ( pcom = pcoms1[i-1]); // Get previous path command pcom
}
p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath
if (pcoms1[i] != "A" && pfirst == "C") pcoms1[i] = "C"; // A is the only command
// which may produce multiple C:s
// so we have to make sure that C is also C in original path
fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1
if (p2) { // the same procedures is done to p2
p2[i] && (pfirst = p2[i][0]);
if (pfirst != "C")
{
pcoms2[i] = pfirst;
i && (pcom = pcoms2[i-1]);
}
p2[i] = processPath(p2[i], attrs2, pcom);
if (pcoms2[i]!="A" && pfirst=="C") pcoms2[i]="C";
fixArc(p2, i);
}
fixM(p, p2, attrs, attrs2, i);
fixM(p2, p, attrs2, attrs, i);
var seg = p[i],
......@@ -3125,7 +3155,7 @@
obj.removeEventListener(type, f, false);
if (supportsTouch && touchMap[type])
obj.removeEventListener(touchMap[type], f, false);
obj.removeEventListener(touchMap[type], _f, false);
return true;
};
......@@ -3455,7 +3485,7 @@
[ method ]
**
* Adds or retrieves given value asociated with given key.
**
**
* See also @Element.removeData
> Parameters
- key (string) key to store data
......@@ -3563,8 +3593,8 @@
- mcontext (object) #optional context for moving handler
- scontext (object) #optional context for drag start handler
- econtext (object) #optional context for drag end handler
* Additionaly following `drag` events will be triggered: `drag.start.<id>` on start,
* `drag.end.<id>` on end and `drag.move.<id>` on every move. When element will be dragged over another element
* Additionaly following `drag` events will be triggered: `drag.start.<id>` on start,
* `drag.end.<id>` on end and `drag.move.<id>` on every move. When element will be dragged over another element
* `drag.over.<id>` will be fired as well.
*
* Start event and start handler will be called in specified context or in context of the element with following parameters:
......@@ -3849,6 +3879,21 @@
return out;
};
/*\
* Paper.getSize
[ method ]
**
* Obtains current paper actual size.
**
= (object)
\*/
paperproto.getSize = function () {
var container = this.canvas.parentNode;
return {
width: container.offsetWidth,
height: container.offsetHeight
};
};
/*\
* Paper.setSize
[ method ]
**
......@@ -3866,7 +3911,7 @@
* Paper.setViewBox
[ method ]
**
* Sets the view box of the paper. Practically it gives you ability to zoom and pan whole paper surface by
* Sets the view box of the paper. Practically it gives you ability to zoom and pan whole paper surface by
* specifying new boundaries.
**
> Parameters
......@@ -4339,7 +4384,7 @@
elproto.getPath = function () {
var path,
getPath = R._getPath[this.type];
if (this.type == "text" || this.type == "set") {
return;
}
......@@ -4625,8 +4670,8 @@
}
}
return element;
//
//
//
//
// var a = params ? R.animation(params, ms, easing, callback) : anim,
// status = element.status(anim);
// return this.animate(a).status(a, status * anim.ms / a.ms);
......@@ -4982,7 +5027,21 @@
p[attr] = params[attr];
}
if (!json) {
return new Animation(params, ms);
// if percent-like syntax is used and end-of-all animation callback used
if(callback){
// find the last one
var lastKey = 0;
for(var i in params){
var percent = toInt(i);
if(params[has](i) && percent > lastKey){
lastKey = percent;
}
}
lastKey += '%';
// if already defined callback in the last keyframe, skip
!params[lastKey].callback && (params[lastKey].callback = callback);
}
return new Animation(params, ms);
} else {
easing && (p.easing = easing);
callback && (p.callback = callback);
......@@ -5254,7 +5313,7 @@
* Set.clear
[ method ]
**
* Removeds all elements from the set
* Removes all elements from the set
\*/
setproto.clear = function () {
while (this.length) {
......@@ -5731,6 +5790,11 @@
| paper.set(paper.circle(100, 100, 20), paper.circle(110, 100, 20)).red();
\*/
R.st = setproto;
eve.on("raphael.DOMload", function () {
loaded = true;
});
// Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
(function (doc, loaded, f) {
if (doc.readyState == null && doc.addEventListener){
......@@ -5746,10 +5810,6 @@
isLoaded();
})(document, "DOMContentLoaded");
eve.on("raphael.DOMload", function () {
loaded = true;
});
// ┌─────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël - JavaScript Vector Library │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\
......@@ -5853,7 +5913,7 @@
return null;
}
id = id.replace(/[\(\)\s,\xb0#]/g, "_");
if (element.gradient && id != element.gradient.id) {
SVG.defs.removeChild(element.gradient);
delete element.gradient;
......@@ -5882,7 +5942,7 @@
}
}
$(o, {
fill: "url(#" + id + ")",
fill: "url(" + document.location + "#" + id + ")",
opacity: 1,
"fill-opacity": 1
});
......@@ -5959,7 +6019,7 @@
}
if (type != "none") {
var pathId = "raphael-marker-" + type,
markerId = "raphael-marker-" + se + type + w + h;
markerId = "raphael-marker-" + se + type + w + h + "-obj" + o.id;
if (!R._g.doc.getElementById(pathId)) {
p.defs.appendChild($($("path"), {
"stroke-linecap": "round",
......@@ -6216,9 +6276,6 @@
if (o._.sx != 1 || o._.sy != 1) {
value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
}
if (o.paper._vbSize) {
value *= o.paper._vbSize;
}
node.setAttribute(att, value);
if (attrs["stroke-dasharray"]) {
addDashes(o, attrs["stroke-dasharray"], params);
......@@ -6359,6 +6416,13 @@
dif = a.y - (bb.y + bb.height / 2);
dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
},
getRealNode = function (node) {
if (node.parentNode && node.parentNode.tagName.toLowerCase() === "a") {
return node.parentNode;
} else {
return node;
}
}
Element = function (node, svg) {
var X = 0,
Y = 0;
......@@ -6394,7 +6458,7 @@
* Element.id
[ property (number) ]
**
* Unique id of the element. Especially usesful when you want to listen to events of the element,
* Unique id of the element. Especially useful when you want to listen to events of the element,
* because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
\*/
this.id = R._oid++;
......@@ -6599,7 +6663,7 @@
this.clip && $(this.clip, {transform: this.matrix.invert()});
this.pattern && updatePosition(this);
this.node && $(this.node, {transform: this.matrix});
if (_.sx != 1 || _.sy != 1) {
var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
this.attr({"stroke-width": sw});
......@@ -6636,7 +6700,8 @@
* Removes element from the paper.
\*/
elproto.remove = function () {
if (this.removed || !this.node.parentNode) {
var node = getRealNode(this.node);
if (this.removed || !node.parentNode) {
return;
}
var paper = this.paper;
......@@ -6646,11 +6711,12 @@
paper.defs.removeChild(this.gradient);
}
R._tear(this, paper);
if (this.node.parentNode.tagName.toLowerCase() == "a") {
this.node.parentNode.parentNode.removeChild(this.node.parentNode);
} else {
this.node.parentNode.removeChild(this.node);
}
node.parentNode.removeChild(node);
// Remove custom data for element
this.removeData();
for (var i in this) {
this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
}
......@@ -6661,13 +6727,35 @@
this.show();
var hide = true;
}
var canvasHidden = false,
containerStyle;
if (this.paper.canvas.parentElement) {
containerStyle = this.paper.canvas.parentElement.style;
} //IE10+ can't find parentElement
else if (this.paper.canvas.parentNode) {
containerStyle = this.paper.canvas.parentNode.style;
}
if(containerStyle && containerStyle.display == "none") {
canvasHidden = true;
containerStyle.display = "";
}
var bbox = {};
try {
bbox = this.node.getBBox();
} catch(e) {
// Firefox 3.0.x plays badly here
// Firefox 3.0.x, 25.0.1 (probably more versions affected) play badly here - possible fix
bbox = {
x: this.node.clientLeft,
y: this.node.clientTop,
width: this.node.clientWidth,
height: this.node.clientHeight
}
} finally {
bbox = bbox || {};
if(canvasHidden){
containerStyle.display = "none";
}
}
hide && this.hide();
return bbox;
......@@ -6824,11 +6912,8 @@
if (this.removed) {
return this;
}
if (this.node.parentNode.tagName.toLowerCase() == "a") {
this.node.parentNode.parentNode.appendChild(this.node.parentNode);
} else {
this.node.parentNode.appendChild(this.node);
}
var node = getRealNode(this.node);
node.parentNode.appendChild(node);
var svg = this.paper;
svg.top != this && R._tofront(this, svg);
return this;
......@@ -6844,12 +6929,9 @@
if (this.removed) {
return this;
}
var parent = this.node.parentNode;
if (parent.tagName.toLowerCase() == "a") {
parent.parentNode.insertBefore(this.node.parentNode, this.node.parentNode.parentNode.firstChild);
} else if (parent.firstChild != this.node) {
parent.insertBefore(this.node, this.node.parentNode.firstChild);
}
var node = getRealNode(this.node);
var parentNode = node.parentNode;
parentNode.insertBefore(node, parentNode.firstChild);
R._toback(this, this.paper);
var svg = this.paper;
return this;
......@@ -6862,14 +6944,16 @@
= (object) @Element
\*/
elproto.insertAfter = function (element) {
if (this.removed) {
if (this.removed || !element) {
return this;
}
var node = element.node || element[element.length - 1].node;
if (node.nextSibling) {
node.parentNode.insertBefore(this.node, node.nextSibling);
var node = getRealNode(this.node);
var afterNode = getRealNode(element.node || element[element.length - 1].node);
if (afterNode.nextSibling) {
afterNode.parentNode.insertBefore(node, afterNode.nextSibling);
} else {
node.parentNode.appendChild(this.node);
afterNode.parentNode.appendChild(node);
}
R._insertafter(this, element, this.paper);
return this;
......@@ -6882,11 +6966,13 @@
= (object) @Element
\*/
elproto.insertBefore = function (element) {
if (this.removed) {
if (this.removed || !element) {
return this;
}
var node = element.node || element[0].node;
node.parentNode.insertBefore(this.node, node);
var node = getRealNode(this.node);
var beforeNode = getRealNode(element.node || element[0].node);
beforeNode.parentNode.insertBefore(node, beforeNode);
R._insertbefore(this, element, this.paper);
return this;
};
......@@ -6959,7 +7045,8 @@
y: y,
"text-anchor": "middle",
text: text,
font: R._availableAttrs.font,
"font-family": R._availableAttrs["font-family"],
"font-size": R._availableAttrs["font-size"],
stroke: "none",
fill: "#000"
};
......@@ -6998,7 +7085,8 @@
height: height,
version: 1.1,
width: width,
xmlns: "http://www.w3.org/2000/svg"
xmlns: "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink"
});
if (container == 1) {
cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
......@@ -7024,7 +7112,8 @@
};
R._engine.setViewBox = function (x, y, w, h, fit) {
eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
var size = mmax(w / this.width, h / this.height),
var paperSize = this.getSize(),
size = mmax(w / paperSize.width, h / paperSize.height),
top = this.top,
aspectRatio = fit ? "xMidYMid meet" : "xMinYMin",
vb,
......@@ -7160,7 +7249,7 @@
bites = /([clmz]),?([^clmz]*)/gi,
blurregexp = / progid:\S+Blur\([^\)]+\)/g,
val = /-?[^,\s-]+/g,
cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
cssDot = "position:absolute;left:0;top:0;width:1px;height:1px;behavior:url(#default#VML)",
zoom = 21600,
pathTypes = {path: 1, rect: 1, image: 1},
ovalTypes = {circle: 1, ellipse: 1},
......@@ -7304,6 +7393,7 @@
"blur" in params && o.blur(params.blur);
if (params.path && o.type == "path" || newpath) {
node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
o._.dirty = 1;
if (o.type == "image") {
o._.fillpos = [a.x, a.y];
o._.fillsize = [a.width, a.height];
......@@ -7629,7 +7719,10 @@
skew.matrix = Str(matrix);
skew.offset = matrix.offset();
}
oldt && (this._.transform = oldt);
if (oldt !== null) { // empty string value is true as well
this._.transform = oldt;
R._extractTransform(this, oldt);
}
return this;
};
elproto.rotate = function (deg, cx, cy) {
......@@ -7705,6 +7798,26 @@
!this.removed && (this.node.style.display = E);
return this;
};
// Needed to fix the vml setViewBox issues
elproto.auxGetBBox = R.el.getBBox;
elproto.getBBox = function(){
var b = this.auxGetBBox();
if (this.paper && this.paper._viewBoxShift)
{
var c = {};
var z = 1/this.paper._viewBoxShift.scale;
c.x = b.x - this.paper._viewBoxShift.dx;
c.x *= z;
c.y = b.y - this.paper._viewBoxShift.dy;
c.y *= z;
c.width = b.width * z;
c.height = b.height * z;
c.x2 = c.x + c.width;
c.y2 = c.y + c.height;
return c;
}
return b;
};
elproto._getBBox = function () {
if (this.removed) {
return {};
......@@ -7994,9 +8107,9 @@
};
R._engine.setViewBox = function (x, y, w, h, fit) {
R.eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
var width = this.width,
height = this.height,
size = 1 / mmax(w / width, h / height),
var paperSize = this.getSize(),
width = paperSize.width,
height = paperSize.height,
H, W;
if (fit) {
H = height / h;
......@@ -8022,7 +8135,13 @@
var createNode;
R._engine.initWin = function (win) {
var doc = win.document;
doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
if (doc.styleSheets.length < 31) {
doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
} else {
// no more room, add to the existing one
// http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
doc.styleSheets[0].addRule(".rvml", "behavior:url(#default#VML)");
}
try {
!doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
createNode = function (tagName) {
......
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