Travis build: 1252

This commit is contained in:
30secondsofcode
2018-01-16 14:03:01 +00:00
parent 46c784b13b
commit ba495b3230
3 changed files with 79 additions and 10 deletions

View File

@ -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 ![advanced](/advanced.svg)
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

View File

@ -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({
observer.observe(
element,
Object.assign(
{
childList: true,
attributes: true,
attributeOldValue: true,
characterData: true,
characterDataOldValue: true,
subtree: true
}, options));
},
options
)
);
return observer;
}
};
```
```js