technosophos/querypath — pull request #128 by noisan (2013-10-04 00:56:51+00:00)
Title: Improve compatibility with jQuery

Hi :blush:

Thanks for merging the previous pull requests!

I'm wondering if I could make `append()` and several other methods
more compatible with jQuery.

This PR updates `prepareInsert()`, and improves the following methods:

* `append()`, `prepend()`, `before()`, `after()`
* `replaceWith()`
* `wrap()`, `wrapInner()`, `wrapAll()`

If the argument of prepareInsert() is a `DOMQuery`,
the current implementation only uses the first element in the DOMQuery.
The new implementation, however, uses all elements.
(...but I'm not sure if I'm on the right track or not.)

Here is a small test script that describes the difference:

Test script:
```php

';
$items = qp('

A

B

', 'p');

qp($xml)->find('div')->append($items)->writeXML();
qp($xml)->find('div')->prepend($items)->writeXML();
qp($xml)->find('div')->before($items)->writeXML();
qp($xml)->find('div')->after($items)->writeXML();

qp($xml)->find('div')->replaceWith($items)->writeXML();

qp($xml)->find('div')->wrap($items->removeChildren())->writeXML();
qp($xml)->find('div')->wrapInner($items->removeChildren())->writeXML();
qp($xml)->find('div')->wrapAll($items->removeChildren())->writeXML();
```

Current behavior:
```xml

A

A

A

A

A

// wrap() causes fatal error.
// wrapInner() causes fatal error.

```

Behavior after PR:
```xml

A

B

A

B

A

B

A

B

A

B

```

Thanks!!