Changeset 44751
- Timestamp:
- 02/19/2019 02:00:21 AM (6 years ago)
- Location:
- branches/5.1
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.1
-
branches/5.1/src/js/_enqueues/lib/comment-reply.js
r44388 r44751 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; … … 41 44 var respondElement; 42 45 46 // The mutation observer. 47 var observer; 48 43 49 // Initialise the events. 44 50 init(); 51 52 // Set up a MutationObserver to check for comments loaded late. 53 observeChanges(); 45 54 46 55 /** … … 58 67 */ 59 68 function init( context ) { 60 if ( true !==cutsTheMustard ) {69 if ( ! cutsTheMustard ) { 61 70 return; 62 71 } … … 162 171 if ( false === follow ) { 163 172 event.preventDefault(); 173 } 174 } 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 } 164 211 } 165 212 }
Note: See TracChangeset
for help on using the changeset viewer.