database.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @file
  3. * Database panel app.
  4. */
  5. (function ($, Drupal, drupalSettings) {
  6. "use strict";
  7. Drupal.behaviors.webprofiler_database = {
  8. attach: function (context) {
  9. $(context).find('.js--explain-trigger').once('js--explain-trigger').each(function () {
  10. $(this).on('click', function () {
  11. var position = $(this).attr('data-wp-queryPosition'),
  12. wrapper = $(this).parent().parent().find('.js--explain-target'),
  13. loader = $(this).parent().parent().find('.js--loader');
  14. if (wrapper.html().length === 0) {
  15. var url = Drupal.url('admin/reports/profiler/database_explain/' + drupalSettings.webprofiler.token + '/' + position);
  16. loader.show();
  17. $.getJSON(url, function (data) {
  18. _.templateSettings.variable = 'rc';
  19. var template = _.template(
  20. $("#wp-query-explain-template").html()
  21. );
  22. wrapper.html(template(data));
  23. loader.hide();
  24. delete _.templateSettings.variable;
  25. });
  26. }
  27. wrapper.toggle();
  28. });
  29. });
  30. $(context).find('.js--code-toggle').once('js--code-toggle').each(function () {
  31. $(this).on('click', function () {
  32. $(this).parent().find('.js--code-target').find('code').toggleClass('is--hidden');
  33. });
  34. });
  35. $(context).find('.js--code-toggle--global').once('js--code-toggle--global').each(function () {
  36. $(this).on('click', function () {
  37. if($(this).hasClass('js--placeholder-visible')){
  38. $('.js--placeholder-query').addClass('is--hidden');
  39. $('.js--original-query').removeClass('is--hidden');
  40. }else{
  41. $('.js--placeholder-query').removeClass('is--hidden');
  42. $('.js--original-query').addClass('is--hidden');
  43. }
  44. $(this).toggleClass('js--placeholder-visible');
  45. });
  46. });
  47. if (typeof hljs != "undefined") {
  48. $('code.sql').each(function (i, block) {
  49. hljs.highlightBlock(block);
  50. });
  51. }
  52. }
  53. }
  54. })
  55. (jQuery, Drupal, drupalSettings);