vendor/symfony/web-profiler-bundle/Resources/views/Profiler/base_js.html.twig line 1

Open in your IDE?
  1. {# This file is partially duplicated in src/Symfony/Component/ErrorHandler/Resources/assets/js/exception.js.
  2.    If you make any change in this file, verify the same change is needed in the other file. #}
  3. <script{% if csp_script_nonce is defined and csp_script_nonce %} nonce="{{ csp_script_nonce }}"{% endif %}>/*<![CDATA[*/
  4.     {# Caution: the contents of this file are processed by Twig before loading
  5.                 them as JavaScript source code. Always use '/*' comments instead
  6.                 of '//' comments to avoid impossible-to-debug side-effects #}
  7. if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
  8.     Sfjs = (function() {
  9.         "use strict";
  10.         if ('classList' in document.documentElement) {
  11.             var hasClass = function (el, cssClass) { return el.classList.contains(cssClass); };
  12.             var removeClass = function(el, cssClass) { el.classList.remove(cssClass); };
  13.             var addClass = function(el, cssClass) { el.classList.add(cssClass); };
  14.             var toggleClass = function(el, cssClass) { el.classList.toggle(cssClass); };
  15.         } else {
  16.             var hasClass = function (el, cssClass) { return el.className.match(new RegExp('\\b' + cssClass + '\\b')); };
  17.             var removeClass = function(el, cssClass) { el.className = el.className.replace(new RegExp('\\b' + cssClass + '\\b'), ' '); };
  18.             var addClass = function(el, cssClass) { if (!hasClass(el, cssClass)) { el.className += " " + cssClass; } };
  19.             var toggleClass = function(el, cssClass) { hasClass(el, cssClass) ? removeClass(el, cssClass) : addClass(el, cssClass); };
  20.         }
  21.         var noop = function() {};
  22.         var profilerStorageKey = 'symfony/profiler/';
  23.         var addEventListener;
  24.         var el = document.createElement('div');
  25.         if (!('addEventListener' in el)) {
  26.             addEventListener = function (element, eventName, callback) {
  27.                 element.attachEvent('on' + eventName, callback);
  28.             };
  29.         } else {
  30.             addEventListener = function (element, eventName, callback) {
  31.                 element.addEventListener(eventName, callback, false);
  32.             };
  33.         }
  34.         if (navigator.clipboard) {
  35.             document.addEventListener('readystatechange', () => {
  36.                 if (document.readyState !== 'complete') {
  37.                     return;
  38.                 }
  39.                 document.querySelectorAll('[data-clipboard-text]').forEach(function (element) {
  40.                     removeClass(element, 'hidden');
  41.                     element.addEventListener('click', function () {
  42.                         navigator.clipboard.writeText(element.getAttribute('data-clipboard-text'));
  43.                         if (element.classList.contains("label")) {
  44.                             let oldContent = element.textContent;
  45.                             element.textContent = "✅ Copied!";
  46.                             element.classList.add("status-success");
  47.                             setTimeout(() => {
  48.                                 element.textContent = oldContent;
  49.                                 element.classList.remove("status-success");
  50.                             }, 7000);
  51.                         }
  52.                     });
  53.                 });
  54.             });
  55.         }
  56.         var request = function(url, onSuccess, onError, payload, options, tries) {
  57.             var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  58.             options = options || {};
  59.             options.retry = options.retry || false;
  60.             tries = tries || 1;
  61.             /* this delays for 125, 375, 625, 875, and 1000, ... */
  62.             var delay = tries < 5 ? (tries - 0.5) * 250 : 1000;
  63.             xhr.open(options.method || 'GET', url, true);
  64.             xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  65.             xhr.onreadystatechange = function(state) {
  66.                 if (4 !== xhr.readyState) {
  67.                     return null;
  68.                 }
  69.                 if (xhr.status == 404 && options.retry && !options.stop) {
  70.                     setTimeout(function() {
  71.                         if (options.stop) {
  72.                             return;
  73.                         }
  74.                         request(url, onSuccess, onError, payload, options, tries + 1);
  75.                     }, delay);
  76.                     return null;
  77.                 }
  78.                 if (200 === xhr.status) {
  79.                     (onSuccess || noop)(xhr);
  80.                 } else {
  81.                     (onError || noop)(xhr);
  82.                 }
  83.             };
  84.             if (options.onSend) {
  85.                 options.onSend(tries);
  86.             }
  87.             xhr.send(payload || '');
  88.         };
  89.         var getPreference = function(name) {
  90.             if (!window.localStorage) {
  91.                 return null;
  92.             }
  93.             return localStorage.getItem(profilerStorageKey + name);
  94.         };
  95.         var setPreference = function(name, value) {
  96.             if (!window.localStorage) {
  97.                 return null;
  98.             }
  99.             localStorage.setItem(profilerStorageKey + name, value);
  100.         };
  101.         var requestStack = [];
  102.         var extractHeaders = function(xhr, stackElement) {
  103.             /* Here we avoid to call xhr.getResponseHeader in order to */
  104.             /* prevent polluting the console with CORS security errors */
  105.             var allHeaders = xhr.getAllResponseHeaders();
  106.             var ret;
  107.             if (ret = allHeaders.match(/^x-debug-token:\s+(.*)$/im)) {
  108.                 stackElement.profile = ret[1];
  109.             }
  110.             if (ret = allHeaders.match(/^x-debug-token-link:\s+(.*)$/im)) {
  111.                 stackElement.profilerUrl = ret[1];
  112.             }
  113.             if (ret = allHeaders.match(/^Symfony-Debug-Toolbar-Replace:\s+(.*)$/im)) {
  114.                 stackElement.toolbarReplaceFinished = false;
  115.                 stackElement.toolbarReplace = '1' === ret[1];
  116.             }
  117.         };
  118.         var successStreak = 4;
  119.         var pendingRequests = 0;
  120.         var renderAjaxRequests = function() {
  121.             var requestCounter = document.querySelector('.sf-toolbar-ajax-request-counter');
  122.             if (!requestCounter) {
  123.                 return;
  124.             }
  125.             requestCounter.textContent = requestStack.length;
  126.             var infoSpan = document.querySelector(".sf-toolbar-ajax-info");
  127.             if (infoSpan) {
  128.                 infoSpan.textContent = requestStack.length + ' AJAX request' + (requestStack.length !== 1 ? 's' : '');
  129.             }
  130.             var ajaxToolbarPanel = document.querySelector('.sf-toolbar-block-ajax');
  131.             if (requestStack.length) {
  132.                 ajaxToolbarPanel.style.display = 'block';
  133.             } else {
  134.                 ajaxToolbarPanel.style.display = 'none';
  135.             }
  136.             if (pendingRequests > 0) {
  137.                 addClass(ajaxToolbarPanel, 'sf-ajax-request-loading');
  138.             } else if (successStreak < 4) {
  139.                 addClass(ajaxToolbarPanel, 'sf-toolbar-status-red');
  140.                 removeClass(ajaxToolbarPanel, 'sf-ajax-request-loading');
  141.             } else {
  142.                 removeClass(ajaxToolbarPanel, 'sf-ajax-request-loading');
  143.                 removeClass(ajaxToolbarPanel, 'sf-toolbar-status-red');
  144.             }
  145.         };
  146.         var startAjaxRequest = function(index) {
  147.             var tbody = document.querySelector('.sf-toolbar-ajax-request-list');
  148.             if (!tbody) {
  149.                 return;
  150.             }
  151.             var nbOfAjaxRequest = tbody.rows.length;
  152.             if (nbOfAjaxRequest >= 100) {
  153.                 tbody.deleteRow(0);
  154.             }
  155.             var request = requestStack[index];
  156.             pendingRequests++;
  157.             var row = document.createElement('tr');
  158.             request.DOMNode = row;
  159.             var requestNumberCell = document.createElement('td');
  160.             requestNumberCell.textContent = index + 1;
  161.             row.appendChild(requestNumberCell);
  162.             var profilerCell = document.createElement('td');
  163.             profilerCell.textContent = 'n/a';
  164.             row.appendChild(profilerCell);
  165.             var methodCell = document.createElement('td');
  166.             methodCell.textContent = request.method;
  167.             row.appendChild(methodCell);
  168.             var typeCell = document.createElement('td');
  169.             typeCell.textContent = request.type;
  170.             row.appendChild(typeCell);
  171.             var statusCodeCell = document.createElement('td');
  172.             var statusCode = document.createElement('span');
  173.             statusCode.textContent = 'n/a';
  174.             statusCodeCell.appendChild(statusCode);
  175.             row.appendChild(statusCodeCell);
  176.             var pathCell = document.createElement('td');
  177.             pathCell.className = 'sf-ajax-request-url';
  178.             if ('GET' === request.method) {
  179.                 var pathLink = document.createElement('a');
  180.                 pathLink.setAttribute('href', request.url);
  181.                 pathLink.textContent = request.url;
  182.                 pathCell.appendChild(pathLink);
  183.             } else {
  184.                 pathCell.textContent = request.url;
  185.             }
  186.             pathCell.setAttribute('title', request.url);
  187.             row.appendChild(pathCell);
  188.             var durationCell = document.createElement('td');
  189.             durationCell.className = 'sf-ajax-request-duration';
  190.             durationCell.textContent = 'n/a';
  191.             row.appendChild(durationCell);
  192.             request.liveDurationHandle = setInterval(function() {
  193.                 durationCell.textContent = (new Date() - request.start) + ' ms';
  194.             }, 100);
  195.             row.className = 'sf-ajax-request sf-ajax-request-loading';
  196.             tbody.insertBefore(row, null);
  197.             var toolbarInfo = document.querySelector('.sf-toolbar-block-ajax .sf-toolbar-info');
  198.             toolbarInfo.scrollTop = toolbarInfo.scrollHeight;
  199.             renderAjaxRequests();
  200.         };
  201.         var finishAjaxRequest = function(index) {
  202.             var request = requestStack[index];
  203.             clearInterval(request.liveDurationHandle);
  204.             if (!request.DOMNode) {
  205.                 return;
  206.             }
  207.             if (request.toolbarReplace && !request.toolbarReplaceFinished && request.profile) {
  208.                 /* Flag as complete because finishAjaxRequest can be called multiple times. */
  209.                 request.toolbarReplaceFinished = true;
  210.                 /* Search up through the DOM to find the toolbar's container ID. */
  211.                 for (var elem = request.DOMNode; elem && elem !== document; elem = elem.parentNode) {
  212.                     if (elem.id.match(/^sfwdt/)) {
  213.                         Sfjs.loadToolbar(elem.id.replace(/^sfwdt/, ''), request.profile);
  214.                         break;
  215.                     }
  216.                 }
  217.             }
  218.             pendingRequests--;
  219.             var row = request.DOMNode;
  220.             /* Unpack the children from the row */
  221.             var profilerCell = row.children[1];
  222.             var methodCell = row.children[2];
  223.             var statusCodeCell = row.children[4];
  224.             var statusCodeElem = statusCodeCell.children[0];
  225.             var durationCell = row.children[6];
  226.             if (request.error) {
  227.                 row.className = 'sf-ajax-request sf-ajax-request-error';
  228.                 methodCell.className = 'sf-ajax-request-error';
  229.                 successStreak = 0;
  230.             } else {
  231.                 row.className = 'sf-ajax-request sf-ajax-request-ok';
  232.                 successStreak++;
  233.             }
  234.             if (request.statusCode) {
  235.                 if (request.statusCode < 300) {
  236.                     statusCodeElem.setAttribute('class', 'sf-toolbar-status');
  237.                 } else if (request.statusCode < 400) {
  238.                     statusCodeElem.setAttribute('class', 'sf-toolbar-status sf-toolbar-status-yellow');
  239.                 } else {
  240.                     statusCodeElem.setAttribute('class', 'sf-toolbar-status sf-toolbar-status-red');
  241.                 }
  242.                 statusCodeElem.textContent = request.statusCode;
  243.             } else {
  244.                 statusCodeElem.setAttribute('class', 'sf-toolbar-status sf-toolbar-status-red');
  245.             }
  246.             if (request.duration) {
  247.                 durationCell.textContent = request.duration + ' ms';
  248.             }
  249.             if (request.profilerUrl) {
  250.                 profilerCell.textContent = '';
  251.                 var profilerLink = document.createElement('a');
  252.                 profilerLink.setAttribute('href', request.profilerUrl);
  253.                 profilerLink.textContent = request.profile;
  254.                 profilerCell.appendChild(profilerLink);
  255.             }
  256.             renderAjaxRequests();
  257.         };
  258.         {% if excluded_ajax_paths is defined %}
  259.             if (window.fetch && window.fetch.polyfill === undefined) {
  260.                 var oldFetch = window.fetch;
  261.                 window.fetch = function () {
  262.                     var promise = oldFetch.apply(this, arguments);
  263.                     var url = arguments[0];
  264.                     var params = arguments[1];
  265.                     var paramType = Object.prototype.toString.call(arguments[0]);
  266.                     if (paramType === '[object Request]') {
  267.                         url = arguments[0].url;
  268.                         params = {
  269.                             method: arguments[0].method,
  270.                             credentials: arguments[0].credentials,
  271.                             headers: arguments[0].headers,
  272.                             mode: arguments[0].mode,
  273.                             redirect: arguments[0].redirect
  274.                         };
  275.                     } else {
  276.                         url = String(url);
  277.                     }
  278.                     if (!url.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
  279.                         var method = 'GET';
  280.                         if (params && params.method !== undefined) {
  281.                             method = params.method;
  282.                         }
  283.                         var stackElement = {
  284.                             error: false,
  285.                             url: url,
  286.                             method: method,
  287.                             type: 'fetch',
  288.                             start: new Date()
  289.                         };
  290.                         var idx = requestStack.push(stackElement) - 1;
  291.                         promise.then(function (r) {
  292.                             stackElement.duration = new Date() - stackElement.start;
  293.                             stackElement.error = r.status < 200 || r.status >= 400;
  294.                             stackElement.statusCode = r.status;
  295.                             stackElement.profile = r.headers.get('x-debug-token');
  296.                             stackElement.profilerUrl = r.headers.get('x-debug-token-link');
  297.                             stackElement.toolbarReplaceFinished = false;
  298.                             stackElement.toolbarReplace = '1' === r.headers.get('Symfony-Debug-Toolbar-Replace');
  299.                             finishAjaxRequest(idx);
  300.                         }, function (e){
  301.                             stackElement.error = true;
  302.                             finishAjaxRequest(idx);
  303.                         });
  304.                         startAjaxRequest(idx);
  305.                     }
  306.                     return promise;
  307.                 };
  308.             }
  309.             if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
  310.                 var proxied = XMLHttpRequest.prototype.open;
  311.                 XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
  312.                     var self = this;
  313.                     /* prevent logging AJAX calls to static and inline files, like templates */
  314.                     var path = url;
  315.                     if (url.slice(0, 1) === '/') {
  316.                         if (0 === url.indexOf('{{ request.basePath|e('js') }}')) {
  317.                             path = url.slice({{ request.basePath|length }});
  318.                         }
  319.                     }
  320.                     else if (0 === url.indexOf('{{ (request.schemeAndHttpHost ~ request.basePath)|e('js') }}')) {
  321.                         path = url.slice({{ (request.schemeAndHttpHost ~ request.basePath)|length }});
  322.                     }
  323.                     if (!path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
  324.                         var stackElement = {
  325.                             error: false,
  326.                             url: url,
  327.                             method: method,
  328.                             type: 'xhr',
  329.                             start: new Date()
  330.                         };
  331.                         var idx = requestStack.push(stackElement) - 1;
  332.                         this.addEventListener('readystatechange', function() {
  333.                             if (self.readyState == 4) {
  334.                                 stackElement.duration = new Date() - stackElement.start;
  335.                                 stackElement.error = self.status < 200 || self.status >= 400;
  336.                                 stackElement.statusCode = self.status;
  337.                                 extractHeaders(self, stackElement);
  338.                                 finishAjaxRequest(idx);
  339.                             }
  340.                         }, false);
  341.                         startAjaxRequest(idx);
  342.                     }
  343.                     proxied.apply(this, Array.prototype.slice.call(arguments));
  344.                 };
  345.             }
  346.         {% endif %}
  347.         return {
  348.             hasClass: hasClass,
  349.             removeClass: removeClass,
  350.             addClass: addClass,
  351.             toggleClass: toggleClass,
  352.             getPreference: getPreference,
  353.             setPreference: setPreference,
  354.             addEventListener: addEventListener,
  355.             request: request,
  356.             renderAjaxRequests: renderAjaxRequests,
  357.             getSfwdt: function(token) {
  358.                 if (!this.sfwdt) {
  359.                     this.sfwdt = document.getElementById('sfwdt' + token);
  360.                 }
  361.                 return this.sfwdt;
  362.             },
  363.             load: function(selector, url, onSuccess, onError, options) {
  364.                 var el = document.getElementById(selector);
  365.                 if (el && el.getAttribute('data-sfurl') !== url) {
  366.                     request(
  367.                         url,
  368.                         function(xhr) {
  369.                             el.innerHTML = xhr.responseText;
  370.                             el.setAttribute('data-sfurl', url);
  371.                             removeClass(el, 'loading');
  372.                             var pending = pendingRequests;
  373.                             for (var i = 0; i < requestStack.length; i++) {
  374.                                 startAjaxRequest(i);
  375.                                 if (requestStack[i].duration) {
  376.                                     finishAjaxRequest(i);
  377.                                 }
  378.                             }
  379.                             /* Revert the pending state in case there was a start called without a finish above. */
  380.                             pendingRequests = pending;
  381.                             (onSuccess || noop)(xhr, el);
  382.                         },
  383.                         function(xhr) { (onError || noop)(xhr, el); },
  384.                         '',
  385.                         options
  386.                     );
  387.                 }
  388.                 return this;
  389.             },
  390.             showToolbar: function(token) {
  391.                 var sfwdt = this.getSfwdt(token);
  392.                 removeClass(sfwdt, 'sf-display-none');
  393.                 if (getPreference('toolbar/displayState') == 'none') {
  394.                     document.getElementById('sfToolbarMainContent-' + token).style.display = 'none';
  395.                     document.getElementById('sfToolbarClearer-' + token).style.display = 'none';
  396.                     document.getElementById('sfMiniToolbar-' + token).style.display = 'block';
  397.                 } else {
  398.                     document.getElementById('sfToolbarMainContent-' + token).style.display = 'block';
  399.                     document.getElementById('sfToolbarClearer-' + token).style.display = 'block';
  400.                     document.getElementById('sfMiniToolbar-' + token).style.display = 'none';
  401.                 }
  402.             },
  403.             hideToolbar: function(token) {
  404.                 var sfwdt = this.getSfwdt(token);
  405.                 addClass(sfwdt, 'sf-display-none');
  406.             },
  407.             initToolbar: function(token) {
  408.                 this.showToolbar(token);
  409.                 var hideButton = document.getElementById('sfToolbarHideButton-' + token);
  410.                 var hideButtonSvg = hideButton.querySelector('svg');
  411.                 hideButtonSvg.setAttribute('aria-hidden', 'true');
  412.                 hideButtonSvg.setAttribute('focusable', 'false');
  413.                 addEventListener(hideButton, 'click', function (event) {
  414.                     event.preventDefault();
  415.                     var p = this.parentNode;
  416.                     p.style.display = 'none';
  417.                     (p.previousElementSibling || p.previousSibling).style.display = 'none';
  418.                     document.getElementById('sfMiniToolbar-' + token).style.display = 'block';
  419.                     setPreference('toolbar/displayState', 'none');
  420.                 });
  421.                 var showButton = document.getElementById('sfToolbarMiniToggler-' + token);
  422.                 var showButtonSvg = showButton.querySelector('svg');
  423.                 showButtonSvg.setAttribute('aria-hidden', 'true');
  424.                 showButtonSvg.setAttribute('focusable', 'false');
  425.                 addEventListener(showButton, 'click', function (event) {
  426.                     event.preventDefault();
  427.                     var elem = this.parentNode;
  428.                     if (elem.style.display == 'none') {
  429.                         document.getElementById('sfToolbarMainContent-' + token).style.display = 'none';
  430.                         document.getElementById('sfToolbarClearer-' + token).style.display = 'none';
  431.                         elem.style.display = 'block';
  432.                     } else {
  433.                         document.getElementById('sfToolbarMainContent-' + token).style.display = 'block';
  434.                         document.getElementById('sfToolbarClearer-' + token).style.display = 'block';
  435.                         elem.style.display = 'none'
  436.                     }
  437.                     setPreference('toolbar/displayState', 'block');
  438.                 });
  439.             },
  440.             loadToolbar: function(token, newToken) {
  441.                 var that = this;
  442.                 var triesCounter = document.getElementById('sfLoadCounter-' + token);
  443.                 var options = {
  444.                     retry: true,
  445.                     onSend: function (count) {
  446.                         if (count === 3) {
  447.                             that.initToolbar(token);
  448.                         }
  449.                         if (triesCounter) {
  450.                             triesCounter.textContent = count;
  451.                         }
  452.                     },
  453.                 };
  454.                 var cancelButton = document.getElementById('sfLoadCancel-' + token);
  455.                 if (cancelButton) {
  456.                     addEventListener(cancelButton, 'click', function (event) {
  457.                         event.preventDefault();
  458.                         options.stop = true;
  459.                         that.hideToolbar(token);
  460.                     });
  461.                 }
  462.                 newToken = (newToken || token);
  463.                 this.load(
  464.                     'sfwdt' + token,
  465.                     '{{ url("_wdt", { "token": "xxxxxx" })|escape('js') }}'.replace(/xxxxxx/, newToken),
  466.                     function(xhr, el) {
  467.                         /* Do nothing in the edge case where the toolbar has already been replaced with a new one */
  468.                         if (!document.getElementById('sfToolbarMainContent-' + newToken)) {
  469.                             return;
  470.                         }
  471.                         /* Evaluate in global scope scripts embedded inside the toolbar */
  472.                         var i, scripts = [].slice.call(el.querySelectorAll('script'));
  473.                         for (i = 0; i < scripts.length; ++i) {
  474.                             eval.call({}, scripts[i].firstChild.nodeValue);
  475.                         }
  476.                         el.style.display = -1 !== xhr.responseText.indexOf('sf-toolbarreset') ? 'block' : 'none';
  477.                         if (el.style.display == 'none') {
  478.                             return;
  479.                         }
  480.                         that.initToolbar(newToken);
  481.                         /* Handle toolbar-info position */
  482.                         var toolbarBlocks = [].slice.call(el.querySelectorAll('.sf-toolbar-block'));
  483.                         for (i = 0; i < toolbarBlocks.length; ++i) {
  484.                             toolbarBlocks[i].onmouseover = function () {
  485.                                 var toolbarInfo = this.querySelectorAll('.sf-toolbar-info')[0];
  486.                                 var pageWidth = document.body.clientWidth;
  487.                                 var elementWidth = toolbarInfo.offsetWidth;
  488.                                 var leftValue = (elementWidth + this.offsetLeft) - pageWidth;
  489.                                 var rightValue = (elementWidth + (pageWidth - this.offsetLeft)) - pageWidth;
  490.                                 /* Reset right and left value, useful on window resize */
  491.                                 toolbarInfo.style.right = '';
  492.                                 toolbarInfo.style.left = '';
  493.                                 if (elementWidth > pageWidth) {
  494.                                     toolbarInfo.style.left = 0;
  495.                                 }
  496.                                 else if (leftValue > 0 && rightValue > 0) {
  497.                                     toolbarInfo.style.right = (rightValue * -1) + 'px';
  498.                                 } else if (leftValue < 0) {
  499.                                     toolbarInfo.style.left = 0;
  500.                                 } else {
  501.                                     toolbarInfo.style.right = '0px';
  502.                                 }
  503.                             };
  504.                         }
  505.                         renderAjaxRequests();
  506.                         addEventListener(document.querySelector('.sf-toolbar-ajax-clear'), 'click', function() {
  507.                             requestStack = [];
  508.                             renderAjaxRequests();
  509.                             successStreak = 4;
  510.                             document.querySelector('.sf-toolbar-ajax-request-list').innerHTML = '';
  511.                         });
  512.                         addEventListener(document.querySelector('.sf-toolbar-block-ajax'), 'mouseenter', function (event) {
  513.                             var elem = document.querySelector('.sf-toolbar-block-ajax .sf-toolbar-info');
  514.                             elem.scrollTop = elem.scrollHeight;
  515.                         });
  516.                         addEventListener(document.querySelector('.sf-toolbar-block-ajax > .sf-toolbar-icon'), 'click', function (event) {
  517.                             event.preventDefault();
  518.                             toggleClass(this.parentNode, 'hover');
  519.                         });
  520.                         var dumpInfo = document.querySelector('.sf-toolbar-block-dump .sf-toolbar-info');
  521.                         if (null !== dumpInfo) {
  522.                             addEventListener(dumpInfo, 'sfbeforedumpcollapse', function () {
  523.                                 dumpInfo.style.minHeight = dumpInfo.getBoundingClientRect().height+'px';
  524.                             });
  525.                             addEventListener(dumpInfo, 'mouseleave', function () {
  526.                                 dumpInfo.style.minHeight = '';
  527.                             });
  528.                         }
  529.                     },
  530.                     function(xhr) {
  531.                         if (xhr.status !== 0 && !options.stop) {
  532.                             var sfwdt = that.getSfwdt(token);
  533.                             sfwdt.innerHTML = '\
  534.                                 <div class="sf-toolbarreset">\
  535.                                     <div class="sf-toolbar-icon"><svg width="26" height="28" xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" viewBox="0 0 26 28" enable-background="new 0 0 26 28" xml:space="preserve"><path fill="#FFFFFF" d="M13 0C5.8 0 0 5.8 0 13c0 7.2 5.8 13 13 13c7.2 0 13-5.8 13-13C26 5.8 20.2 0 13 0z M20 7.5 c-0.6 0-1-0.3-1-0.9c0-0.2 0-0.4 0.2-0.6c0.1-0.3 0.2-0.3 0.2-0.4c0-0.3-0.5-0.4-0.7-0.4c-2 0.1-2.5 2.7-2.9 4.8l-0.2 1.1 c1.1 0.2 1.9 0 2.4-0.3c0.6-0.4-0.2-0.8-0.1-1.3C18 9.2 18.4 9 18.7 8.9c0.5 0 0.8 0.5 0.8 1c0 0.8-1.1 2-3.3 1.9 c-0.3 0-0.5 0-0.7-0.1L15 14.1c-0.4 1.7-0.9 4.1-2.6 6.2c-1.5 1.8-3.1 2.1-3.8 2.1c-1.3 0-2.1-0.6-2.2-1.6c0-0.9 0.8-1.4 1.3-1.4 c0.7 0 1.2 0.5 1.2 1.1c0 0.5-0.2 0.6-0.4 0.7c-0.1 0.1-0.3 0.2-0.3 0.4c0 0.1 0.1 0.3 0.4 0.3c0.5 0 0.9-0.3 1.2-0.5 c1.3-1 1.7-2.9 2.4-6.2l0.1-0.8c0.2-1.1 0.5-2.3 0.8-3.5c-0.9-0.7-1.4-1.5-2.6-1.8c-0.8-0.2-1.3 0-1.7 0.4C8.4 10 8.6 10.7 9 11.1 l0.7 0.7c0.8 0.9 1.3 1.7 1.1 2.7c-0.3 1.6-2.1 2.8-4.3 2.1c-1.9-0.6-2.2-1.9-2-2.7c0.2-0.6 0.7-0.8 1.2-0.6 c0.5 0.2 0.7 0.8 0.6 1.3c0 0.1 0 0.1-0.1 0.3C6 15 5.9 15.2 5.9 15.3c-0.1 0.4 0.4 0.7 0.8 0.8c0.8 0.3 1.7-0.2 1.9-0.9 c0.2-0.6-0.2-1.1-0.4-1.2l-0.8-0.9c-0.4-0.4-1.2-1.5-0.8-2.8c0.2-0.5 0.5-1 0.9-1.4c1-0.7 2-0.8 3-0.6c1.3 0.4 1.9 1.2 2.8 1.9 c0.5-1.3 1.1-2.6 2-3.8c0.9-1 2-1.7 3.3-1.8C20 4.8 21 5.4 21 6.3C21 6.7 20.8 7.5 20 7.5z"/></svg></div>\
  536.                                     An error occurred while loading the web debug toolbar. <a href="{{ url("_profiler_home")|escape('js') }}' + newToken + '>Open the web profiler.</a>\
  537.                                 </div>\
  538.                             ';
  539.                             sfwdt.setAttribute('class', 'sf-toolbar sf-error-toolbar');
  540.                         }
  541.                     },
  542.                     options
  543.                 );
  544.                 return this;
  545.             },
  546.             toggle: function(selector, elOn, elOff) {
  547.                 var tmp = elOn.style.display,
  548.                     el = document.getElementById(selector);
  549.                 elOn.style.display = elOff.style.display;
  550.                 elOff.style.display = tmp;
  551.                 if (el) {
  552.                     el.style.display = 'none' === tmp ? 'none' : 'block';
  553.                 }
  554.                 return this;
  555.             },
  556.             createTabs: function() {
  557.                 var tabGroups = document.querySelectorAll('.sf-tabs:not([data-processed=true])');
  558.                 /* create the tab navigation for each group of tabs */
  559.                 for (var i = 0; i < tabGroups.length; i++) {
  560.                     var tabs = tabGroups[i].querySelectorAll(':scope > .tab');
  561.                     var tabNavigation = document.createElement('ul');
  562.                     tabNavigation.className = 'tab-navigation';
  563.                     var selectedTabId = 'tab-' + i + '-0'; /* select the first tab by default */
  564.                     for (var j = 0; j < tabs.length; j++) {
  565.                         var tabId = 'tab-' + i + '-' + j;
  566.                         var tabTitle = tabs[j].querySelector('.tab-title').innerHTML;
  567.                         var tabNavigationItem = document.createElement('li');
  568.                         tabNavigationItem.setAttribute('data-tab-id', tabId);
  569.                         if (hasClass(tabs[j], 'active')) { selectedTabId = tabId; }
  570.                         if (hasClass(tabs[j], 'disabled')) { addClass(tabNavigationItem, 'disabled'); }
  571.                         tabNavigationItem.innerHTML = tabTitle;
  572.                         tabNavigation.appendChild(tabNavigationItem);
  573.                         var tabContent = tabs[j].querySelector('.tab-content');
  574.                         tabContent.parentElement.setAttribute('id', tabId);
  575.                     }
  576.                     tabGroups[i].insertBefore(tabNavigation, tabGroups[i].firstChild);
  577.                     addClass(document.querySelector('[data-tab-id="' + selectedTabId + '"]'), 'active');
  578.                 }
  579.                 /* display the active tab and add the 'click' event listeners */
  580.                 for (i = 0; i < tabGroups.length; i++) {
  581.                     tabNavigation = tabGroups[i].querySelectorAll(':scope > .tab-navigation li');
  582.                     for (j = 0; j < tabNavigation.length; j++) {
  583.                         tabId = tabNavigation[j].getAttribute('data-tab-id');
  584.                         document.getElementById(tabId).querySelector('.tab-title').className = 'hidden';
  585.                         if (hasClass(tabNavigation[j], 'active')) {
  586.                             document.getElementById(tabId).className = 'block';
  587.                         } else {
  588.                             document.getElementById(tabId).className = 'hidden';
  589.                         }
  590.                         tabNavigation[j].addEventListener('click', function(e) {
  591.                             var activeTab = e.target || e.srcElement;
  592.                             /* needed because when the tab contains HTML contents, user can click */
  593.                             /* on any of those elements instead of their parent '<li>' element */
  594.                             while (activeTab.tagName.toLowerCase() !== 'li') {
  595.                                 activeTab = activeTab.parentNode;
  596.                             }
  597.                             /* get the full list of tabs through the parent of the active tab element */
  598.                             var tabNavigation = activeTab.parentNode.children;
  599.                             for (var k = 0; k < tabNavigation.length; k++) {
  600.                                 var tabId = tabNavigation[k].getAttribute('data-tab-id');
  601.                                 document.getElementById(tabId).className = 'hidden';
  602.                                 removeClass(tabNavigation[k], 'active');
  603.                             }
  604.                             addClass(activeTab, 'active');
  605.                             var activeTabId = activeTab.getAttribute('data-tab-id');
  606.                             document.getElementById(activeTabId).className = 'block';
  607.                         });
  608.                     }
  609.                     tabGroups[i].setAttribute('data-processed', 'true');
  610.                 }
  611.             },
  612.             createToggles: function() {
  613.                 var toggles = document.querySelectorAll('.sf-toggle:not([data-processed=true])');
  614.                 for (var i = 0; i < toggles.length; i++) {
  615.                     var elementSelector = toggles[i].getAttribute('data-toggle-selector');
  616.                     var element = document.querySelector(elementSelector);
  617.                     addClass(element, 'sf-toggle-content');
  618.                     if (toggles[i].hasAttribute('data-toggle-initial') && toggles[i].getAttribute('data-toggle-initial') == 'display') {
  619.                         addClass(toggles[i], 'sf-toggle-on');
  620.                         addClass(element, 'sf-toggle-visible');
  621.                     } else {
  622.                         addClass(toggles[i], 'sf-toggle-off');
  623.                         addClass(element, 'sf-toggle-hidden');
  624.                     }
  625.                     addEventListener(toggles[i], 'click', function(e) {
  626.                         e.preventDefault();
  627.                         if ('' !== window.getSelection().toString()) {
  628.                             /* Don't do anything on text selection */
  629.                             return;
  630.                         }
  631.                         var toggle = e.target || e.srcElement;
  632.                         /* needed because when the toggle contains HTML contents, user can click */
  633.                         /* on any of those elements instead of their parent '.sf-toggle' element */
  634.                         while (!hasClass(toggle, 'sf-toggle')) {
  635.                             toggle = toggle.parentNode;
  636.                         }
  637.                         var element = document.querySelector(toggle.getAttribute('data-toggle-selector'));
  638.                         toggleClass(toggle, 'sf-toggle-on');
  639.                         toggleClass(toggle, 'sf-toggle-off');
  640.                         toggleClass(element, 'sf-toggle-hidden');
  641.                         toggleClass(element, 'sf-toggle-visible');
  642.                         /* the toggle doesn't change its contents when clicking on it */
  643.                         if (!toggle.hasAttribute('data-toggle-alt-content')) {
  644.                             return;
  645.                         }
  646.                         if (!toggle.hasAttribute('data-toggle-original-content')) {
  647.                             toggle.setAttribute('data-toggle-original-content', toggle.innerHTML);
  648.                         }
  649.                         var currentContent = toggle.innerHTML;
  650.                         var originalContent = toggle.getAttribute('data-toggle-original-content');
  651.                         var altContent = toggle.getAttribute('data-toggle-alt-content');
  652.                         toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
  653.                     });
  654.                     /* Prevents from disallowing clicks on links inside toggles */
  655.                     var toggleLinks = toggles[i].querySelectorAll('a');
  656.                     for (var j = 0; j < toggleLinks.length; j++) {
  657.                         addEventListener(toggleLinks[j], 'click', function(e) {
  658.                             e.stopPropagation();
  659.                         });
  660.                     }
  661.                     /* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */
  662.                     var copyToClipboardElements = toggles[i].querySelectorAll('span[data-clipboard-text]');
  663.                     for (var k = 0; k < copyToClipboardElements.length; k++) {
  664.                         addEventListener(copyToClipboardElements[k], 'click', function(e) {
  665.                             e.stopPropagation();
  666.                         });
  667.                     }
  668.                     toggles[i].setAttribute('data-processed', 'true');
  669.                 }
  670.             },
  671.             initializeLogsTable: function() {
  672.                 Sfjs.updateLogsTable();
  673.                 document.querySelectorAll('.log-filter input').forEach((input) => {
  674.                     input.addEventListener('change', () => { Sfjs.updateLogsTable(); });
  675.                 });
  676.                 document.querySelectorAll('.filter-select-all-or-none button').forEach((link) => {
  677.                     link.addEventListener('click', () => {
  678.                         const selectAll = link.classList.contains('select-all');
  679.                         link.closest('.log-filter-content').querySelectorAll('input').forEach((input) => {
  680.                             input.checked = selectAll;
  681.                         });
  682.                         Sfjs.updateLogsTable();
  683.                     });
  684.                 });
  685.                 document.body.addEventListener('click', (event) => {
  686.                     document.querySelectorAll('details.log-filter').forEach((filterElement) => {
  687.                         if (!filterElement.contains(event.target) && filterElement.open) {
  688.                             filterElement.open = false;
  689.                         }
  690.                     });
  691.                 });
  692.             },
  693.             updateLogsTable: function() {
  694.                 const selectedType = document.querySelector('#log-filter-type input:checked').value;
  695.                 const priorities = document.querySelectorAll('#log-filter-priority input');
  696.                 const allPriorities = Array.from(priorities).map((input) => input.value);
  697.                 const selectedPriorities = Array.from(priorities).filter((input) => input.checked).map((input) => input.value);
  698.                 const channels = document.querySelectorAll('#log-filter-channel input');
  699.                 const selectedChannels = Array.from(channels).filter((input) => input.checked).map((input) => input.value);
  700.                 const logs = document.querySelector('table.logs');
  701.                 if (null === logs) {
  702.                     return;
  703.                 }
  704.                 /* hide rows that don't match the current filters */
  705.                 let numVisibleRows = 0;
  706.                 logs.querySelectorAll('tbody tr').forEach((row) => {
  707.                     if ('all' !== selectedType && selectedType !== row.getAttribute('data-type')) {
  708.                         row.style.display = 'none';
  709.                         return;
  710.                     }
  711.                     const priority = row.getAttribute('data-priority');
  712.                     if (false === selectedPriorities.includes(priority) && true === allPriorities.includes(priority)) {
  713.                         row.style.display = 'none';
  714.                         return;
  715.                     }
  716.                     if ('' !== row.getAttribute('data-channel') && false === selectedChannels.includes(row.getAttribute('data-channel'))) {
  717.                         row.style.display = 'none';
  718.                         return;
  719.                     }
  720.                     row.style.display = 'table-row';
  721.                     numVisibleRows++;
  722.                 });
  723.                 document.querySelector('table.logs').style.display = 0 === numVisibleRows ? 'none' : 'table';
  724.                 document.querySelector('.no-logs-message').style.display = 0 === numVisibleRows ? 'block' : 'none';
  725.                 /* update the selected totals of all filters */
  726.                 document.querySelector('#log-filter-priority .filter-active-num').innerText = (priorities.length === selectedPriorities.length) ? 'All' : selectedPriorities.length;
  727.                 document.querySelector('#log-filter-channel .filter-active-num').innerText = (channels.length === selectedChannels.length) ? 'All' : selectedChannels.length;
  728.                 /* update the currently selected "log type" tab */
  729.                 document.querySelectorAll('#log-filter-type li').forEach((tab) => tab.classList.remove('active'));
  730.                 document.querySelector(`#log-filter-type input[value="${selectedType}"]`).parentElement.classList.add('active');
  731.             },
  732.         };
  733.     })();
  734.     Sfjs.addEventListener(document, 'DOMContentLoaded', function() {
  735.         Sfjs.createTabs();
  736.         Sfjs.createToggles();
  737.     });
  738. }
  739. /*]]>*/</script>