Source: observer/MutationObserver.js

(function () {
    /**
     * observes mutation events
     * @augments Help4.observer.Observer
     */
    Help4.observer.MutationObserver = class extends Help4.observer.Observer {
        /**
         * @override
         * @param {Help4.observer.Callback} callback
         */
        constructor(callback) {
            if (!Help4.observer.MutationObserver.isSupported()) {
                throw new Error('MutationObserver: Not supported!');
            }

            super(callback, {
                statics: {
                    _mutationObserver: {destroy: false}
                }
            });
            this._mutationObserver = new Help4.MutationObserver(this._callback);
        }

        /**
         * whether MutationObserver is supported by the browser
         * @returns {boolean}
         */
        static isSupported() {
            return !!Help4.MutationObserver;
        }

        /**
         * observes mutation events in a certain window
         * @override
         * @param {Window} target - the window
         * @param {Object} options - configuraton for mutation observer
         * @returns {Help4.observer.MutationObserver}
         */
        observe(target, options) {
            // one MutationObserver is able to observe multiple windows
            super.observe(target, options);
            this._mutationObserver.observe(target, options);
            return this;
        }

        /**
         * @override
         * @returns {Help4.observer.MutationObserver}
         */
        disconnect() {
            this._mutationObserver.disconnect();
            super.disconnect();
            return this;
        }
    }
})();