Comments: Fix title not updating when replying to a comment
When replying to an existing comment, the comment form is moved to below the existing comment with JS, but the form heading was not being updated. This fixes the issue by introducing a new data-attribute to the reply link with the correct heading string, and applying that string to the heading when the form is moved. Props isabel_brison, azaozz, peterwilsoncc. Fixes #38009. Built from https://develop.svn.wordpress.org/trunk@47506 git-svn-id: http://core.svn.wordpress.org/trunk@47281 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
55482506a3
commit
b4e1e8f0d1
|
@ -1703,6 +1703,7 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null
|
|||
'postid' => $post->ID,
|
||||
'belowelement' => $args['add_below'] . '-' . $comment->comment_ID,
|
||||
'respondelement' => $args['respond_id'],
|
||||
'replyto' => sprintf( $args['reply_to_text'], $comment->comment_author ),
|
||||
);
|
||||
|
||||
$data_attribute_string = '';
|
||||
|
|
|
@ -15,6 +15,7 @@ window.addComment = ( function( window ) {
|
|||
// Settings.
|
||||
var config = {
|
||||
commentReplyClass : 'comment-reply-link',
|
||||
commentReplyTitleId : 'reply-title',
|
||||
cancelReplyId : 'cancel-comment-reply-link',
|
||||
commentFormId : 'commentform',
|
||||
temporaryFormId : 'wp-temp-form-div',
|
||||
|
@ -171,8 +172,14 @@ window.addComment = ( function( window ) {
|
|||
getElementById( config.parentIdFieldId ).value = '0';
|
||||
|
||||
// Move the respond form back in place of the temporary element.
|
||||
temporaryElement.parentNode.replaceChild( respondElement ,temporaryElement );
|
||||
var headingText = temporaryElement.textContent;
|
||||
temporaryElement.parentNode.replaceChild( respondElement, temporaryElement );
|
||||
cancelLink.style.display = 'none';
|
||||
var replyHeadingElement = getElementById( config.commentReplyTitleId );
|
||||
var replyHeadingTextNode = replyHeadingElement && replyHeadingElement.firstChild;
|
||||
if ( replyHeadingTextNode && replyHeadingTextNode.nodeType === Node.TEXT_NODE && headingText ) {
|
||||
replyHeadingTextNode.textContent = headingText;
|
||||
}
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
@ -184,11 +191,14 @@ window.addComment = ( function( window ) {
|
|||
* @param {Event} event The calling event.
|
||||
*/
|
||||
function clickEvent( event ) {
|
||||
var replyNode = getElementById( config.commentReplyTitleId );
|
||||
var defaultReplyHeading = replyNode && replyNode.firstChild.textContent;
|
||||
var replyLink = this,
|
||||
commId = getDataAttribute( replyLink, 'belowelement'),
|
||||
parentId = getDataAttribute( replyLink, 'commentid' ),
|
||||
respondId = getDataAttribute( replyLink, 'respondelement'),
|
||||
postId = getDataAttribute( replyLink, 'postid'),
|
||||
respondId = getDataAttribute( replyLink, 'respondelement' ),
|
||||
postId = getDataAttribute( replyLink, 'postid' ),
|
||||
replyTo = getDataAttribute( replyLink, 'replyto' ) || defaultReplyHeading,
|
||||
follow;
|
||||
|
||||
if ( ! commId || ! parentId || ! respondId || ! postId ) {
|
||||
|
@ -203,7 +213,7 @@ window.addComment = ( function( window ) {
|
|||
* Third party comments systems can hook into this function via the global scope,
|
||||
* therefore the click event needs to reference the global scope.
|
||||
*/
|
||||
follow = window.addComment.moveForm(commId, parentId, respondId, postId);
|
||||
follow = window.addComment.moveForm( commId, parentId, respondId, postId, replyTo );
|
||||
if ( false === follow ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
@ -292,8 +302,9 @@ window.addComment = ( function( window ) {
|
|||
* @param {String} commentId Database ID of comment being replied to.
|
||||
* @param {String} respondId HTML ID of 'respond' element.
|
||||
* @param {String} postId Database ID of the post.
|
||||
* @param {String} replyTo Form heading content.
|
||||
*/
|
||||
function moveForm( addBelowId, commentId, respondId, postId ) {
|
||||
function moveForm( addBelowId, commentId, respondId, postId, replyTo ) {
|
||||
// Get elements based on their IDs.
|
||||
var addBelowElement = getElementById( addBelowId );
|
||||
respondElement = getElementById( respondId );
|
||||
|
@ -303,11 +314,18 @@ window.addComment = ( function( window ) {
|
|||
var postIdField = getElementById( config.postIdFieldId );
|
||||
var element, cssHidden, style;
|
||||
|
||||
var replyHeading = getElementById( config.commentReplyTitleId );
|
||||
var replyHeadingTextNode = replyHeading && replyHeading.firstChild;
|
||||
|
||||
if ( ! addBelowElement || ! respondElement || ! parentIdField ) {
|
||||
// Missing key elements, fail.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'undefined' === typeof replyTo ) {
|
||||
replyTo = replyHeadingTextNode && replyHeadingTextNode.textContent;
|
||||
}
|
||||
|
||||
addPlaceHolder( respondElement );
|
||||
|
||||
// Set the value of the post.
|
||||
|
@ -319,7 +337,9 @@ window.addComment = ( function( window ) {
|
|||
|
||||
cancelElement.style.display = '';
|
||||
addBelowElement.parentNode.insertBefore( respondElement, addBelowElement.nextSibling );
|
||||
|
||||
if ( replyHeadingTextNode.nodeType === Node.TEXT_NODE ) {
|
||||
replyHeadingTextNode.textContent = replyTo;
|
||||
}
|
||||
/*
|
||||
* This is for backward compatibility with third party commenting systems
|
||||
* hooking into the event using older techniques.
|
||||
|
@ -387,6 +407,8 @@ window.addComment = ( function( window ) {
|
|||
function addPlaceHolder( respondElement ) {
|
||||
var temporaryFormId = config.temporaryFormId;
|
||||
var temporaryElement = getElementById( temporaryFormId );
|
||||
var replyElement = getElementById( config.commentReplyTitleId );
|
||||
var initialHeadingText = ( 'undefined' !== typeof replyElement ) ? replyElement.firstChild.textContent : '';
|
||||
|
||||
if ( temporaryElement ) {
|
||||
// The element already exists, no need to recreate.
|
||||
|
@ -396,6 +418,7 @@ window.addComment = ( function( window ) {
|
|||
temporaryElement = document.createElement( 'div' );
|
||||
temporaryElement.id = temporaryFormId;
|
||||
temporaryElement.style.display = 'none';
|
||||
temporaryElement.textContent = initialHeadingText;
|
||||
respondElement.parentNode.insertBefore( temporaryElement, respondElement );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
/*! This file is auto-generated */
|
||||
window.addComment=function(s){var u,f,v,y=s.document,p={commentReplyClass:"comment-reply-link",cancelReplyId:"cancel-comment-reply-link",commentFormId:"commentform",temporaryFormId:"wp-temp-form-div",parentIdFieldId:"comment_parent",postIdFieldId:"comment_post_ID"},e=s.MutationObserver||s.WebKitMutationObserver||s.MozMutationObserver,i="querySelector"in y&&"addEventListener"in s,n=!!y.documentElement.dataset;function t(){r(),function(){if(!e)return;new e(d).observe(y.body,{childList:!0,subtree:!0})}()}function r(e){if(i&&(u=I(p.cancelReplyId),f=I(p.commentFormId),u)){u.addEventListener("touchstart",a),u.addEventListener("click",a);var t=function(e){if((e.metaKey||e.ctrlKey)&&13===e.keyCode)return f.removeEventListener("keydown",t),e.preventDefault(),f.submit.click(),!1};f&&f.addEventListener("keydown",t);for(var n,r=function(e){var t,n=p.commentReplyClass;e&&e.childNodes||(e=y);t=y.getElementsByClassName?e.getElementsByClassName(n):e.querySelectorAll("."+n);return t}(e),d=0,o=r.length;d<o;d++)(n=r[d]).addEventListener("touchstart",l),n.addEventListener("click",l)}}function a(e){var t=I(p.temporaryFormId);t&&v&&(I(p.parentIdFieldId).value="0",t.parentNode.replaceChild(v,t),this.style.display="none",e.preventDefault())}function l(e){var t=this,n=m(t,"belowelement"),r=m(t,"commentid"),d=m(t,"respondelement"),o=m(t,"postid");n&&r&&d&&o&&!1===s.addComment.moveForm(n,r,d,o)&&e.preventDefault()}function d(e){for(var t=e.length;t--;)if(e[t].addedNodes.length)return void r()}function m(e,t){return n?e.dataset[t]:e.getAttribute("data-"+t)}function I(e){return y.getElementById(e)}return i&&"loading"!==y.readyState?t():i&&s.addEventListener("DOMContentLoaded",t,!1),{init:r,moveForm:function(e,t,n,r){var d=I(e);v=I(n);var o,i,a,l=I(p.parentIdFieldId),m=I(p.postIdFieldId);if(d&&v&&l){!function(e){var t=p.temporaryFormId,n=I(t);if(n)return;(n=y.createElement("div")).id=t,n.style.display="none",e.parentNode.insertBefore(n,e)}(v),r&&m&&(m.value=r),l.value=t,u.style.display="",d.parentNode.insertBefore(v,d.nextSibling),u.onclick=function(){return!1};try{for(var c=0;c<f.elements.length;c++)if(o=f.elements[c],i=!1,"getComputedStyle"in s?a=s.getComputedStyle(o):y.documentElement.currentStyle&&(a=o.currentStyle),(o.offsetWidth<=0&&o.offsetHeight<=0||"hidden"===a.visibility)&&(i=!0),"hidden"!==o.type&&!o.disabled&&!i){o.focus();break}}catch(e){}return!1}}}}(window);
|
||||
window.addComment=function(p){var f,v,I,C=p.document,h={commentReplyClass:"comment-reply-link",commentReplyTitleId:"reply-title",cancelReplyId:"cancel-comment-reply-link",commentFormId:"commentform",temporaryFormId:"wp-temp-form-div",parentIdFieldId:"comment_parent",postIdFieldId:"comment_post_ID"},e=p.MutationObserver||p.WebKitMutationObserver||p.MozMutationObserver,i="querySelector"in C&&"addEventListener"in p,n=!!C.documentElement.dataset;function t(){r(),function(){if(!e)return;new e(o).observe(C.body,{childList:!0,subtree:!0})}()}function r(e){if(i&&(f=E(h.cancelReplyId),v=E(h.commentFormId),f)){f.addEventListener("touchstart",l),f.addEventListener("click",l);var t=function(e){if((e.metaKey||e.ctrlKey)&&13===e.keyCode)return v.removeEventListener("keydown",t),e.preventDefault(),v.submit.click(),!1};v&&v.addEventListener("keydown",t);for(var n,r=function(e){var t,n=h.commentReplyClass;e&&e.childNodes||(e=C);t=C.getElementsByClassName?e.getElementsByClassName(n):e.querySelectorAll("."+n);return t}(e),o=0,d=r.length;o<d;o++)(n=r[o]).addEventListener("touchstart",a),n.addEventListener("click",a)}}function l(e){var t=E(h.temporaryFormId);if(t&&I){E(h.parentIdFieldId).value="0";var n=t.textContent;t.parentNode.replaceChild(I,t),this.style.display="none";var r=E(h.commentReplyTitleId),o=r&&r.firstChild;o&&o.nodeType===Node.TEXT_NODE&&n&&(o.textContent=n),e.preventDefault()}}function a(e){var t=E(h.commentReplyTitleId),n=t&&t.firstChild.textContent,r=this,o=m(r,"belowelement"),d=m(r,"commentid"),i=m(r,"respondelement"),l=m(r,"postid"),a=m(r,"replyto")||n;o&&d&&i&&l&&!1===p.addComment.moveForm(o,d,i,l,a)&&e.preventDefault()}function o(e){for(var t=e.length;t--;)if(e[t].addedNodes.length)return void r()}function m(e,t){return n?e.dataset[t]:e.getAttribute("data-"+t)}function E(e){return C.getElementById(e)}return i&&"loading"!==C.readyState?t():i&&p.addEventListener("DOMContentLoaded",t,!1),{init:r,moveForm:function(e,t,n,r,o){var d=E(e);I=E(n);var i,l,a,m=E(h.parentIdFieldId),c=E(h.postIdFieldId),s=E(h.commentReplyTitleId),u=s&&s.firstChild;if(d&&I&&m){void 0===o&&(o=u&&u.textContent),function(e){var t=h.temporaryFormId,n=E(t),r=E(h.commentReplyTitleId),o=void 0!==r?r.firstChild.textContent:"";if(n)return;(n=C.createElement("div")).id=t,n.style.display="none",n.textContent=o,e.parentNode.insertBefore(n,e)}(I),r&&c&&(c.value=r),m.value=t,f.style.display="",d.parentNode.insertBefore(I,d.nextSibling),u.nodeType===Node.TEXT_NODE&&(u.textContent=o),f.onclick=function(){return!1};try{for(var y=0;y<v.elements.length;y++)if(i=v.elements[y],l=!1,"getComputedStyle"in p?a=p.getComputedStyle(i):C.documentElement.currentStyle&&(a=i.currentStyle),(i.offsetWidth<=0&&i.offsetHeight<=0||"hidden"===a.visibility)&&(l=!0),"hidden"!==i.type&&!i.disabled&&!l){i.focus();break}}catch(e){}return!1}}}}(window);
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-47502';
|
||||
$wp_version = '5.5-alpha-47506';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue