1/** 2 * Show all jQuery Migrate warnings in the UI. 3 */ 4jQuery( document ).ready( function( $ ) { 5 var notice = $( '.notice.jquery-migrate-deprecation-notice' ); 6 var warnings = jQuery.migrateWarnings || []; 7 var adminbar = $( '#wp-admin-bar-enable-jquery-migrate-helper' ); 8 var countWrapper = $( '.count-wrapper', adminbar ); 9 10 var previousDeprecations = []; 11 12 /** 13 * Filter the trace, return the first URI that is to a plugin or theme script. 14 */ 15 function getSlugFromTrace( trace ) { 16 var traceLines = trace.split( '\n' ), 17 match = null; 18 19 // Loop over each line in the stack trace 20 traceLines.forEach( function( line ) { 21 if ( ! line ) { 22 return; 23 } 24 25 // Remove cache-busting. 26 line = line.split( '?' )[0]; 27 28 // The first few lines are going to be references to the jquery-migrate script. 29 // The first instance that is not one of them is probably a valid plugin or theme. 30 if ( 31 ! match && 32 line.indexOf( '/' + JQMH.plugin_slug + '/js' ) === -1 && 33 ( line.indexOf( '/plugins/' ) > -1 || line.indexOf( '/themes/' ) > -1 || line.indexOf( '/wp-admin/js/' ) > -1 || line.indexOf( '/wp-includes/js/' ) > -1 ) 34 ) { 35 match = line.replace( /.*?http/, 'http' ); 36 } 37 38 // If no match is found, we do a second pass, and attempt to extrapolate special 39 // cases where the script may be within anonymous functions, and thus has no asset relationship. 40 if ( 41 ! match && 42 line.indexOf( '/' + JQMH.plugin_slug + '/js' ) === -1 && 43 line.indexOf( 'anonymous' ) > -1 44 ) { 45 match = line.replace( /.*?http/, 'http' ); 46 } 47 } ); 48 49 // If the stack trace did not contain a matching plugin or theme, just return a null value. 50 return match; 51 } 52 53 /** 54 * Update the count of deprecations found on this page. 55 * 56 * @param count 57 */ 58 function setAdminBarCount( count ) { 59 if ( ! adminbar.length ) { 60 return; 61 } 62 63 // The live counter may be disabled if jQuery 3 is used during WordPress 5.6 64 if ( ! JQMH.capture_deprecations ) { 65 return; 66 } 67 68 if ( ! countWrapper.is( ':visible' ) ) { 69 countWrapper.show(); 70 71 countWrapperVisibility(); 72 } 73 74 $( '.count', adminbar ).text( count ); 75 } 76 77 /** 78 * Set the admin bar visibility level based on the warning counters. 79 */ 80 function countWrapperVisibility() { 81 if ( countWrapper.is( ':visible' ) ) { 82 adminbar 83 .css( 'background-color', '#be4400' ) 84 .css( 'color', '#eeeeee' ); 85 } else { 86 adminbar 87 .css( 'background-color', '' ) 88 .css( 'color', '' ); 89 } 90 } 91 92 /** 93 * Append the deprecation to the admin dashbaord, if applicable. 94 * 95 * @param message 96 */ 97 function appendNoticeDisplay( message ) { 98 var list = notice.find( '.jquery-migrate-deprecation-list' ); 99 100 if ( ! notice.length ) { 101 return; 102 } 103 104 // Only list one case of the same error per file. 105 if ( JQMH.single_instance_log ) { 106 if ( previousDeprecations.indexOf( message ) > -1 ) { 107 return; 108 } 109 110 previousDeprecations.push( message ); 111 } 112 113 if ( ! notice.is( ':visible' ) ) { 114 notice.show(); 115 } 116 117 list.append( $( '<li></li>' ).text( message ) ); 118 } 119 120 /** 121 * Try to log the deprecation for the admin area. 122 * 123 * @param message 124 */ 125 function reportDeprecation( message ) { 126 // Do not write to the logfile if this is the backend and the notices are written to the screen. 127 if ( JQMH.backend && notice.length ) { 128 return; 129 } 130 131 if ( ! JQMH.capture_deprecations ) { 132 return; 133 } 134 135 var data = { 136 action: 'jquery-migrate-log-notice', 137 notice: message, 138 nonce: JQMH.report_nonce, 139 backend: JQMH.backend, 140 url: window.location.href, 141 }; 142 143 $.post( { 144 url: JQMH.ajaxurl, 145 data: data 146 } ); 147 } 148 149 if ( warnings.length ) {
150 warnings.forEach( function( entry ) { 151 const trace = getSlugFromTrace( entry.trace ? entry.trace : "" ); 152 let message = trace ? trace + ': ' : ''; 153 154 // Traces some times get a null value, skip these. 155 if ( '' === message ) { 156 return; 157 } 158 159 message += entry.warning; 160 161 appendNoticeDisplay( message ); 162 163 reportDeprecation( message ); 164 } ); 165 166 setAdminBarCount( warnings.length ); 167 } 168 169 // Add handler for dismissing of the dashboard notice. 170 $( document ).on( 'click', '.jquery-migrate-dashboard-notice .notice-dismiss', function() { 171 var $notice = $( this ).closest( '.notice' ); 172 var notice_id = $notice.data( 'notice-id' ); 173 174 $.post( { 175 url: window.ajaxurl, 176 data: { 177 action: 'jquery-migrate-dismiss-notice', 178 'notice': notice_id, 179 'dismiss-notice-nonce': $( '#' + notice_id + '-nonce' ).val(), 180 }, 181 } ); 182 } ); 183 184 // When the previous deprecations are dismissed, reset the admin bar log display. 185 $( document ).on( 'click', '.jquery-migrate-previous-deprecations .notice-dismiss', function() { 186 countWrapper.hide(); 187 countWrapperVisibility(); 188 } ); 189 190 // Check if the counter is visible on page load. 191 countWrapperVisibility(); 192} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.