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

Open in your IDE?
  1. {% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %}
  2. {# This file is based on WebProfilerBundle/Resources/views/Profiler/base_js.html.twig.
  3.    If you make any change in this file, verify the same change is needed in the other file. #}
  4. <script{% if csp_script_nonce is defined and csp_script_nonce %} nonce="{{ csp_script_nonce }}"{% endif %}>/*<![CDATA[*/
  5.     {# Caution: the contents of this file are processed by Twig before loading
  6.                 them as JavaScript source code. Always use '/*' comments instead
  7.                 of '//' comments to avoid impossible-to-debug side-effects #}
  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 addEventListener;
  22.         var el = document.createElement('div');
  23.         if (!('addEventListener' in el)) {
  24.             addEventListener = function (element, eventName, callback) {
  25.                 element.attachEvent('on' + eventName, callback);
  26.             };
  27.         } else {
  28.             addEventListener = function (element, eventName, callback) {
  29.                 element.addEventListener(eventName, callback, false);
  30.             };
  31.         }
  32.         return {
  33.             addEventListener: addEventListener,
  34.             createTabs: function() {
  35.                 var tabGroups = document.querySelectorAll('.sf-tabs:not([data-processed=true])');
  36.                 /* create the tab navigation for each group of tabs */
  37.                 for (var i = 0; i < tabGroups.length; i++) {
  38.                     var tabs = tabGroups[i].querySelectorAll(':scope > .tab');
  39.                     var tabNavigation = document.createElement('ul');
  40.                     tabNavigation.className = 'tab-navigation';
  41.                     var selectedTabId = 'tab-' + i + '-0'; /* select the first tab by default */
  42.                     for (var j = 0; j < tabs.length; j++) {
  43.                         var tabId = 'tab-' + i + '-' + j;
  44.                         var tabTitle = tabs[j].querySelector('.tab-title').innerHTML;
  45.                         var tabNavigationItem = document.createElement('li');
  46.                         tabNavigationItem.setAttribute('data-tab-id', tabId);
  47.                         if (hasClass(tabs[j], 'active')) { selectedTabId = tabId; }
  48.                         if (hasClass(tabs[j], 'disabled')) { addClass(tabNavigationItem, 'disabled'); }
  49.                         tabNavigationItem.innerHTML = tabTitle;
  50.                         tabNavigation.appendChild(tabNavigationItem);
  51.                         var tabContent = tabs[j].querySelector('.tab-content');
  52.                         tabContent.parentElement.setAttribute('id', tabId);
  53.                     }
  54.                     tabGroups[i].insertBefore(tabNavigation, tabGroups[i].firstChild);
  55.                     addClass(document.querySelector('[data-tab-id="' + selectedTabId + '"]'), 'active');
  56.                 }
  57.                 /* display the active tab and add the 'click' event listeners */
  58.                 for (i = 0; i < tabGroups.length; i++) {
  59.                     tabNavigation = tabGroups[i].querySelectorAll(':scope >.tab-navigation li');
  60.                     for (j = 0; j < tabNavigation.length; j++) {
  61.                         tabId = tabNavigation[j].getAttribute('data-tab-id');
  62.                         document.getElementById(tabId).querySelector('.tab-title').className = 'hidden';
  63.                         if (hasClass(tabNavigation[j], 'active')) {
  64.                             document.getElementById(tabId).className = 'block';
  65.                         } else {
  66.                             document.getElementById(tabId).className = 'hidden';
  67.                         }
  68.                         tabNavigation[j].addEventListener('click', function(e) {
  69.                             var activeTab = e.target || e.srcElement;
  70.                             /* needed because when the tab contains HTML contents, user can click */
  71.                             /* on any of those elements instead of their parent '<li>' element */
  72.                             while (activeTab.tagName.toLowerCase() !== 'li') {
  73.                                 activeTab = activeTab.parentNode;
  74.                             }
  75.                             /* get the full list of tabs through the parent of the active tab element */
  76.                             var tabNavigation = activeTab.parentNode.children;
  77.                             for (var k = 0; k < tabNavigation.length; k++) {
  78.                                 var tabId = tabNavigation[k].getAttribute('data-tab-id');
  79.                                 document.getElementById(tabId).className = 'hidden';
  80.                                 removeClass(tabNavigation[k], 'active');
  81.                             }
  82.                             addClass(activeTab, 'active');
  83.                             var activeTabId = activeTab.getAttribute('data-tab-id');
  84.                             document.getElementById(activeTabId).className = 'block';
  85.                         });
  86.                     }
  87.                     tabGroups[i].setAttribute('data-processed', 'true');
  88.                 }
  89.             },
  90.             createToggles: function() {
  91.                 var toggles = document.querySelectorAll('.sf-toggle:not([data-processed=true])');
  92.                 for (var i = 0; i < toggles.length; i++) {
  93.                     var elementSelector = toggles[i].getAttribute('data-toggle-selector');
  94.                     var element = document.querySelector(elementSelector);
  95.                     addClass(element, 'sf-toggle-content');
  96.                     if (toggles[i].hasAttribute('data-toggle-initial') && toggles[i].getAttribute('data-toggle-initial') == 'display') {
  97.                         addClass(toggles[i], 'sf-toggle-on');
  98.                         addClass(element, 'sf-toggle-visible');
  99.                     } else {
  100.                         addClass(toggles[i], 'sf-toggle-off');
  101.                         addClass(element, 'sf-toggle-hidden');
  102.                     }
  103.                     addEventListener(toggles[i], 'click', function(e) {
  104.                         e.preventDefault();
  105.                         if ('' !== window.getSelection().toString()) {
  106.                             /* Don't do anything on text selection */
  107.                             return;
  108.                         }
  109.                         var toggle = e.target || e.srcElement;
  110.                         /* needed because when the toggle contains HTML contents, user can click */
  111.                         /* on any of those elements instead of their parent '.sf-toggle' element */
  112.                         while (!hasClass(toggle, 'sf-toggle')) {
  113.                             toggle = toggle.parentNode;
  114.                         }
  115.                         var element = document.querySelector(toggle.getAttribute('data-toggle-selector'));
  116.                         toggleClass(toggle, 'sf-toggle-on');
  117.                         toggleClass(toggle, 'sf-toggle-off');
  118.                         toggleClass(element, 'sf-toggle-hidden');
  119.                         toggleClass(element, 'sf-toggle-visible');
  120.                         /* the toggle doesn't change its contents when clicking on it */
  121.                         if (!toggle.hasAttribute('data-toggle-alt-content')) {
  122.                             return;
  123.                         }
  124.                         if (!toggle.hasAttribute('data-toggle-original-content')) {
  125.                             toggle.setAttribute('data-toggle-original-content', toggle.innerHTML);
  126.                         }
  127.                         var currentContent = toggle.innerHTML;
  128.                         var originalContent = toggle.getAttribute('data-toggle-original-content');
  129.                         var altContent = toggle.getAttribute('data-toggle-alt-content');
  130.                         toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
  131.                     });
  132.                     /* Prevents from disallowing clicks on links inside toggles */
  133.                     var toggleLinks = toggles[i].querySelectorAll('a');
  134.                     for (var j = 0; j < toggleLinks.length; j++) {
  135.                         addEventListener(toggleLinks[j], 'click', function(e) {
  136.                             e.stopPropagation();
  137.                         });
  138.                     }
  139.                     toggles[i].setAttribute('data-processed', 'true');
  140.                 }
  141.             },
  142.             createFilters: function() {
  143.                 document.querySelectorAll('[data-filters] [data-filter]').forEach(function (filter) {
  144.                     var filters = filter.closest('[data-filters]'),
  145.                         type = 'choice',
  146.                         name = filter.dataset.filter,
  147.                         ucName = name.charAt(0).toUpperCase()+name.slice(1),
  148.                         list = document.createElement('ul'),
  149.                         values = filters.dataset['filter'+ucName] || filters.querySelectorAll('[data-filter-'+name+']'),
  150.                         labels = {},
  151.                         defaults = null,
  152.                         indexed = {},
  153.                         processed = {};
  154.                     if (typeof values === 'string') {
  155.                         type = 'level';
  156.                         labels = values.split(',');
  157.                         values = values.toLowerCase().split(',');
  158.                         defaults = values.length - 1;
  159.                     }
  160.                     addClass(list, 'filter-list');
  161.                     addClass(list, 'filter-list-'+type);
  162.                     values.forEach(function (value, i) {
  163.                         if (value instanceof HTMLElement) {
  164.                             value = value.dataset['filter'+ucName];
  165.                         }
  166.                         if (value in processed) {
  167.                             return;
  168.                         }
  169.                         var option = document.createElement('li'),
  170.                             label = i in labels ? labels[i] : value,
  171.                             active = false,
  172.                             matches;
  173.                         if ('' === label) {
  174.                             option.innerHTML = '<em>(none)</em>';
  175.                         } else {
  176.                             option.innerText = label;
  177.                         }
  178.                         option.dataset.filter = value;
  179.                         option.setAttribute('title', 1 === (matches = filters.querySelectorAll('[data-filter-'+name+'="'+value+'"]').length) ? 'Matches 1 row' : 'Matches '+matches+' rows');
  180.                         indexed[value] = i;
  181.                         list.appendChild(option);
  182.                         addEventListener(option, 'click', function () {
  183.                             if ('choice' === type) {
  184.                                 filters.querySelectorAll('[data-filter-'+name+']').forEach(function (row) {
  185.                                     if (option.dataset.filter === row.dataset['filter'+ucName]) {
  186.                                         toggleClass(row, 'filter-hidden-'+name);
  187.                                     }
  188.                                 });
  189.                                 toggleClass(option, 'active');
  190.                             } else if ('level' === type) {
  191.                                 if (i === this.parentNode.querySelectorAll('.active').length - 1) {
  192.                                     return;
  193.                                 }
  194.                                 this.parentNode.querySelectorAll('li').forEach(function (currentOption, j) {
  195.                                     if (j <= i) {
  196.                                         addClass(currentOption, 'active');
  197.                                         if (i === j) {
  198.                                             addClass(currentOption, 'last-active');
  199.                                         } else {
  200.                                             removeClass(currentOption, 'last-active');
  201.                                         }
  202.                                     } else {
  203.                                         removeClass(currentOption, 'active');
  204.                                         removeClass(currentOption, 'last-active');
  205.                                     }
  206.                                 });
  207.                                 filters.querySelectorAll('[data-filter-'+name+']').forEach(function (row) {
  208.                                     if (i < indexed[row.dataset['filter'+ucName]]) {
  209.                                         addClass(row, 'filter-hidden-'+name);
  210.                                     } else {
  211.                                         removeClass(row, 'filter-hidden-'+name);
  212.                                     }
  213.                                 });
  214.                             }
  215.                         });
  216.                         if ('choice' === type) {
  217.                             active = null === defaults || 0 <= defaults.indexOf(value);
  218.                         } else if ('level' === type) {
  219.                             active = i <= defaults;
  220.                             if (active && i === defaults) {
  221.                                 addClass(option, 'last-active');
  222.                             }
  223.                         }
  224.                         if (active) {
  225.                             addClass(option, 'active');
  226.                         } else {
  227.                             filters.querySelectorAll('[data-filter-'+name+'="'+value+'"]').forEach(function (row) {
  228.                                 toggleClass(row, 'filter-hidden-'+name);
  229.                             });
  230.                         }
  231.                         processed[value] = true;
  232.                     });
  233.                     if (1 < list.childNodes.length) {
  234.                         filter.appendChild(list);
  235.                         filter.dataset.filtered = '';
  236.                     }
  237.                 });
  238.             }
  239.         };
  240.     })();
  241.     Sfjs.addEventListener(document, 'DOMContentLoaded', function() {
  242.         Sfjs.createTabs();
  243.         Sfjs.createToggles();
  244.         Sfjs.createFilters();
  245.     });
  246. /*]]>*/</script>