Merge pull request #119 from sbking/sbking

Added Element.appendTo() and Element.prependTo()
master
Dmitry Baranovskiy 2013-11-18 03:55:31 -08:00
commit 5d66163ef5
2 changed files with 47 additions and 0 deletions

View File

@ -1657,6 +1657,20 @@ function arrayFirstValue(arr) {
el.paper = this.paper;
return this;
};
/*\
* Element.appendTo
[ method ]
**
* Appends the current element to the given one
**
- el (Element) parent element to append to
= (Element) the child element
\*/
elproto.appendTo = function (el) {
el = wrap(el);
el.append(this);
return this;
};
/*\
* Element.prepend
[ method ]
@ -1672,6 +1686,20 @@ function arrayFirstValue(arr) {
el.paper = this.paper;
return this;
};
/*\
* Element.prependTo
[ method ]
**
* Prepends the current element to the given one
**
- el (Element) parent element to prepend to
= (Element) the child element
\*/
elproto.prependTo = function (el) {
el = wrap(el);
el.prepend(this);
return this;
};
/*\
* Element.before
[ method ]

View File

@ -51,6 +51,13 @@ describe("Element methods", function () {
expect(rect2.node.parentNode).to.be(s.node);
expect(result).to.be(s);
});
it("Element.appendTo", function() {
var rect = s.rect(10, 20, 30, 40);
var result = rect.appendTo(s);
expect(rect.node.parentNode).to.be(s.node);
expect(s.node.lastChild).to.be(rect.node);
expect(result).to.be(rect);
});
it("Element.after", function() {
var circle = s.circle(10, 20, 30);
var rect = s.rect(10, 20, 30, 40);
@ -70,6 +77,18 @@ describe("Element methods", function () {
expect(group.node.firstChild).to.be(circle.node);
expect(result).to.be(group);
});
it("Element.prependTo", function() {
var rect = s.rect(10, 20, 30, 40);
var circle = s.circle(10, 20, 30);
var group = s.group();
s.append(group);
var result = rect.prependTo(group);
expect(group.node.firstChild).to.be(rect.node);
expect(result).to.be(rect);
result = circle.prependTo(group);
expect(group.node.firstChild).to.be(circle.node);
expect(result).to.be(circle);
});
it("Element.insertAfter", function() {
var circle = s.circle(10, 20, 30);
var rect = s.rect(10, 20, 30, 40);