1/** 2 * Show all jQuery Migrate warnings in the UI. 3 */ 4jQuery( document ).ready( function( $ ) { 5 const notice = $( '.notice.jquery-migrate-deprecation-notice' ); 6 const warnings = jQuery.migrateWarnings || []; 7 const adminbar = $( '#wp-admin-bar-enable-jquery-migrate-helper' ); 8 const 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 let 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 ) 34 ) { 35 match = line.replace( /.*?http/, 'http' ); 36 } 37 } ); 38 39 // If the stack trace did not contain a matching plugin or theme, just return a null value. 40 return match; 41 } 42 43 /** 44 * Update the count of deprecations found on this page. 45 * 46 * @param count 47 */ 48 function setAdminBarCount( count ) { 49 if ( ! adminbar.length ) { 50 return; 51 } 52 53 // The live counter may be disabled if jQuery 3 is used during WordPress 5.6 54 if ( ! JQMH.capture_deprecations ) { 55 return; 56 } 57 58 if ( ! countWrapper.is( ':visible' ) ) { 59 countWrapper.show(); 60 61 countWrapperVisibility(); 62 } 63 64 $( '.count', adminbar ).text( count ); 65 } 66 67 /** 68 * Set the admin bar visibility level based on the warning counters. 69 */ 70 function countWrapperVisibility() { 71 if ( countWrapper.is( ':visible' ) ) { 72 adminbar 73 .css( 'background-color', '#be4400' ) 74 .css( 'color', '#eeeeee' ); 75 } else { 76 adminbar 77 .css( 'background-color', '' ) 78 .css( 'color', '' ); 79 } 80 } 81 82 /** 83 * Append the deprecation to the admin dashbaord, if applicable. 84 * 85 * @param message 86 */ 87 function appendNoticeDisplay( message ) { 88 const list = notice.find( '.jquery-migrate-deprecation-list' ); 89 90 if ( ! notice.length ) { 91 return; 92 } 93 94 // Only list one case of the same error per file. 95 if ( JQMH.single_instance_log ) { 96 if ( previousDeprecations.indexOf( message ) > -1 ) { 97 return; 98 } 99 100 previousDeprecations.push( message ); 101 } 102 103 if ( ! notice.is( ':visible' ) ) { 104 notice.show(); 105 } 106 107 list.append( $( '<li></li>' ).text( message ) ); 108 } 109 110 /** 111 * Try to log the deprecation for the admin area. 112 * 113 * @param message 114 */ 115 function reportDeprecation( message ) { 116 // Do not write to the logfile if this is the backend and the notices are written to the screen. 117 if ( JQMH.backend && notice.length ) { 118 return; 119 } 120 121 if ( ! JQMH.capture_deprecations ) { 122 return; 123 } 124 125 let data = { 126 action: 'jquery-migrate-log-notice', 127 notice: message, 128 nonce: JQMH.report_nonce, 129 backend: JQMH.backend, 130 url: window.location.href, 131 }; 132 133 $.post( { 134 url: JQMH.ajaxurl, 135 data 136 } ); 137 } 138 139 if ( warnings.length ) {
140 warnings.forEach( function( entry ) { 141 const trace = getSlugFromTrace( entry.trace ? entry.trace : "" ); 142 let message = trace ? trace + ': ' : ''; 143 144 // Traces some times get a null value, skip these. 145 if ( '' === message ) { 146 return; 147 } 148 149 message += entry.warning; 150 151 appendNoticeDisplay( message ); 152 153 reportDeprecation( message ); 154 } ); 155 156 setAdminBarCount( warnings.length ); 157 } 158 159 // Add handler for dismissing of the dashboard notice. 160 $( document ).on( 'click', '.jquery-migrate-dashboard-notice .notice-dismiss', function() { 161 const $notice = $( this ).closest( '.notice' ); 162 const notice_id = $notice.data( 'notice-id' ); 163 164 $.post( { 165 url: window.ajaxurl, 166 data: { 167 action: 'jquery-migrate-dismiss-notice', 168 'notice': notice_id, 169 'dismiss-notice-nonce': $( '#' + notice_id + '-nonce' ).val(), 170 }, 171 } ); 172 } ); 173 174 // When the previous deprecations are dismissed, reset the admin bar log display. 175 $( document ).on( 'click', '.jquery-migrate-previous-deprecations .notice-dismiss', function() { 176 countWrapper.hide(); 177 countWrapperVisibility(); 178 } ); 179 180 // Check if the counter is visible on page load. 181 countWrapperVisibility(); 182} );
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.