Skip to content
Permalink
Browse files

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.
Merges [44794] to the 5.1 branch.
Fixes #46280.



git-svn-id: https://develop.svn.wordpress.org/branches/5.1@44795 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
peterwilsoncc committed Mar 5, 2019
1 parent 11b3b4b commit 8f8b1c9237ee56493474a5d79b77942c1a55f6a0
Showing with 26 additions and 5 deletions.
  1. +26 −5 src/js/_enqueues/lib/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.

0 comments on commit 8f8b1c9

Please sign in to comment.
You can’t perform that action at this time.