diff --git a/wp-includes/js/comment-reply.js b/wp-includes/js/comment-reply.js index fae92ee237..75fc183e42 100644 --- a/wp-includes/js/comment-reply.js +++ b/wp-includes/js/comment-reply.js @@ -32,7 +32,7 @@ window.addComment = ( function( window ) { * Check browser supports dataset. * !! sets the variable to true if the property exists. */ - var supportsDataset = !! document.body.dataset; + var supportsDataset = !! document.documentElement.dataset; // For holding the cancel element. var cancelElement; @@ -46,11 +46,24 @@ window.addComment = ( function( window ) { // The mutation observer. var observer; - // Initialise the events. - init(); + if ( cutsTheMustard && document.readyState !== 'loading' ) { + ready(); + } else if ( cutsTheMustard ) { + window.addEventListener( 'DOMContentLoaded', ready, false ); + } - // Set up a MutationObserver to check for comments loaded late. - observeChanges(); + /** + * Sets up object variables after the DOM is ready. + * + * @since 5.1.1 + */ + function ready() { + // Initialise the events. + init(); + + // Set up a MutationObserver to check for comments loaded late. + observeChanges(); + } /** * Add events to links classed .comment-reply-link. @@ -163,6 +176,14 @@ window.addComment = ( function( window ) { postId = getDataAttribute( replyLink, 'postid'), follow; + if ( ! commId || ! parentId || ! respondId || ! postId ) { + /* + * Theme or plugin defines own link via custom `wp_list_comments()` callback + * and calls `moveForm()` either directly or via a custom event hook. + */ + return; + } + /* * Third party comments systems can hook into this function via the global scope, * therefore the click event needs to reference the global scope. diff --git a/wp-includes/js/comment-reply.min.js b/wp-includes/js/comment-reply.min.js index af43cd4617..a969b71e72 100644 --- a/wp-includes/js/comment-reply.min.js +++ b/wp-includes/js/comment-reply.min.js @@ -1 +1 @@ -window.addComment=function(a){function b(a){if(s&&(l=i(q.cancelReplyId),m=i(q.commentFormId),l)){l.addEventListener("touchstart",d),l.addEventListener("click",d);for(var b,f=c(a),g=0,h=f.length;g