Permalink
Browse files

Fixed tests. Added new tests for class methods. Fix for bug #227

  • Loading branch information...
DmitryBaranovskiy committed Apr 22, 2014
1 parent bbc1d4d commit 51afce7824bb2ea99811950d8170e7cd488e8789
Showing with 399 additions and 203 deletions.
  1. +4 −4 dist/snap.svg-min.js
  2. +86 −16 dist/snap.svg.js
  3. +159 −159 doc/reference.html
  4. +85 −15 src/svg.js
  5. +1 −1 template.dot
  6. +55 −0 test/class.js
  7. +8 −8 test/filter.js
  8. +1 −0 test/test.html

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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");
@@ -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;
@@ -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")) {
@@ -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 ]
@@ -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 ]
@@ -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) {
@@ -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;
Oops, something went wrong.

0 comments on commit 51afce7

Please sign in to comment.