debug-bar.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. jQuery(function($) {
  2. function runAjaxAction(button, action) {
  3. button = $(button);
  4. var panel = button.closest('.puc-debug-bar-panel-v5');
  5. var responseBox = button.closest('td').find('.puc-ajax-response');
  6. responseBox.text('Processing...').show();
  7. $.post(
  8. ajaxurl,
  9. {
  10. action : action,
  11. uid : panel.data('uid'),
  12. _wpnonce: panel.data('nonce')
  13. },
  14. function(data) {
  15. responseBox.html(data);
  16. },
  17. 'html'
  18. );
  19. }
  20. $('.puc-debug-bar-panel-v5 input[name="puc-check-now-button"]').on('click', function() {
  21. runAjaxAction(this, 'puc_v5_debug_check_now');
  22. return false;
  23. });
  24. $('.puc-debug-bar-panel-v5 input[name="puc-request-info-button"]').on('click', function() {
  25. runAjaxAction(this, 'puc_v5_debug_request_info');
  26. return false;
  27. });
  28. // Debug Bar uses the panel class name as part of its link and container IDs. This means we can
  29. // end up with multiple identical IDs if more than one plugin uses the update checker library.
  30. // Fix it by replacing the class name with the plugin slug.
  31. var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v5');
  32. panels.each(function() {
  33. var panel = $(this);
  34. var uid = panel.data('uid');
  35. var target = panel.closest('.debug-menu-target');
  36. //Change the panel wrapper ID.
  37. target.attr('id', 'debug-menu-target-puc-' + uid);
  38. //Change the menu link ID as well and point it at the new target ID.
  39. $('#debug-bar-menu').find('.puc-debug-menu-link-' + uid)
  40. .closest('.debug-menu-link')
  41. .attr('id', 'debug-menu-link-puc-' + uid)
  42. .attr('href', '#' + target.attr('id'));
  43. });
  44. });