5 (function ($, Drupal, drupalSettings) {
9 Drupal.behaviors.webprofiler_database = {
10 attach: function (context) {
11 $(context).find('.js--explain-trigger').once('js--explain-trigger').each(function () {
13 $(this).on('click', function () {
14 var position = $(this).attr('data-wp-queryPosition'),
15 wrapper = $(this).parent().parent().find('.js--explain-target'),
16 loader = $(this).parent().parent().find('.js--loader');
18 if (wrapper.html().length === 0) {
20 var url = Drupal.url('admin/reports/profiler/database_explain/' + drupalSettings.webprofiler.token + '/' + position);
24 $.getJSON(url, function (data) {
25 _.templateSettings.variable = 'rc';
26 var template = _.template(
27 $("#wp-query-explain-template").html()
29 wrapper.html(template(data));
31 delete _.templateSettings.variable;
39 $(context).find('.js--code-toggle').once('js--code-toggle').each(function () {
40 $(this).on('click', function () {
41 $(this).parent().find('.js--code-target').find('code').toggleClass('is--hidden');
45 $(context).find('.js--code-toggle--global').once('js--code-toggle--global').each(function () {
46 $(this).on('click', function () {
48 if($(this).hasClass('js--placeholder-visible')){
49 $('.js--placeholder-query').addClass('is--hidden');
50 $('.js--original-query').removeClass('is--hidden');
53 $('.js--placeholder-query').removeClass('is--hidden');
54 $('.js--original-query').addClass('is--hidden');
56 $(this).toggleClass('js--placeholder-visible');
60 if (typeof hljs != "undefined") {
61 $('code.sql').each(function (i, block) {
62 hljs.highlightBlock(block);
68 (jQuery, Drupal, drupalSettings);