Travis build: 1252
This commit is contained in:
43
README.md
43
README.md
@ -163,6 +163,7 @@ average(1, 2, 3);
|
|||||||
* [`hasClass`](#hasclass)
|
* [`hasClass`](#hasclass)
|
||||||
* [`hide`](#hide)
|
* [`hide`](#hide)
|
||||||
* [`httpsRedirect`](#httpsredirect)
|
* [`httpsRedirect`](#httpsredirect)
|
||||||
|
* [`observeMutations`](#observemutations-)
|
||||||
* [`off`](#off)
|
* [`off`](#off)
|
||||||
* [`on`](#on)
|
* [`on`](#on)
|
||||||
* [`onUserInputChange`](#onuserinputchange-)
|
* [`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)
|
<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
|
### off
|
||||||
|
|
||||||
Removes an event listener from an element.
|
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
|
```js
|
||||||
const observeMutations = (element, callback, options) => {
|
const observeMutations = (element, callback, options) => {
|
||||||
const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
|
const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
|
||||||
observer.observe(element, Object.assign({
|
observer.observe(
|
||||||
|
element,
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
childList: true,
|
childList: true,
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeOldValue: true,
|
attributeOldValue: true,
|
||||||
characterData: true,
|
characterData: true,
|
||||||
characterDataOldValue: true,
|
characterDataOldValue: true,
|
||||||
subtree: true
|
subtree: true
|
||||||
}, options));
|
},
|
||||||
|
options
|
||||||
|
)
|
||||||
|
);
|
||||||
return observer;
|
return observer;
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user