diff --git a/src/js/_enqueues/lib/comment-reply.js b/src/js/_enqueues/lib/comment-reply.js
index 71f997328e..fae92ee237 100644
a
|
b
|
window.addComment = ( function( window ) { |
22 | 22 | postIdFieldId : 'comment_post_ID' |
23 | 23 | }; |
24 | 24 | |
| 25 | // Cross browser MutationObserver. |
| 26 | var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; |
| 27 | |
25 | 28 | // Check browser cuts the mustard. |
26 | 29 | var cutsTheMustard = 'querySelector' in document && 'addEventListener' in window; |
27 | 30 | |
… |
… |
window.addComment = ( function( window ) { |
40 | 43 | // The respond element. |
41 | 44 | var respondElement; |
42 | 45 | |
| 46 | // The mutation observer. |
| 47 | var observer; |
| 48 | |
43 | 49 | // Initialise the events. |
44 | 50 | init(); |
45 | 51 | |
| 52 | // Set up a MutationObserver to check for comments loaded late. |
| 53 | observeChanges(); |
| 54 | |
46 | 55 | /** |
47 | 56 | * Add events to links classed .comment-reply-link. |
48 | 57 | * |
… |
… |
window.addComment = ( function( window ) { |
57 | 66 | * @param {HTMLElement} context The parent DOM element to search for links. |
58 | 67 | */ |
59 | 68 | function init( context ) { |
60 | | if ( true !== cutsTheMustard ) { |
| 69 | if ( ! cutsTheMustard ) { |
61 | 70 | return; |
62 | 71 | } |
63 | 72 | |
… |
… |
window.addComment = ( function( window ) { |
164 | 173 | } |
165 | 174 | } |
166 | 175 | |
| 176 | /** |
| 177 | * Creates a mutation observer to check for newly inserted comments. |
| 178 | * |
| 179 | * @since 5.1.0 |
| 180 | */ |
| 181 | function observeChanges() { |
| 182 | if ( ! MutationObserver ) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | var observerOptions = { |
| 187 | childList: true, |
| 188 | subTree: true |
| 189 | }; |
| 190 | |
| 191 | observer = new MutationObserver( handleChanges ); |
| 192 | observer.observe( document.body, observerOptions ); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Handles DOM changes, calling init() if any new nodes are added. |
| 197 | * |
| 198 | * @since 5.1.0 |
| 199 | * |
| 200 | * @param {Array} mutationRecords Array of MutationRecord objects. |
| 201 | */ |
| 202 | function handleChanges( mutationRecords ) { |
| 203 | var i = mutationRecords.length; |
| 204 | |
| 205 | while ( i-- ) { |
| 206 | // Call init() once if any record in this set adds nodes. |
| 207 | if ( mutationRecords[ i ].addedNodes.length ) { |
| 208 | init(); |
| 209 | return; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
167 | 214 | /** |
168 | 215 | * Backward compatible getter of data-* attribute. |
169 | 216 | * |