Version 1
[yaffs-website] / web / modules / contrib / devel / webprofiler / js / database.js
1 /**
2  * @file
3  * Database panel app.
4  */
5 (function ($, Drupal, drupalSettings) {
6
7     "use strict";
8
9     Drupal.behaviors.webprofiler_database = {
10         attach: function (context) {
11             $(context).find('.js--explain-trigger').once('js--explain-trigger').each(function () {
12
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');
17
18                     if (wrapper.html().length === 0) {
19
20                         var url = Drupal.url('admin/reports/profiler/database_explain/' + drupalSettings.webprofiler.token + '/' + position);
21
22                         loader.show();
23
24                         $.getJSON(url, function (data) {
25                             _.templateSettings.variable = 'rc';
26                             var template = _.template(
27                                 $("#wp-query-explain-template").html()
28                             );
29                             wrapper.html(template(data));
30                             loader.hide();
31                             delete _.templateSettings.variable;
32                         });
33                     }
34                     wrapper.toggle();
35
36                 });
37             });
38
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');
42                 });
43             });
44
45             $(context).find('.js--code-toggle--global').once('js--code-toggle--global').each(function () {
46                 $(this).on('click', function () {
47
48                     if($(this).hasClass('js--placeholder-visible')){
49                         $('.js--placeholder-query').addClass('is--hidden');
50                         $('.js--original-query').removeClass('is--hidden');
51
52                     }else{
53                         $('.js--placeholder-query').removeClass('is--hidden');
54                         $('.js--original-query').addClass('is--hidden');
55                     }
56                     $(this).toggleClass('js--placeholder-visible');
57                 });
58             });
59
60             if (typeof hljs != "undefined") {
61                 $('code.sql').each(function (i, block) {
62                     hljs.highlightBlock(block);
63                 });
64             }
65         }
66     }
67 })
68 (jQuery, Drupal, drupalSettings);