Skip to content

Commit 51afce7

Browse files
Fixed tests. Added new tests for class methods. Fix for bug #227
1 parent bbc1d4d commit 51afce7

8 files changed

Lines changed: 399 additions & 203 deletions

File tree

dist/snap.svg-min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/snap.svg.js

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616
//
17-
// build: 2014-04-18
17+
// build: 2014-04-22
1818
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
1919
//
2020
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1907,21 +1907,21 @@ function svgTransform2string(tstr) {
19071907
params.push(0, 0);
19081908
}
19091909
if (name == "scale") {
1910-
if (params.length == 2) {
1910+
if (params.length > 2) {
1911+
params = params.slice(0, 2);
1912+
} else if (params.length == 2) {
19111913
params.push(0, 0);
19121914
}
19131915
if (params.length == 1) {
19141916
params.push(params[0], 0, 0);
19151917
}
1916-
if (params.length > 2) {
1917-
params = params.slice(0, 2);
1918-
}
19191918
}
19201919
if (name == "skewX") {
19211920
res.push(["m", 1, 0, math.tan(rad(params[0])), 1, 0, 0]);
19221921
} else if (name == "skewY") {
19231922
res.push(["m", 1, math.tan(rad(params[0])), 0, 1, 0, 0]);
19241923
} else {
1924+
console.log(params);
19251925
res.push([name.charAt(0)].concat(params));
19261926
}
19271927
return all;
@@ -2746,28 +2746,94 @@ function arrayFirstValue(arr) {
27462746
}
27472747
}
27482748
var rgNotSpace = /\S+/g,
2749-
rgBadSpace = /[\t\r\n\f]/g;
2749+
rgBadSpace = /[\t\r\n\f]/g,
2750+
rgTrim = /(^\s+|\s+$)/g;
27502751
elproto.addClass = function (value) {
27512752
var classes = (value || "").match(rgNotSpace) || [],
27522753
elem = this.node,
2753-
cur = elem.className ? (" " + elem.className + " ").replace(rgBadSpace, " ") : " ",
2754+
className = elem.className.baseVal,
2755+
curClasses = className.match(rgNotSpace) || [],
2756+
j,
2757+
pos,
2758+
clazz,
2759+
finalValue;
2760+
2761+
if (classes.length) {
2762+
j = 0;
2763+
while ((clazz = classes[j++])) {
2764+
pos = curClasses.indexOf(clazz);
2765+
if (!~pos) {
2766+
curClasses.push(clazz);
2767+
}
2768+
}
2769+
2770+
finalValue = curClasses.join(" ");
2771+
if (className != finalValue) {
2772+
elem.className.baseVal = finalValue;
2773+
}
2774+
}
2775+
};
2776+
elproto.removeClass = function (value) {
2777+
var classes = (value || "").match(rgNotSpace) || [],
2778+
elem = this.node,
2779+
className = elem.className.baseVal,
2780+
curClasses = className.match(rgNotSpace) || [],
27542781
j,
2782+
pos,
27552783
clazz,
27562784
finalValue;
2757-
if (cur) {
2785+
if (curClasses.length) {
27582786
j = 0;
27592787
while ((clazz = classes[j++])) {
2760-
if (cur.indexOf(" " + clazz + " ") < 0) {
2761-
cur += clazz + " ";
2788+
pos = curClasses.indexOf(clazz);
2789+
if (~pos) {
2790+
curClasses.splice(pos, 1);
27622791
}
27632792
}
27642793

2765-
finalValue = cur.replace(/(^\s+|\s+$)/g, "");
2766-
if (elem.className != finalValue) {
2767-
elem.className = finalValue;
2794+
finalValue = curClasses.join(" ");
2795+
if (className != finalValue) {
2796+
elem.className.baseVal = finalValue;
27682797
}
27692798
}
27702799
};
2800+
elproto.hasClass = function (value) {
2801+
var elem = this.node,
2802+
className = elem.className.baseVal,
2803+
curClasses = className.match(rgNotSpace) || [];
2804+
return !!~curClasses.indexOf(value);
2805+
};
2806+
elproto.toggleClass = function (value, flag) {
2807+
if (flag != null) {
2808+
if (flag) {
2809+
return this.addClass(value);
2810+
} else {
2811+
return this.removeClass(value);
2812+
}
2813+
}
2814+
var classes = (value || "").match(rgNotSpace) || [],
2815+
elem = this.node,
2816+
className = elem.className.baseVal,
2817+
curClasses = className.match(rgNotSpace) || [],
2818+
j,
2819+
pos,
2820+
clazz,
2821+
finalValue;
2822+
j = 0;
2823+
while ((clazz = classes[j++])) {
2824+
pos = curClasses.indexOf(clazz);
2825+
if (~pos) {
2826+
curClasses.splice(pos, 1);
2827+
} else {
2828+
curClasses.push(clazz);
2829+
}
2830+
}
2831+
2832+
finalValue = curClasses.join(" ");
2833+
if (className != finalValue) {
2834+
elem.className.baseVal = finalValue;
2835+
}
2836+
};
27712837
elproto.clone = function () {
27722838
var clone = wrap(this.node.cloneNode(true));
27732839
if ($(clone.node, "id")) {
@@ -2777,7 +2843,6 @@ function arrayFirstValue(arr) {
27772843
clone.insertAfter(this);
27782844
return clone;
27792845
};
2780-
// 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_?
27812846
/*\
27822847
* Element.toDefs
27832848
[ method ]
@@ -2791,8 +2856,6 @@ function arrayFirstValue(arr) {
27912856
defs.appendChild(this.node);
27922857
return this;
27932858
};
2794-
// 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?
2795-
// SIERRA Element.pattern(): clarify that x/y are offsets that e.g., may add gutters between the tiles.
27962859
/*\
27972860
* Element.pattern
27982861
[ method ]
@@ -4090,6 +4153,10 @@ eve.on("snap.util.attr.path", function (value) {
40904153
eve.stop();
40914154
this.attr({d: value});
40924155
})(-1);
4156+
eve.on("snap.util.attr.class", function (value) {
4157+
eve.stop();
4158+
this.node.className.baseVal = value;
4159+
})(-1);
40934160
eve.on("snap.util.attr.viewBox", function (value) {
40944161
var vb;
40954162
if (is(value, "object") && "x" in value) {
@@ -4378,6 +4445,9 @@ eve.on("snap.util.getattr.path", function () {
43784445
eve.stop();
43794446
return p;
43804447
});
4448+
eve.on("snap.util.getattr.class", function () {
4449+
return this.node.className.baseVal;
4450+
});
43814451
function getFontSize() {
43824452
eve.stop();
43834453
return this.node.style.fontSize;

0 commit comments

Comments
 (0)