Make WordPress Core

Ticket #46280: 46280.diff

File 46280.diff, 2.1 KB (added by pento, 5 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 fae92ee237..7398cc409e 100644
    a b  
    1010 */
    1111window.addComment = ( function( window ) {
    1212        // Avoid scope lookups on commonly used variables.
    13         var document = window.document;
     13        var document;
    1414
    1515        // Settings.
    1616        var config = {
    window.addComment = ( function( window ) { 
    2323        };
    2424
    2525        // Cross browser MutationObserver.
    26         var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
     26        var MutationObserver;
    2727
    2828        // Check browser cuts the mustard.
    29         var cutsTheMustard = 'querySelector' in document && 'addEventListener' in window;
     29        var cutsTheMustard;
    3030
    31         /*
    32          * Check browser supports dataset.
    33          * !! sets the variable to true if the property exists.
    34          */
    35         var supportsDataset = !! document.body.dataset;
     31        // Check browser supports dataset.
     32        var supportsDataset;
    3633
    3734        // For holding the cancel element.
    3835        var cancelElement;
    window.addComment = ( function( window ) { 
    4643        // The mutation observer.
    4744        var observer;
    4845
    49         // Initialise the events.
    50         init();
     46        if ( window.document && window.document.body ) {
     47                ready();
     48        } else if ( window.addEventListener ) {
     49                window.addEventListener( 'DOMContentLoaded', ready, false );
     50        }
     51
     52        /**
     53         * Sets up object variables after the DOM is ready.
     54         *
     55         * @since 5.1.0
     56         */
     57        function ready() {
     58                document = window.document;
     59
     60                MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
     61
     62                // Check browser cuts the mustard.
     63                cutsTheMustard = 'querySelector' in document && 'addEventListener' in window;
    5164
    52         // Set up a MutationObserver to check for comments loaded late.
    53         observeChanges();
     65                // !! sets the variable to true if the property exists.
     66                supportsDataset = !! document.body.dataset;
     67
     68                // Initialise the events.
     69                init();
     70
     71                // Set up a MutationObserver to check for comments loaded late.
     72                observeChanges();
     73        }
    5474
    5575        /**
    5676         * Add events to links classed .comment-reply-link.