Skip to content

Commit

Permalink
Fixed tests. Added new tests for class methods. Fix for bug #227
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBaranovskiy committed Apr 22, 2014
1 parent bbc1d4d commit 51afce7
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 203 deletions.
8 changes: 4 additions & 4 deletions dist/snap.svg-min.js

Large diffs are not rendered by default.

102 changes: 86 additions & 16 deletions dist/snap.svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// build: 2014-04-18
// build: 2014-04-22
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -1907,21 +1907,21 @@ function svgTransform2string(tstr) {
params.push(0, 0);
}
if (name == "scale") {
if (params.length == 2) {
if (params.length > 2) {
params = params.slice(0, 2);
} else if (params.length == 2) {
params.push(0, 0);
}
if (params.length == 1) {
params.push(params[0], 0, 0);
}
if (params.length > 2) {
params = params.slice(0, 2);
}
}
if (name == "skewX") {
res.push(["m", 1, 0, math.tan(rad(params[0])), 1, 0, 0]);
} else if (name == "skewY") {
res.push(["m", 1, math.tan(rad(params[0])), 0, 1, 0, 0]);
} else {
console.log(params);
res.push([name.charAt(0)].concat(params));
}
return all;
Expand Down Expand Up @@ -2746,28 +2746,94 @@ function arrayFirstValue(arr) {
}
}
var rgNotSpace = /\S+/g,
rgBadSpace = /[\t\r\n\f]/g;
rgBadSpace = /[\t\r\n\f]/g,
rgTrim = /(^\s+|\s+$)/g;
elproto.addClass = function (value) {
var classes = (value || "").match(rgNotSpace) || [],
elem = this.node,
cur = elem.className ? (" " + elem.className + " ").replace(rgBadSpace, " ") : " ",
className = elem.className.baseVal,
curClasses = className.match(rgNotSpace) || [],
j,
pos,
clazz,
finalValue;

if (classes.length) {
j = 0;
while ((clazz = classes[j++])) {
pos = curClasses.indexOf(clazz);
if (!~pos) {
curClasses.push(clazz);
}
}

finalValue = curClasses.join(" ");
if (className != finalValue) {
elem.className.baseVal = finalValue;
}
}
};
elproto.removeClass = function (value) {
var classes = (value || "").match(rgNotSpace) || [],
elem = this.node,
className = elem.className.baseVal,
curClasses = className.match(rgNotSpace) || [],
j,
pos,
clazz,
finalValue;
if (cur) {
if (curClasses.length) {
j = 0;
while ((clazz = classes[j++])) {
if (cur.indexOf(" " + clazz + " ") < 0) {
cur += clazz + " ";
pos = curClasses.indexOf(clazz);
if (~pos) {
curClasses.splice(pos, 1);
}
}

finalValue = cur.replace(/(^\s+|\s+$)/g, "");
if (elem.className != finalValue) {
elem.className = finalValue;
finalValue = curClasses.join(" ");
if (className != finalValue) {
elem.className.baseVal = finalValue;
}
}
};
elproto.hasClass = function (value) {
var elem = this.node,
className = elem.className.baseVal,
curClasses = className.match(rgNotSpace) || [];
return !!~curClasses.indexOf(value);
};
elproto.toggleClass = function (value, flag) {
if (flag != null) {
if (flag) {
return this.addClass(value);
} else {
return this.removeClass(value);
}
}
var classes = (value || "").match(rgNotSpace) || [],
elem = this.node,
className = elem.className.baseVal,
curClasses = className.match(rgNotSpace) || [],
j,
pos,
clazz,
finalValue;
j = 0;
while ((clazz = classes[j++])) {
pos = curClasses.indexOf(clazz);
if (~pos) {
curClasses.splice(pos, 1);
} else {
curClasses.push(clazz);
}
}

finalValue = curClasses.join(" ");
if (className != finalValue) {
elem.className.baseVal = finalValue;
}
};
elproto.clone = function () {
var clone = wrap(this.node.cloneNode(true));
if ($(clone.node, "id")) {
Expand All @@ -2777,7 +2843,6 @@ function arrayFirstValue(arr) {
clone.insertAfter(this);
return clone;
};
// SIERRA Element.toDefs(): If this _moves_ an element to the <defs> region, why is the return value a _clone_? Also unclear why it's called the _relative_ <defs> section. Perhaps _shared_?
/*\
* Element.toDefs
[ method ]
Expand All @@ -2791,8 +2856,6 @@ function arrayFirstValue(arr) {
defs.appendChild(this.node);
return this;
};
// SIERRA Element.pattern(): x/y/width/height data types are listed as both String and Number. Is that an error, or does it mean strings are coerced?
// SIERRA Element.pattern(): clarify that x/y are offsets that e.g., may add gutters between the tiles.
/*\
* Element.pattern
[ method ]
Expand Down Expand Up @@ -4090,6 +4153,10 @@ eve.on("snap.util.attr.path", function (value) {
eve.stop();
this.attr({d: value});
})(-1);
eve.on("snap.util.attr.class", function (value) {
eve.stop();
this.node.className.baseVal = value;
})(-1);
eve.on("snap.util.attr.viewBox", function (value) {
var vb;
if (is(value, "object") && "x" in value) {
Expand Down Expand Up @@ -4378,6 +4445,9 @@ eve.on("snap.util.getattr.path", function () {
eve.stop();
return p;
});
eve.on("snap.util.getattr.class", function () {
return this.node.className.baseVal;
});
function getFontSize() {
eve.stop();
return this.node.style.fontSize;
Expand Down
Loading

0 comments on commit 51afce7

Please sign in to comment.