Added Element.appendTo() and Element.prependTo()

master
Stephen King 2013-11-18 01:03:26 -08:00
parent 36958d25c2
commit 38af3ec9f1
2 changed files with 47 additions and 0 deletions

View File

@ -1642,6 +1642,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 ]
@ -1657,6 +1671,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);