Travis build: 1252
This commit is contained in:
43
README.md
43
README.md
@ -163,6 +163,7 @@ average(1, 2, 3);
|
||||
* [`hasClass`](#hasclass)
|
||||
* [`hide`](#hide)
|
||||
* [`httpsRedirect`](#httpsredirect)
|
||||
* [`observeMutations`](#observemutations-)
|
||||
* [`off`](#off)
|
||||
* [`on`](#on)
|
||||
* [`onUserInputChange`](#onuserinputchange-)
|
||||
@ -2228,6 +2229,48 @@ httpsRedirect(); // If you are on http://mydomain.com, you are redirected to htt
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### observeMutations 
|
||||
|
||||
Returns a new MutationObserver and runs the provided callback for each mutation on the specified element.
|
||||
|
||||
Use a [`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) to observe mutations on the given element.
|
||||
Use `Array.forEach()` to run the callback for each mutation that is observed.
|
||||
Omit the third argument, `options`, to use the default [options](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit) (all `true`).
|
||||
|
||||
```js
|
||||
const observeMutations = (element, callback, options) => {
|
||||
const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
|
||||
observer.observe(
|
||||
element,
|
||||
Object.assign(
|
||||
{
|
||||
childList: true,
|
||||
attributes: true,
|
||||
attributeOldValue: true,
|
||||
characterData: true,
|
||||
characterDataOldValue: true,
|
||||
subtree: true
|
||||
},
|
||||
options
|
||||
)
|
||||
);
|
||||
return observer;
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
const obs = observeMutations(document, console.log); // Logs all mutations that happen on the page
|
||||
obs.disconnect(); // Disconnects the observer and stops logging mutations on the page
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### off
|
||||
|
||||
Removes an event listener from an element.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -9,16 +9,22 @@ Omit the third argument, `options`, to use the default [options](https://develop
|
||||
```js
|
||||
const observeMutations = (element, callback, options) => {
|
||||
const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
|
||||
observer.observe(element, Object.assign({
|
||||
childList: true,
|
||||
attributes: true,
|
||||
attributeOldValue: true,
|
||||
characterData: true,
|
||||
characterDataOldValue: true,
|
||||
subtree: true
|
||||
}, options));
|
||||
observer.observe(
|
||||
element,
|
||||
Object.assign(
|
||||
{
|
||||
childList: true,
|
||||
attributes: true,
|
||||
attributeOldValue: true,
|
||||
characterData: true,
|
||||
characterDataOldValue: true,
|
||||
subtree: true
|
||||
},
|
||||
options
|
||||
)
|
||||
);
|
||||
return observer;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user