Skip to content

Commit

Permalink
Fix for #229 and #207
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBaranovskiy committed Apr 18, 2014
1 parent c58fc82 commit bbc1d4d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 128 deletions.
6 changes: 3 additions & 3 deletions dist/snap.svg-min.js

Large diffs are not rendered by default.

39 changes: 17 additions & 22 deletions dist/snap.svg.js
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// build: 2014-03-07
// build: 2014-04-18
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -852,6 +852,9 @@ var has = "hasOwnProperty",

function $(el, attr) {
if (attr) {
if (el == "#text") {
el = glob.doc.createTextNode(attr.text || "");
}
if (typeof el == "string") {
el = $(el);
}
Expand Down Expand Up @@ -2051,10 +2054,6 @@ var contains = glob.doc.contains || glob.doc.compareDocumentPosition ?
return false;
};
function getSomeDefs(el) {
var cache = Snap._.someDefs;
if (cache && contains(cache.ownerDocument.documentElement, cache)) {
return cache;
}
var p = (el.node.ownerSVGElement && wrap(el.node.ownerSVGElement)) ||
(el.node.parentNode && wrap(el.node.parentNode)) ||
Snap.select("svg") ||
Expand All @@ -2064,7 +2063,6 @@ function getSomeDefs(el) {
if (!defs) {
defs = make("defs", p.node).node;
}
Snap._.someDefs = defs;
return defs;
}
Snap._.getSomeDefs = getSomeDefs;
Expand Down Expand Up @@ -2099,9 +2097,9 @@ function unit2px(el, name, value) {
}
function set(nam, f) {
if (name == null) {
out[nam] = f(el.attr(nam));
out[nam] = f(el.attr(nam) || 0);
} else if (nam == name) {
out = f(value == null ? el.attr(nam) : value);
out = f(value == null ? el.attr(nam) || 0 : value);
}
}
switch (el.type) {
Expand Down Expand Up @@ -2290,7 +2288,7 @@ function arrayFirstValue(arr) {
json[params] = value;
params = json;
} else {
return arrayFirstValue(eve("snap.util.getattr."+params, el));
return arrayFirstValue(eve("snap.util.getattr." + params, el));
}
}
for (var att in params) {
Expand Down Expand Up @@ -3265,7 +3263,6 @@ function make(name, parent) {
var res = $(name);
parent.appendChild(res);
var el = wrap(res);
el.type = name;
return el;
}
function Paper(w, h) {
Expand Down Expand Up @@ -3478,7 +3475,7 @@ function gradientRadial(defs, cx, cy, r, fx, fy) {
if (ry == null) {
ry = rx;
}
if (is(x, "object") && "x" in x) {
if (is(x, "object") && x == "[object Object]") {
attr = x;
} else if (x != null) {
attr = {
Expand Down Expand Up @@ -3510,7 +3507,7 @@ function gradientRadial(defs, cx, cy, r, fx, fy) {
\*/
proto.circle = function (cx, cy, r) {
var attr;
if (is(cx, "object") && "cx" in cx) {
if (is(cx, "object") && cx == "[object Object]") {
attr = cx;
} else if (cx != null) {
attr = {
Expand Down Expand Up @@ -3585,7 +3582,7 @@ function gradientRadial(defs, cx, cy, r, fx, fy) {
\*/
proto.ellipse = function (cx, cy, rx, ry) {
var el = make("ellipse", this.node);
if (is(cx, "object") && "cx" in cx) {
if (is(cx, "object") && cx == "[object Object]") {
el.attr(cx);
} else if (cx != null) {
el.attr({
Expand Down Expand Up @@ -3667,10 +3664,6 @@ function gradientRadial(defs, cx, cy, r, fx, fy) {
\*/
proto.group = proto.g = function (first) {
var el = make("g", this.node);
el.add = add2group;
for (var method in proto) if (proto[has](method)) {
el[method] = proto[method];
}
if (arguments.length == 1 && first && !first.type) {
el.attr(first);
} else if (arguments.length) {
Expand Down Expand Up @@ -4470,6 +4463,7 @@ Snap.plugin = function (f) {
glob.win.Snap = Snap;
return Snap;
}());

// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -4977,15 +4971,15 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
},
ellipse: function (el) {
var attr = unit2px(el);
return ellipsePath(attr.cx, attr.cy, attr.rx, attr.ry);
return ellipsePath(attr.cx || 0, attr.cy || 0, attr.rx, attr.ry);
},
rect: function (el) {
var attr = unit2px(el);
return rectPath(attr.x, attr.y, attr.width, attr.height, attr.rx, attr.ry);
return rectPath(attr.x || 0, attr.y || 0, attr.width, attr.height, attr.rx, attr.ry);
},
image: function (el) {
var attr = unit2px(el);
return rectPath(attr.x, attr.y, attr.width, attr.height);
return rectPath(attr.x || 0, attr.y || 0, attr.width, attr.height);
},
text: function (el) {
var bbox = el.node.getBBox();
Expand All @@ -5000,7 +4994,7 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
},
line: function (el) {
return "M" + [el.attr("x1"), el.attr("y1"), el.attr("x2"), el.attr("y2")];
return "M" + [el.attr("x1") || 0, el.attr("y1") || 0, el.attr("x2"), el.attr("y2")];
},
polyline: function (el) {
return "M" + el.attr("points");
Expand Down Expand Up @@ -5421,7 +5415,7 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
d.Y = path[2];
break;
case "A":
path = ["C"].concat(a2c[apply](0, [d.x, d.y].concat(path.slice(1))));
path = ["C"].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1))));
break;
case "S":
if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S.
Expand Down Expand Up @@ -5895,6 +5889,7 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
Snap.path.toString = toString;
Snap.path.clone = pathClone;
});

// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit bbc1d4d

Please sign in to comment.