debug-bar.dev.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. var wpDebugBar;
  2. (function($) {
  3. var api;
  4. wpDebugBar = api = {
  5. // The element that we will pad to prevent the debug bar
  6. // from overlapping the bottom of the page.
  7. body: undefined,
  8. init: function() {
  9. // If we're not in the admin, pad the body.
  10. api.body = $(document.body);
  11. api.toggle.init();
  12. api.tabs();
  13. api.actions.init();
  14. },
  15. isVisible: function() {
  16. return api.body.hasClass( 'debug-bar-visible' );
  17. },
  18. toggle: {
  19. init: function() {
  20. $('#wp-admin-bar-debug-bar').click( function(e) {
  21. e.preventDefault();
  22. api.toggle.visibility();
  23. });
  24. },
  25. visibility: function( show ) {
  26. show = typeof show == 'undefined' ? ! api.isVisible() : show;
  27. // Show/hide the debug bar.
  28. api.body.toggleClass( 'debug-bar-visible', show );
  29. // Press/unpress the button.
  30. $(this).toggleClass( 'active', show );
  31. }
  32. },
  33. tabs: function() {
  34. var debugMenuLinks = $('.debug-menu-link'),
  35. debugMenuTargets = $('.debug-menu-target');
  36. debugMenuLinks.click( function(e) {
  37. var t = $(this);
  38. e.preventDefault();
  39. if ( t.hasClass('current') )
  40. return;
  41. // Deselect other tabs and hide other panels.
  42. debugMenuTargets.hide().trigger('debug-bar-hide');
  43. debugMenuLinks.removeClass('current');
  44. // Select the current tab and show the current panel.
  45. t.addClass('current');
  46. // The hashed component of the href is the id that we want to display.
  47. $('#' + this.href.substr( this.href.indexOf( '#' ) + 1 ) ).show().trigger('debug-bar-show');
  48. });
  49. },
  50. actions: {
  51. init: function() {
  52. var actions = $('#debug-bar-actions');
  53. // Close the panel with the esc key if it's open
  54. // 27 = esc
  55. $(document).keydown( function( e ) {
  56. var key = e.key || e.which || e.keyCode;
  57. if ( 27 != key || ! api.isVisible() )
  58. return;
  59. e.preventDefault();
  60. return api.actions.close();
  61. });
  62. $('.maximize', actions).click( api.actions.maximize );
  63. $('.restore', actions).click( api.actions.restore );
  64. $('.close', actions).click( api.actions.close );
  65. },
  66. maximize: function() {
  67. api.body.removeClass('debug-bar-partial');
  68. api.body.addClass('debug-bar-maximized');
  69. },
  70. restore: function() {
  71. api.body.removeClass('debug-bar-maximized');
  72. api.body.addClass('debug-bar-partial');
  73. },
  74. close: function() {
  75. api.toggle.visibility( false );
  76. console.log( 'boo');
  77. }
  78. }
  79. };
  80. wpDebugBar.Panel = function() {
  81. };
  82. $(document).ready( wpDebugBar.init );
  83. })(jQuery);