diff --git a/src/js/_enqueues/lib/comment-reply.js b/src/js/_enqueues/lib/comment-reply.js
index 71f997328e..fb38dfe9cb 100644
|
a
|
b
|
window.addComment = ( function( window ) { |
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | | // Get required elements. |
| 65 | | cancelElement = getElementById( config.cancelReplyId ); |
| 66 | | commentFormElement = getElementById( config.commentFormId ); |
| 67 | | |
| 68 | | // No cancel element, no replies. |
| 69 | | if ( ! cancelElement ) { |
| 70 | | return; |
| 71 | | } |
| 72 | | |
| 73 | | cancelElement.addEventListener( 'touchstart', cancelEvent ); |
| 74 | | cancelElement.addEventListener( 'click', cancelEvent ); |
| 75 | | |
| 76 | | var links = replyLinks( context ); |
| 77 | | var element; |
| 78 | | |
| 79 | | for ( var i = 0, l = links.length; i < l; i++ ) { |
| 80 | | element = links[i]; |
| 81 | | |
| 82 | | element.addEventListener( 'touchstart', clickEvent ); |
| 83 | | element.addEventListener( 'click', clickEvent ); |
| 84 | | } |
| 85 | | } |
| 86 | | |
| 87 | | /** |
| 88 | | * Return all links classed .comment-reply-link. |
| 89 | | * |
| 90 | | * @since 5.1.0 |
| 91 | | * |
| 92 | | * @param {HTMLElement} context The parent DOM element to search for links. |
| 93 | | * |
| 94 | | * @return {HTMLCollection|NodeList|Array} |
| 95 | | */ |
| 96 | | function replyLinks( context ) { |
| 97 | | var selectorClass = config.commentReplyClass; |
| 98 | | var allReplyLinks; |
| 99 | | |
| 100 | 64 | // childNodes is a handy check to ensure the context is a HTMLElement. |
| 101 | 65 | if ( ! context || ! context.childNodes ) { |
| 102 | 66 | context = document; |
| 103 | 67 | } |
| 104 | 68 | |
| 105 | | if ( document.getElementsByClassName ) { |
| 106 | | // Fastest. |
| 107 | | allReplyLinks = context.getElementsByClassName( selectorClass ); |
| 108 | | } |
| 109 | | else { |
| 110 | | // Fast. |
| 111 | | allReplyLinks = context.querySelectorAll( '.' + selectorClass ); |
| 112 | | } |
| | 69 | document.addEventListener( 'touchstart', cancelEvent ); |
| | 70 | document.addEventListener( 'click', cancelEvent ); |
| 113 | 71 | |
| 114 | | return allReplyLinks; |
| | 72 | context.addEventListener( 'touchstart', clickEvent ); |
| | 73 | context.addEventListener( 'click', clickEvent ); |
| 115 | 74 | } |
| 116 | 75 | |
| 117 | 76 | /** |
| … |
… |
window.addComment = ( function( window ) { |
| 122 | 81 | * @param {Event} event The calling event. |
| 123 | 82 | */ |
| 124 | 83 | function cancelEvent( event ) { |
| 125 | | var cancelLink = this; |
| | 84 | if ( ! matches( event.target, '#' + config.cancelReplyId ) ) { |
| | 85 | return; |
| | 86 | } |
| | 87 | |
| | 88 | var cancelLink = event.target; |
| 126 | 89 | var temporaryFormId = config.temporaryFormId; |
| 127 | 90 | var temporaryElement = getElementById( temporaryFormId ); |
| 128 | 91 | |
| … |
… |
window.addComment = ( function( window ) { |
| 147 | 110 | * @param {Event} event The calling event. |
| 148 | 111 | */ |
| 149 | 112 | function clickEvent( event ) { |
| 150 | | var replyLink = this, |
| | 113 | if ( ! matches( event.target, '.' + config.commentReplyClass ) ) { |
| | 114 | return; |
| | 115 | } |
| | 116 | |
| | 117 | var replyLink = event.target, |
| 151 | 118 | commId = getDataAttribute( replyLink, 'belowelement'), |
| 152 | 119 | parentId = getDataAttribute( replyLink, 'commentid' ), |
| 153 | 120 | respondId = getDataAttribute( replyLink, 'respondelement'), |
| … |
… |
window.addComment = ( function( window ) { |
| 198 | 165 | return document.getElementById( elementId ); |
| 199 | 166 | } |
| 200 | 167 | |
| | 168 | /** |
| | 169 | * Checks if the element matches the selector. |
| | 170 | * |
| | 171 | * Local alias/polyfill for Element.prototype.matches. |
| | 172 | * |
| | 173 | * @since 5.1.0 |
| | 174 | * |
| | 175 | * @param {HTMLElement} element The element to be checked. |
| | 176 | * @param {String} selector The selector to match. |
| | 177 | * |
| | 178 | * @return {Boolean} Whether or not the element matched the selector. |
| | 179 | */ |
| | 180 | function matches( element, selector ) { |
| | 181 | if ( ! element ) { |
| | 182 | return false; |
| | 183 | } |
| | 184 | |
| | 185 | var matches = element.matches || |
| | 186 | element.matchesSelector || |
| | 187 | element.mozMatchesSelector || |
| | 188 | element.msMatchesSelector || |
| | 189 | element.oMatchesSelector || |
| | 190 | element.webkitMatchesSelector; |
| | 191 | |
| | 192 | if ( matches ) { |
| | 193 | return matches.call( element, selector ); |
| | 194 | } |
| | 195 | |
| | 196 | return false; |
| | 197 | } |
| | 198 | |
| 201 | 199 | /** |
| 202 | 200 | * Moves the reply form from its current position to the reply location. |
| 203 | 201 | * |
| … |
… |
window.addComment = ( function( window ) { |
| 213 | 211 | function moveForm( addBelowId, commentId, respondId, postId ) { |
| 214 | 212 | // Get elements based on their IDs. |
| 215 | 213 | var addBelowElement = getElementById( addBelowId ); |
| 216 | | respondElement = getElementById( respondId ); |
| 217 | 214 | |
| 218 | 215 | // Get the hidden fields. |
| 219 | 216 | var parentIdField = getElementById( config.parentIdFieldId ); |
| 220 | 217 | var postIdField = getElementById( config.postIdFieldId ); |
| 221 | 218 | var element, cssHidden, style; |
| 222 | 219 | |
| 223 | | if ( ! addBelowElement || ! respondElement || ! parentIdField ) { |
| | 220 | respondElement = getElementById( respondId ); |
| | 221 | cancelElement = getElementById( config.cancelReplyId ); |
| | 222 | commentFormElement = getElementById( config.commentFormId ); |
| | 223 | |
| | 224 | if ( ! addBelowElement || ! respondElement || ! parentIdField || ! cancelElement || ! commentFormElement ) { |
| 224 | 225 | // Missing key elements, fail. |
| 225 | 226 | return; |
| 226 | 227 | } |