-
Notifications
You must be signed in to change notification settings - Fork 1
/
whenInDom.min.js
1 lines (1 loc) · 1.15 KB
/
whenInDom.min.js
1
var WhenInDOM=function(a,b,c){var d=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;this.observer=null,this.callback=b,this.el=a,this.observeEl=c||document;var e=function(a,b){for(var c=a.length;c--;)if(a[c]===b||f(a[c],b))return!0;return!1},f=function(a,b){var c=document.documentElement;if(c.contains){b.nodeType!==1&&(b=b.parentNode);return a!==b&&a.contains(b)}if(c.compareDocumentPosition)return!!(a.compareDocumentPosition(b)&16)};this.init=function(){var a=this,b={childList:!0,subtree:!0};this.observer=new d(function(b){b.forEach(function(b){b.type=="childList"&&e(b.addedNodes,a.el)&&(a.stop(),a.callback())})}),this.observer.observe(this.observeEl,b)},this.crawl=function(){this.crawlEl&&this.crawlEl.parentNode&&(this.crawlEl.parentNode===this.observeEl||this.crawlEl.parentNode.nodeType>8?(this.stop(),this.callback()):this.crawlEl=this.crawlEl.parentNode)},this.crawlInit=function(){var a=this;this.crawlEl=this.el,this.crawlHandler=setInterval(function(){a.crawl.call(a)},10)},this.stop=function(){this.observer&&this.observer.disconnect(),this.crawlHandler&&clearInterval(this.crawlHandler)},d?this.init():this.crawlInit()}