Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bitovi/mutationobserver


https://github.com/bitovi/mutationobserver

Last synced: about 5 hours ago
JSON representation

Awesome Lists containing this project

README

        

# mutationobserver

This repository includes a collection of MutationObserver polyfills so that you can use MutationObserver in all browsers (>= IE8). The browser breakdown is:

* IE8: jQuery polyfill
* IE9 and IE10: Mutation Events polyfill
* IE11, Chrome, Safari, Firefox, Opera: Native MutationObserver

# Installation

This polyfill is available from [Bower](http://bower.io/):

```shell
bower install mutationobserver
```

# Usage

This polyfill uses [Steal](https://github.com/bitovi/steal) so the best way to use it is to steal the main `mutationobserver.js` file which will return a MutationObserver constructor that you can use:

```javascript
steal("mutationobserver", function(Observer) {
var observer = new Observer(function(mutations) {
console.log(mutations);
});

observer.observe($("body")[0], {
attributes: true,
childList: true
});
});
```

# Options support

| Feature | Native | Events Polyfill | jQuery Polyfill |
| --------------------- |:-------------:| ----------------:| ----------------:|
| childList | ✓ | ✓ | ✓ |
| attributes | ✓ | ✓ | ✓ |
| characterData | ✓ | ✓ | ✗ |
| subtree | ✓ | ✓ | ✓ |
| attributeOldValue | ✓ | ✓ | ✓ |
| characterDataOldValue | ✓ | ✓ | ✗ |
| attributeFilter | ✓ | ✓ | ✓ |

jQuery has no way to manipulate a CharacterData's data property, so there is no practical way to do this. Most commonly people manipulate text content using `text()` which would result in new TextNodes anyways.

# Development

To contribute first clone the repository then run `bower install` which will install the development dependencies (just QUnit). Then navigate to `test/test.html` to see the tests. If you find a bug create a test in one of the appropriate files:

1. `attributes_test.js` is for the "attributes" event.
2. `childlist_test.js` is for the "childList" event.
3. `mutationobserver_test.js` is for generic tests that make sure the API is fully supported.

# License

The Mutation Events polyfill is taken from the [Polymer Project](https://github.com/Polymer/MutationObservers) and has a BSD license.

Otherwise this project is MIT licensed.