ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

Fix .after() and .before() to accept sets/arrays of nodes (like other methods) #67

Closed benvinegar closed 12 years ago

benvinegar commented 12 years ago

Enables the following:

var created = $.create('<span>some <em>shiza</em></span>')
$('.after-created-examples').after(created);

This works using a number of other Bonzo methods, so it seemed natural to extend it here. For example, one could do the following just fine:

var created = $.create('<span>some <em>shiza</em></span>')
created.appendTo('.after-created-examples');
ded commented 12 years ago

thanks for the request. i'm confused how the example is an array of nodes. is it not just one node? <span> some <em>shiza</em></span> — tis still just one node to append (despite it having children).

i'll have a look at the tests and see what's going on.

benvinegar commented 12 years ago

In this case, it's just a Bonzo object. By "set", I meant Bonzo object. I should have included a test for arrays too.

benvinegar commented 12 years ago

Okay, I've seriously beefed up the test suite to test a range of inputs for each of after, before, append, prepend.

Also, I changed append and prepend to use Bonzo.create instead of normalize. This is to match jQuery's append and prepend behaviour, where if you pass append and prepend a DOM element (or jQuery) object, that object is cloned for each append target.

ded commented 12 years ago

oy. right on. will have a look

herbdaily commented 12 years ago

I also ran into a problem with after(). I replaced it in my code with parent().append() and it works fine. Maybe the after() method should be replaced with something like that?

herbdaily commented 12 years ago

D'oh! Nvm, only works for last element in its parent, which happens to be what I'm doing.

benvinegar commented 12 years ago

Getting constantly burned by this diff.

Another (related) issue is that one can't do this $('#foo').html($('

one
two
'));

ded commented 12 years ago

looks like @rvagg is starting to jump on these