Formatting clean up after merging pull request.
parent
47cbe2f9f1
commit
f5d9ff5bb7
39
src/set.js
39
src/set.js
|
@ -159,25 +159,28 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
|
|||
- eattr (string) attribute on the element to bind the attribute to
|
||||
= (object) Set object
|
||||
\*/
|
||||
setproto.bind = function(attr, a, b) {
|
||||
var data = {};
|
||||
if (typeof(a)=="function") {
|
||||
this.bindings[attr] = a;
|
||||
} else {
|
||||
var aname = b || attr;
|
||||
this.bindings[attr] = function(v) {
|
||||
data[aname] = v;
|
||||
a.attr(data);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
setproto.bind = function (attr, a, b) {
|
||||
var data = {};
|
||||
if (typeof a == "function") {
|
||||
this.bindings[attr] = a;
|
||||
} else {
|
||||
var aname = b || attr;
|
||||
this.bindings[attr] = function (v) {
|
||||
data[aname] = v;
|
||||
a.attr(data);
|
||||
};
|
||||
}
|
||||
return this;
|
||||
};
|
||||
setproto.attr = function (value) {
|
||||
var unbound = {};
|
||||
for (var k in value) {
|
||||
if (this.bindings[k]) this.bindings[k](value[k]);
|
||||
else unbound[k] = value[k];
|
||||
}
|
||||
var unbound = {};
|
||||
for (var k in value) {
|
||||
if (this.bindings[k]) {
|
||||
this.bindings[k](value[k]);
|
||||
} else {
|
||||
unbound[k] = value[k];
|
||||
}
|
||||
}
|
||||
for (var i = 0, ii = this.items.length; i < ii; i++) {
|
||||
this.items[i].attr(unbound);
|
||||
}
|
||||
|
|
34
test/set.js
34
test/set.js
|
@ -86,10 +86,10 @@ describe("Set methods", function () {
|
|||
var rect1 = s.rect(10, 20, 30, 40);
|
||||
var rect2 = s.rect(10, 20, 30, 40);
|
||||
var set = Snap.set(rect1, rect2);
|
||||
set.attr({"fill": "#ff0000"});
|
||||
set.attr({"fill": "#ff0000"});
|
||||
expect(rect1.node.getAttribute("fill")).to.be("#ff0000");
|
||||
expect(rect2.node.getAttribute("fill")).to.be("#ff0000");
|
||||
set.attr({"stroke": "#0000ff"});
|
||||
set.attr({"stroke": "#0000ff"});
|
||||
expect(rect1.node.getAttribute("stroke")).to.be("#0000ff");
|
||||
expect(rect2.node.getAttribute("stroke")).to.be("#0000ff");
|
||||
});
|
||||
|
@ -98,32 +98,32 @@ describe("Set methods", function () {
|
|||
var rect2 = s.rect(10, 20, 30, 40);
|
||||
var set = Snap.set(rect1, rect2);
|
||||
|
||||
// Setting "stroke" on set only applies it to rect1
|
||||
set.bind("stroke", rect1);
|
||||
// Setting "fill1" on set maps to fill attribute on rect1
|
||||
set.bind("fill1", rect1, "fill");
|
||||
// Setting "fill2" on set maps to fill attribute on rect2
|
||||
set.bind("fill2", function(v) { rect2.attr({"fill": v}); });
|
||||
// Setting "stroke" on set only applies it to rect1
|
||||
set.bind("stroke", rect1);
|
||||
// Setting "fill1" on set maps to fill attribute on rect1
|
||||
set.bind("fill1", rect1, "fill");
|
||||
// Setting "fill2" on set maps to fill attribute on rect2
|
||||
set.bind("fill2", function(v) { rect2.attr({"fill": v}); });
|
||||
|
||||
// Set everything to black
|
||||
rect1.attr({"fill": "#000000", "stroke": "#000000"})
|
||||
rect2.attr({"fill": "#000000", "stroke": "#000000"})
|
||||
// Set everything to black
|
||||
rect1.attr({"fill": "#000000", "stroke": "#000000"});
|
||||
rect2.attr({"fill": "#000000", "stroke": "#000000"});
|
||||
|
||||
set.attr({"fill1": "#00ff00"});
|
||||
set.attr({"fill1": "#00ff00"});
|
||||
expect(rect1.node.getAttribute("fill")).to.be("#00ff00");
|
||||
expect(rect2.node.getAttribute("fill")).to.be("#000000");
|
||||
|
||||
// Will trigger the fallback implementation of attr which is
|
||||
// to set that attribute on all elements in the set.
|
||||
set.attr({"fill": "#ff0000"});
|
||||
// Will trigger the fallback implementation of attr which is
|
||||
// to set that attribute on all elements in the set.
|
||||
set.attr({"fill": "#ff0000"});
|
||||
expect(rect1.node.getAttribute("fill")).to.be("#ff0000");
|
||||
expect(rect2.node.getAttribute("fill")).to.be("#ff0000");
|
||||
|
||||
set.attr({"fill2": "#00ff00"});
|
||||
set.attr({"fill2": "#00ff00"});
|
||||
expect(rect1.node.getAttribute("fill")).to.be("#ff0000");
|
||||
expect(rect2.node.getAttribute("fill")).to.be("#00ff00");
|
||||
|
||||
set.attr({"stroke": "#0000ff"});
|
||||
set.attr({"stroke": "#0000ff"});
|
||||
expect(rect1.node.getAttribute("stroke")).to.be("#0000ff");
|
||||
expect(rect2.node.getAttribute("stroke")).to.be("#000000");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue