debug-bar-js.dev.js 1.2 KB

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