Permalink
Browse files

Fix the scope for `prependChildTo`

Similar to 589866d, prepending elements to another element in
a composite view, should not prepend to all the selectors that match
in the document.
  • Loading branch information...
1 parent 2c3c9d7 commit b0b20b7c19a0e457fa30981da34ef843d790fe52 @nhocki nhocki committed with christoomey Jan 15, 2013
@@ -41,7 +41,7 @@ _.extend(Support.CompositeView.prototype, Backbone.View.prototype, Support.Obser
prependChildTo: function (view, container) {
this.renderChild(view);
- $(container).prepend(view.el);
+ this.$(container).prepend(view.el);
},
_leaveChildren: function() {
@@ -91,6 +91,15 @@ describe("Support.CompositeView", function() {
expect($(view.el).find('.inside').text()).toEqual("Append to this!Orange!");
});
+
+ it("appends the element only to elements inside the view", function(){
+ var view = new blankView({el: $('<div><div class="main">Append to this!</div></div>')});
+ var div = $("<div class='main' id='outside'></div>");
+ view.appendChildTo(new orangeView(), ".main");
+
+ expect($(view.el).find('.main').text()).toEqual("Append to this!Orange!");
+ expect($("#outside").text()).toEqual("");
+ });
});
describe("#prependChild", function() {
@@ -108,11 +117,29 @@ describe("Support.CompositeView", function() {
$("#test1").text("Prepend to this!");
var view = new blankView({el: "#test"});
+ expect($("#test").text()).toEqual("");
+
+ $("#test").append($("#test1"));
view.prependChildTo(new orangeView(), "#test1");
- expect($("#test").text()).toEqual("");
expect($("#test1").text()).toEqual("Orange!Prepend to this!");
});
+
+ it("prepends child into a sub-element even if it is not added to the document", function() {
+ var view = new blankView({el: $('<div><div class="inside">Prepend to this!</div></div>')});
+ view.prependChildTo(new orangeView(), ".inside");
+
+ expect($(view.el).find('.inside').text()).toEqual("Orange!Prepend to this!");
+ });
+
+ it("prepends the element only to elements inside the view", function(){
+ var view = new blankView({el: $('<div><div class="main">Prepend to this!</div></div>')});
+ var div = $("<div class='main' id='outside'></div>");
+ view.prependChildTo(new orangeView(), ".main");
+
+ expect($(view.el).find('.main').text()).toEqual("Orange!Prepend to this!");
+ expect($("#outside").text()).toEqual("");
+ });
});
describe("#leave", function() {

0 comments on commit b0b20b7

Please sign in to comment.