diff --git a/src/js/_enqueues/lib/comment-reply.js b/src/js/_enqueues/lib/comment-reply.js
index 71f997328e..01eac4cdbd 100644
|
a
|
b
|
window.addComment = ( function( window ) { |
| 40 | 40 | // The respond element. |
| 41 | 41 | var respondElement; |
| 42 | 42 | |
| | 43 | // The mutation observer. |
| | 44 | var observer; |
| | 45 | |
| 43 | 46 | // Initialise the events. |
| 44 | 47 | init(); |
| 45 | 48 | |
| | 49 | // Set up a MutationObserver to check for comments loaded late. |
| | 50 | observeChanges(); |
| | 51 | |
| 46 | 52 | /** |
| 47 | 53 | * Add events to links classed .comment-reply-link. |
| 48 | 54 | * |
| … |
… |
window.addComment = ( function( window ) { |
| 164 | 170 | } |
| 165 | 171 | } |
| 166 | 172 | |
| | 173 | /** |
| | 174 | * Creates a mutation observer to check for newly inserted comments. |
| | 175 | */ |
| | 176 | function observeChanges() { |
| | 177 | var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; |
| | 178 | var observerOptions = { |
| | 179 | childList: true, |
| | 180 | subTree: true, |
| | 181 | }; |
| | 182 | |
| | 183 | if ( ! MutationObserver ) { |
| | 184 | return; |
| | 185 | } |
| | 186 | |
| | 187 | observer = new MutationObserver( handleChanges ); |
| | 188 | observer.observe( document.body, observerOptions ); |
| | 189 | } |
| | 190 | |
| | 191 | /** |
| | 192 | * Handles DOM changes, calling init() if any new nodes are added. |
| | 193 | * |
| | 194 | * @since 5.1.0 |
| | 195 | * |
| | 196 | * @param {Array} mutationRecords Array of MutationRecord objects. |
| | 197 | */ |
| | 198 | function handleChanges( mutationRecords ) { |
| | 199 | var i = mutationRecords.length; |
| | 200 | |
| | 201 | while ( i-- ) { |
| | 202 | // Call init() once if any record in this set adds nodes. |
| | 203 | if ( mutationRecords[ i ].addedNodes.length ) { |
| | 204 | init(); |
| | 205 | return; |
| | 206 | } |
| | 207 | } |
| | 208 | } |
| | 209 | |
| 167 | 210 | /** |
| 168 | 211 | * Backward compatible getter of data-* attribute. |
| 169 | 212 | * |