MutationObserver polyfill
A small polyfill to handle mutation observer subtree modifications events
(function() {
  var MutationObserver;
  if (window.MutationObserver != null) {
    return;
  }
  MutationObserver = (function() {
    function MutationObserver(callBack) {
      this.callBack = callBack;
    }
    MutationObserver.prototype.observe = function(element, options) {
      this.element = element;
      return this.interval = setInterval((function(_this) {
        return function() {
          var html;
          html = _this.element.innerHTML;
          if (html !== _this.oldHtml) {
            _this.oldHtml = html;
            return _this.callBack.apply(null);
          }
        };
      })(this), 200);
    };
    MutationObserver.prototype.disconnect = function() {
      return window.clearInterval(this.interval);
    };
    return MutationObserver;
  })();
  window.MutationObserver = MutationObserver;
}).call(this);And for who might appreciate, here's the coffeescript version ;-)
Written by Carlo
Related protips
1 Response
 
That was super useful since PhantomJS pre 2.0 still doesn't support MutationObserver. Thanks! :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Coffescript 
Authors
 
kajyr
4.474K
 
laudenberg
2.292K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#
 
