Make WordPress Core

Ticket #46260: 46260.2.diff

File 46260.2.diff, 1.4 KB (added by pento, 6 years ago)
  • src/js/_enqueues/lib/comment-reply.js

    diff --git a/src/js/_enqueues/lib/comment-reply.js b/src/js/_enqueues/lib/comment-reply.js
    index 71f997328e..7e147c17d5 100644
    a b window.addComment = ( function( window ) { 
    4040        // The respond element.
    4141        var respondElement;
    4242
     43        // The mutation observer.
     44        var observer;
     45
    4346        // Initialise the events.
    4447        init();
    4548
     49        // Set up a MutationObserver to check for comments loaded late.
     50        observeChanges();
     51
    4652        /**
    4753         * Add events to links classed .comment-reply-link.
    4854         *
    window.addComment = ( function( window ) { 
    164170                }
    165171        }
    166172
     173        /**
     174         * Creates a mutation observer to check for newly inserted comments.
     175         */
     176        function observeChanges() {
     177                var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
     178                var observerOptions = {
     179                        characterData: false,
     180                        childList: true,
     181                        subTree: true,
     182                };
     183
     184                if ( ! MutationObserver ) {
     185                        return;
     186                }
     187
     188                observer = new MutationObserver( handleChanges );
     189                observer.observe( document.body, observerOptions );
     190        }
     191
     192        /**
     193         * Handles DOM changes, passing added nodes to init().
     194         *
     195         * @since 5.1.0
     196         *
     197         * @param {MutationRecord} mutations Object containing changes to the DOM document.
     198         */
     199        function handleChanges( mutations ) {
     200                init( mutations.addedNodes );
     201        }
     202
    167203        /**
    168204         * Backward compatible getter of data-* attribute.
    169205         *