Extension_NewRelic_Widget_View.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. jQuery(document).ready(function($) {
  2. function w3tcnr_load_basic() {
  3. $('.w3tcnr_loading').removeClass('w3tc_hidden');
  4. $('.w3tcnr_content').addClass('w3tc_hidden');
  5. $('.w3tcnr_error').addClass('w3tc_none');
  6. $.getJSON(ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  7. '&w3tc_action=newrelic_widgetdata_basic',
  8. function(data) {
  9. for (p in data) {
  10. var v = data[p];
  11. jQuery('.w3tcnr_' + p).html(v);
  12. }
  13. $('.w3tcnr_content').removeClass('w3tc_hidden');
  14. $('.w3tcnr_loading').addClass('w3tc_hidden');
  15. }
  16. ).fail(function() {
  17. $('.w3tcnr_error').removeClass('w3tc_none');
  18. $('.w3tcnr_content').addClass('w3tc_hidden');
  19. $('.w3tcnr_loading').addClass('w3tc_hidden');
  20. });
  21. }
  22. function w3tcnr_load_topfive(action, selector) {
  23. $.getJSON(ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  24. '&w3tc_action=' + action,
  25. function(data) {
  26. $(selector).html(data.content);
  27. // resize outer window to newly grown widget
  28. jQuery('#normal-sortables').masonry({
  29. itemSelector: '.postbox'
  30. });
  31. }
  32. ).fail(function() {
  33. $(selector).html('<div class="w3tcnr_topfive_message">Request failed</div>');
  34. });
  35. }
  36. var nr_widget = jQuery('#new-relic-widget');
  37. nr_widget.find('div.top-five').hide();
  38. $('.w3tcnr-header-pageloads').click(function() {
  39. jQuery(this).find('div').toggleClass('close');
  40. jQuery(this).parents('.wrapper').find("div.top-five").toggle();
  41. w3tcnr_load_topfive('newrelic_widgetdata_pageloads',
  42. '.w3tcnr_pageloads');
  43. });
  44. $('.w3tcnr-header-webtransactions').click(function() {
  45. jQuery(this).find('div').toggleClass('close');
  46. jQuery(this).parents('.wrapper').find("div.top-five").toggle();
  47. w3tcnr_load_topfive('newrelic_widgetdata_webtransactions',
  48. '.w3tcnr_webtransactions');
  49. });
  50. $('.w3tcnr-header-dbtimes').click(function() {
  51. jQuery(this).find('div').toggleClass('close');
  52. jQuery(this).parents('.wrapper').find("div.top-five").toggle();
  53. w3tcnr_load_topfive('newrelic_widgetdata_dbtimes',
  54. '.w3tcnr_dbtimes');
  55. });
  56. w3tcnr_load_basic();
  57. });