Created
July 8, 2016 21:54
-
-
Save mikermcneil/e7a799fc300fb462a88a19ba74e6a01d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Docs: | |
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit | |
// | |
// This is what it actually means: | |
// ========================================================================================================= | |
var $elementToStretch = $('#the-element'); | |
var debouncedStretchInnards = _.debounce(stretchInnards); | |
var $allAncestors = $elementToStretch.parents(); | |
editorMD.ancestorObservers = _.reduce($allAncestors, function (memo, ancestorRawDOMElement) { | |
var observer = new MutationObserver(function onMutation(){ debouncedStretchInnards(); }); | |
observer.observe(ancestorRawDOMElement, { attributes: true, attributeOldValue: true, attributeFilter: ['style'] }); | |
// Track ancestor observer. | |
memo.push(observer); | |
return memo; | |
}, []); | |
// Then in onRemove, call `.disconnect()` on each "observer" in `editorMD.ancestorObservers`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment