Skip to content

bitovi/mutationobserver

Repository files navigation

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:

bower install mutationobserver

Usage

This polyfill uses 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:

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 and has a BSD license.

Otherwise this project is MIT licensed.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published