debug-bar-js.dev.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function() {
  2. var count, list, dbjsError,
  3. rawCount = 0,
  4. errors = [];
  5. window.onerror = function( errorMsg, url, lineNumber ) {
  6. if ( ! document.getElementById( 'debug-bar-js-error-count' ) )
  7. errors[ errors.length ] = [errorMsg, url, lineNumber];
  8. else
  9. dbjsError(errorMsg, url, lineNumber);
  10. }
  11. jQuery(document).ready( function(){
  12. for ( err in errors )
  13. dbjsError( errors[err][0], errors[err][1], errors[err][2] );
  14. });
  15. dbjsError = function( errorMsg, url, lineNumber ) {
  16. var errorLine, place, button, tab;
  17. rawCount++;
  18. if ( !count )
  19. count = document.getElementById( 'debug-bar-js-error-count' );
  20. if ( !list )
  21. list = document.getElementById( 'debug-bar-js-errors' );
  22. if ( !count || !list )
  23. return; // threw way too early... @todo cache these?
  24. if ( 1 == rawCount ) {
  25. button = document.getElementById( 'wp-admin-bar-debug-bar' );
  26. if ( !button )
  27. return; // how did this happen?
  28. if ( button.className.indexOf( 'debug-bar-php-warning-summary' ) === -1 )
  29. button.className = button.className + ' debug-bar-php-warning-summary';
  30. tab = document.getElementById('debug-menu-link-Debug_Bar_JS');
  31. if ( tab )
  32. tab.style.display = 'block';
  33. }
  34. count.textContent = rawCount;
  35. errorLine = document.createElement( 'li' );
  36. errorLine.className = 'debug-bar-js-error';
  37. errorLine.textContent = errorMsg;
  38. place = document.createElement( 'span' );
  39. place.textContent = url + ' line ' + lineNumber;
  40. errorLine.appendChild( place );
  41. list.appendChild( errorLine );
  42. };
  43. })();