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