ded/bonzo — pull request #86 by rvagg (2012-06-21 12:59:04+00:00)
Title: Put the insertion ordering and cloning bugs to bed

So I was being a boss on my Atari 2600, mastering my newly acquired first-edition paddles and I thought: why don't I put all this awesomeness to work fixing those Bonzo insertion issues instead?

Resolves #67, tho I didn't merge any of @benvinegar's code I did make sure his tests pass against my code (the tests kind of duplicate some what my new tests are doing so I didn't bother pulling them in). That pull can be closed when this is merged.

The first batch of commits are simply reorganising the test code. I pulled the JS out of index.html and split it up into multiple files to make it easier to manage. The *real* changes start at ce4b15c7. Most of the test code is left as-is (descemiolonified), mostly the new stuff is just in [dommanip_insertions.js](https://github.com/rvagg/bonzo/pull/new/fixinsertions#diff-6).

1. Fix ordering of all prepending insertion methods (`prepend()`, `before()`, `prependTo()`, `insertBefore()`) so they are consistent and work as you would expect--nodes remain in their original order after they are prepended.
2. Ensure that cloning occurs where it needs to. The methods that use `insert()` (`appendTo()`, `prependTo()`, `insertAfter()`, `insertBefore()`) were working mostly OK but the others didn't do any cloning so stuff gets lost when you're doing multiple insertions in one call. I pulled out the cloning code from `insert()` and let `normalize()` call it where required.
3. Ensure that all insertion methods can be called with raw nodes, arrays of nodes, Bonzo objects and HTML strings (where appropriate).

Tested on all browsers that matter. Didn't test on OS X cause my Mac VM is busted at the moment but that's not really an important target these days anyway is it?