Make WordPress Core

Changeset 44794


Ignore:
Timestamp:
03/05/2019 01:51:31 AM (7 years ago)
Author:
peterwilsoncc
Message:

Comments: Allow for comment-reply.js to be loaded in the HTML header.

Allows for themes or plugins setting the comment-reply JavaScript as a dependency of an HTML header script. This in turn causes comment-reply.js to be loaded early, requiring execution to be delayed.

Props pento, peterwilsoncc, jorbin for feedback.
Fixes #46280.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/comment-reply.js

    r44748 r44794  
    3333         * !! sets the variable to true if the property exists.
    3434         */
    35         var supportsDataset = !! document.body.dataset;
     35        var supportsDataset = !! document.documentElement.dataset;
    3636
    3737        // For holding the cancel element.
     
    4747        var observer;
    4848
    49         // Initialise the events.
    50         init();
    51 
    52         // Set up a MutationObserver to check for comments loaded late.
    53         observeChanges();
     49        if ( cutsTheMustard && document.readyState !== 'loading' ) {
     50                ready();
     51        } else if ( cutsTheMustard ) {
     52                window.addEventListener( 'DOMContentLoaded', ready, false );
     53        }
     54
     55        /**
     56         * Sets up object variables after the DOM is ready.
     57         *
     58         * @since 5.1.1
     59         */
     60        function ready() {
     61                // Initialise the events.
     62                init();
     63
     64                // Set up a MutationObserver to check for comments loaded late.
     65                observeChanges();
     66        }
    5467
    5568        /**
     
    163176                        postId    = getDataAttribute( replyLink, 'postid'),
    164177                        follow;
     178
     179                if ( ! commId || ! parentId || ! respondId || ! postId ) {
     180                        /*
     181                         * Theme or plugin defines own link via custom `wp_list_comments()` callback
     182                         * and calls `moveForm()` either directly or via a custom event hook.
     183                         */
     184                        return;
     185                }
    165186
    166187                /*
Note: See TracChangeset for help on using the changeset viewer.