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 TwigBundle/Resources/views/base_js.html.twig. If you
  2.    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.     Sfjs = (function() {
  8.         "use strict";
  9.         if ('classList' in document.documentElement) {
  10.             var hasClass = function (el, cssClass) { return el.classList.contains(cssClass); };
  11.             var removeClass = function(el, cssClass) { el.classList.remove(cssClass); };
  12.             var addClass = function(el, cssClass) { el.classList.add(cssClass); };
  13.             var toggleClass = function(el, cssClass) { el.classList.toggle(cssClass); };
  14.         } else {
  15.             var hasClass = function (el, cssClass) { return el.className.match(new RegExp('\\b' + cssClass + '\\b')); };
  16.             var removeClass = function(el, cssClass) { el.className = el.className.replace(new RegExp('\\b' + cssClass + '\\b'), ' '); };
  17.             var addClass = function(el, cssClass) { if (!hasClass(el, cssClass)) { el.className += " " + cssClass; } };
  18.             var toggleClass = function(el, cssClass) { hasClass(el, cssClass) ? removeClass(el, cssClass) : addClass(el, cssClass); };
  19.         }
  20.         var noop = function() {};
  21.         var profilerStorageKey = 'symfony/profiler/';
  22.         var request = function(url, onSuccess, onError, payload, options) {
  23.             var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  24.             options = options || {};
  25.             options.maxTries = options.maxTries || 0;
  26.             xhr.open(options.method || 'GET', url, true);
  27.             xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  28.             xhr.onreadystatechange = function(state) {
  29.                 if (4 !== xhr.readyState) {
  30.                     return null;
  31.                 }
  32.                 if (xhr.status == 404 && options.maxTries > 1) {
  33.                     setTimeout(function(){
  34.                         options.maxTries--;
  35.                         request(url, onSuccess, onError, payload, options);
  36.                     }, 1000);
  37.                     return null;
  38.                 }
  39.                 if (200 === xhr.status) {
  40.                     (onSuccess || noop)(xhr);
  41.                 } else {
  42.                     (onError || noop)(xhr);
  43.                 }
  44.             };
  45.             xhr.send(payload || '');
  46.         };
  47.         var getPreference = function(name) {
  48.             if (!window.localStorage) {
  49.                 return null;
  50.             }
  51.             return localStorage.getItem(profilerStorageKey + name);
  52.         };
  53.         var setPreference = function(name, value) {
  54.             if (!window.localStorage) {
  55.                 return null;
  56.             }
  57.             localStorage.setItem(profilerStorageKey + name, value);
  58.         };
  59.         var requestStack = [];
  60.         var extractHeaders = function(xhr, stackElement) {
  61.             /* Here we avoid to call xhr.getResponseHeader in order to */
  62.             /* prevent polluting the console with CORS security errors */
  63.             var allHeaders = xhr.getAllResponseHeaders();
  64.             var ret;
  65.             if (ret = allHeaders.match(/^x-debug-token:\s+(.*)$/im)) {
  66.                 stackElement.profile = ret[1];
  67.             }
  68.             if (ret = allHeaders.match(/^x-debug-token-link:\s+(.*)$/im)) {
  69.                 stackElement.profilerUrl = ret[1];
  70.             }
  71.             if (ret = allHeaders.match(/^Symfony-Debug-Toolbar-Replace:\s+(.*)$/im)) {
  72.                 stackElement.toolbarReplaceFinished = false;
  73.                 stackElement.toolbarReplace = '1' === ret[1];
  74.             }
  75.         };
  76.         var successStreak = 4;
  77.         var pendingRequests = 0;
  78.         var renderAjaxRequests = function() {
  79.             var requestCounter = document.querySelector('.sf-toolbar-ajax-request-counter');
  80.             if (!requestCounter) {
  81.                 return;
  82.             }
  83.             requestCounter.textContent = requestStack.length;
  84.             var infoSpan = document.querySelector(".sf-toolbar-ajax-info");
  85.             if (infoSpan) {
  86.                 infoSpan.textContent = requestStack.length + ' AJAX request' + (requestStack.length !== 1 ? 's' : '');
  87.             }
  88.             var ajaxToolbarPanel = document.querySelector('.sf-toolbar-block-ajax');
  89.             if (requestStack.length) {
  90.                 ajaxToolbarPanel.style.display = 'block';
  91.             } else {
  92.                 ajaxToolbarPanel.style.display = 'none';
  93.             }
  94.             if (pendingRequests > 0) {
  95.                 addClass(ajaxToolbarPanel, 'sf-ajax-request-loading');
  96.             } else if (successStreak < 4) {
  97.                 addClass(ajaxToolbarPanel, 'sf-toolbar-status-red');
  98.                 removeClass(ajaxToolbarPanel, 'sf-ajax-request-loading');
  99.             } else {
  100.                 removeClass(ajaxToolbarPanel, 'sf-ajax-request-loading');
  101.                 removeClass(ajaxToolbarPanel, 'sf-toolbar-status-red');
  102.             }
  103.         };
  104.         var startAjaxRequest = function(index) {
  105.             var tbody = document.querySelector('.sf-toolbar-ajax-request-list');
  106.             if (!tbody) {
  107.                 return;
  108.             }
  109.             var nbOfAjaxRequest = tbody.rows.length;
  110.             if (nbOfAjaxRequest >= 100) {
  111.                 tbody.deleteRow(nbOfAjaxRequest - 1);
  112.             }
  113.             var request = requestStack[index];
  114.             pendingRequests++;
  115.             var row = document.createElement('tr');
  116.             request.DOMNode = row;
  117.             var profilerCell = document.createElement('td');
  118.             profilerCell.textContent = 'n/a';
  119.             row.appendChild(profilerCell);
  120.             var methodCell = document.createElement('td');
  121.             methodCell.textContent = request.method;
  122.             row.appendChild(methodCell);
  123.             var typeCell = document.createElement('td');
  124.             typeCell.textContent = request.type;
  125.             row.appendChild(typeCell);
  126.             var statusCodeCell = document.createElement('td');
  127.             var statusCode = document.createElement('span');
  128.             statusCode.textContent = 'n/a';
  129.             statusCodeCell.appendChild(statusCode);
  130.             row.appendChild(statusCodeCell);
  131.             var pathCell = document.createElement('td');
  132.             pathCell.className = 'sf-ajax-request-url';
  133.             if ('GET' === request.method) {
  134.                 var pathLink = document.createElement('a');
  135.                 pathLink.setAttribute('href', request.url);
  136.                 pathLink.textContent = request.url;
  137.                 pathCell.appendChild(pathLink);
  138.             } else {
  139.                 pathCell.textContent = request.url;
  140.             }
  141.             pathCell.setAttribute('title', request.url);
  142.             row.appendChild(pathCell);
  143.             var durationCell = document.createElement('td');
  144.             durationCell.className = 'sf-ajax-request-duration';
  145.             durationCell.textContent = 'n/a';
  146.             row.appendChild(durationCell);
  147.             request.liveDurationHandle = setInterval(function() {
  148.                 durationCell.textContent = (new Date() - request.start) + 'ms';
  149.             }, 100);
  150.             row.className = 'sf-ajax-request sf-ajax-request-loading';
  151.             tbody.insertBefore(row, tbody.firstChild);
  152.             renderAjaxRequests();
  153.         };
  154.         var finishAjaxRequest = function(index) {
  155.             var request = requestStack[index];
  156.             clearInterval(request.liveDurationHandle);
  157.             if (!request.DOMNode) {
  158.                 return;
  159.             }
  160.             if (request.toolbarReplace && !request.toolbarReplaceFinished && request.profile) {
  161.                 /* Flag as complete because finishAjaxRequest can be called multiple times. */
  162.                 request.toolbarReplaceFinished = true;
  163.                 /* Search up through the DOM to find the toolbar's container ID. */
  164.                 for (var elem = request.DOMNode; elem && elem !== document; elem = elem.parentNode) {
  165.                     if (elem.id.match(/^sfwdt/)) {
  166.                         Sfjs.loadToolbar(elem.id.replace(/^sfwdt/, ''), request.profile);
  167.                         break;
  168.                     }
  169.                 }
  170.             }
  171.             pendingRequests--;
  172.             var row = request.DOMNode;
  173.             /* Unpack the children from the row */
  174.             var profilerCell = row.children[0];
  175.             var methodCell = row.children[1];
  176.             var statusCodeCell = row.children[3];
  177.             var statusCodeElem = statusCodeCell.children[0];
  178.             var durationCell = row.children[5];
  179.             if (request.error) {
  180.                 row.className = 'sf-ajax-request sf-ajax-request-error';
  181.                 methodCell.className = 'sf-ajax-request-error';
  182.                 successStreak = 0;
  183.             } else {
  184.                 row.className = 'sf-ajax-request sf-ajax-request-ok';
  185.                 successStreak++;
  186.             }
  187.             if (request.statusCode) {
  188.                 if (request.statusCode < 300) {
  189.                     statusCodeElem.setAttribute('class', 'sf-toolbar-status');
  190.                 } else if (request.statusCode < 400) {
  191.                     statusCodeElem.setAttribute('class', 'sf-toolbar-status sf-toolbar-status-yellow');
  192.                 } else {
  193.                     statusCodeElem.setAttribute('class', 'sf-toolbar-status sf-toolbar-status-red');
  194.                 }
  195.                 statusCodeElem.textContent = request.statusCode;
  196.             } else {
  197.                 statusCodeElem.setAttribute('class', 'sf-toolbar-status sf-toolbar-status-red');
  198.             }
  199.             if (request.duration) {
  200.                 durationCell.textContent = request.duration + 'ms';
  201.             }
  202.             if (request.profilerUrl) {
  203.                 profilerCell.textContent = '';
  204.                 var profilerLink = document.createElement('a');
  205.                 profilerLink.setAttribute('href', request.statusCode < 400 ? request.profilerUrl : request.profilerUrl + '?panel=exception');
  206.                 profilerLink.textContent = request.profile;
  207.                 profilerCell.appendChild(profilerLink);
  208.             }
  209.             renderAjaxRequests();
  210.         };
  211.         var addEventListener;
  212.         var el = document.createElement('div');
  213.         if (!('addEventListener' in el)) {
  214.             addEventListener = function (element, eventName, callback) {
  215.                 element.attachEvent('on' + eventName, callback);
  216.             };
  217.         } else {
  218.             addEventListener = function (element, eventName, callback) {
  219.                 element.addEventListener(eventName, callback, false);
  220.             };
  221.         }
  222.         {% if excluded_ajax_paths is defined %}
  223.             if (window.fetch && window.fetch.polyfill === undefined) {
  224.                 var oldFetch = window.fetch;
  225.                 window.fetch = function () {
  226.                     var promise = oldFetch.apply(this, arguments);
  227.                     var url = arguments[0];
  228.                     var params = arguments[1];
  229.                     var paramType = Object.prototype.toString.call(arguments[0]);
  230.                     if (paramType === '[object Request]') {
  231.                         url = arguments[0].url;
  232.                         params = {
  233.                             method: arguments[0].method,
  234.                             credentials: arguments[0].credentials,
  235.                             headers: arguments[0].headers,
  236.                             mode: arguments[0].mode,
  237.                             redirect: arguments[0].redirect
  238.                         };
  239.                     } else {
  240.                         url = String(url);
  241.                     }
  242.                     if (!url.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
  243.                         var method = 'GET';
  244.                         if (params && params.method !== undefined) {
  245.                             method = params.method;
  246.                         }
  247.                         var stackElement = {
  248.                             error: false,
  249.                             url: url,
  250.                             method: method,
  251.                             type: 'fetch',
  252.                             start: new Date()
  253.                         };
  254.                         var idx = requestStack.push(stackElement) - 1;
  255.                         promise.then(function (r) {
  256.                             stackElement.duration = new Date() - stackElement.start;
  257.                             stackElement.error = r.status < 200 || r.status >= 400;
  258.                             stackElement.statusCode = r.status;
  259.                             stackElement.profile = r.headers.get('x-debug-token');
  260.                             stackElement.profilerUrl = r.headers.get('x-debug-token-link');
  261.                             stackElement.toolbarReplaceFinished = false;
  262.                             stackElement.toolbarReplace = '1' === r.headers.get('Symfony-Debug-Toolbar-Replace');
  263.                             finishAjaxRequest(idx);
  264.                         }, function (e){
  265.                             stackElement.error = true;
  266.                             finishAjaxRequest(idx);
  267.                         });
  268.                         startAjaxRequest(idx);
  269.                     }
  270.                     return promise;
  271.                 };
  272.             }
  273.             if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
  274.                 var proxied = XMLHttpRequest.prototype.open;
  275.                 XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
  276.                     var self = this;
  277.                     /* prevent logging AJAX calls to static and inline files, like templates */
  278.                     var path = url;
  279.                     if (url.substr(0, 1) === '/') {
  280.                         if (0 === url.indexOf('{{ request.basePath|e('js') }}')) {
  281.                             path = url.substr({{ request.basePath|length }});
  282.                         }
  283.                     }
  284.                     else if (0 === url.indexOf('{{ (request.schemeAndHttpHost ~ request.basePath)|e('js') }}')) {
  285.                         path = url.substr({{ (request.schemeAndHttpHost ~ request.basePath)|length }});
  286.                     }
  287.                     if (!path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
  288.                         var stackElement = {
  289.                             error: false,
  290.                             url: url,
  291.                             method: method,
  292.                             type: 'xhr',
  293.                             start: new Date()
  294.                         };
  295.                         var idx = requestStack.push(stackElement) - 1;
  296.                         this.addEventListener('readystatechange', function() {
  297.                             if (self.readyState == 4) {
  298.                                 stackElement.duration = new Date() - stackElement.start;
  299.                                 stackElement.error = self.status < 200 || self.status >= 400;
  300.                                 stackElement.statusCode = self.status;
  301.                                 extractHeaders(self, stackElement);
  302.                                 finishAjaxRequest(idx);
  303.                             }
  304.                         }, false);
  305.                         startAjaxRequest(idx);
  306.                     }
  307.                     proxied.apply(this, Array.prototype.slice.call(arguments));
  308.                 };
  309.             }
  310.         {% endif %}
  311.         return {
  312.             hasClass: hasClass,
  313.             removeClass: removeClass,
  314.             addClass: addClass,
  315.             toggleClass: toggleClass,
  316.             getPreference: getPreference,
  317.             setPreference: setPreference,
  318.             addEventListener: addEventListener,
  319.             request: request,
  320.             renderAjaxRequests: renderAjaxRequests,
  321.             load: function(selector, url, onSuccess, onError, options) {
  322.                 var el = document.getElementById(selector);
  323.                 if (el && el.getAttribute('data-sfurl') !== url) {
  324.                     request(
  325.                         url,
  326.                         function(xhr) {
  327.                             el.innerHTML = xhr.responseText;
  328.                             el.setAttribute('data-sfurl', url);
  329.                             removeClass(el, 'loading');
  330.                             var pending = pendingRequests;
  331.                             for (var i = 0; i < requestStack.length; i++) {
  332.                                 startAjaxRequest(i);
  333.                                 if (requestStack[i].duration) {
  334.                                     finishAjaxRequest(i);
  335.                                 }
  336.                             }
  337.                             /* Revert the pending state in case there was a start called without a finish above. */
  338.                             pendingRequests = pending;
  339.                             (onSuccess || noop)(xhr, el);
  340.                         },
  341.                         function(xhr) { (onError || noop)(xhr, el); },
  342.                         '',
  343.                         options
  344.                     );
  345.                 }
  346.                 return this;
  347.             },
  348.             loadToolbar: function(token, newToken) {
  349.                 newToken = (newToken || token);
  350.                 this.load(
  351.                     'sfwdt' + token,
  352.                     '{{ path("_wdt", { "token": "xxxxxx" }) }}'.replace(/xxxxxx/, newToken),
  353.                     function(xhr, el) {
  354.                         /* Evaluate in global scope scripts embedded inside the toolbar */
  355.                         var i, scripts = [].slice.call(el.querySelectorAll('script'));
  356.                         for (i = 0; i < scripts.length; ++i) {
  357.                             eval.call({}, scripts[i].firstChild.nodeValue);
  358.                         }
  359.                         el.style.display = -1 !== xhr.responseText.indexOf('sf-toolbarreset') ? 'block' : 'none';
  360.                         if (el.style.display == 'none') {
  361.                             return;
  362.                         }
  363.                         if (getPreference('toolbar/displayState') == 'none') {
  364.                             document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'none';
  365.                             document.getElementById('sfToolbarClearer-' + newToken).style.display = 'none';
  366.                             document.getElementById('sfMiniToolbar-' + newToken).style.display = 'block';
  367.                         } else {
  368.                             document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'block';
  369.                             document.getElementById('sfToolbarClearer-' + newToken).style.display = 'block';
  370.                             document.getElementById('sfMiniToolbar-' + newToken).style.display = 'none';
  371.                         }
  372.                         /* Handle toolbar-info position */
  373.                         var toolbarBlocks = [].slice.call(el.querySelectorAll('.sf-toolbar-block'));
  374.                         for (i = 0; i < toolbarBlocks.length; ++i) {
  375.                             toolbarBlocks[i].onmouseover = function () {
  376.                                 var toolbarInfo = this.querySelectorAll('.sf-toolbar-info')[0];
  377.                                 var pageWidth = document.body.clientWidth;
  378.                                 var elementWidth = toolbarInfo.offsetWidth;
  379.                                 var leftValue = (elementWidth + this.offsetLeft) - pageWidth;
  380.                                 var rightValue = (elementWidth + (pageWidth - this.offsetLeft)) - pageWidth;
  381.                                 /* Reset right and left value, useful on window resize */
  382.                                 toolbarInfo.style.right = '';
  383.                                 toolbarInfo.style.left = '';
  384.                                 if (elementWidth > pageWidth) {
  385.                                     toolbarInfo.style.left = 0;
  386.                                 }
  387.                                 else if (leftValue > 0 && rightValue > 0) {
  388.                                     toolbarInfo.style.right = (rightValue * -1) + 'px';
  389.                                 } else if (leftValue < 0) {
  390.                                     toolbarInfo.style.left = 0;
  391.                                 } else {
  392.                                     toolbarInfo.style.right = '0px';
  393.                                 }
  394.                             };
  395.                         }
  396.                         addEventListener(document.getElementById('sfToolbarHideButton-' + newToken), 'click', function (event) {
  397.                             event.preventDefault();
  398.                             var p = this.parentNode;
  399.                             p.style.display = 'none';
  400.                             (p.previousElementSibling || p.previousSibling).style.display = 'none';
  401.                             document.getElementById('sfMiniToolbar-' + newToken).style.display = 'block';
  402.                             setPreference('toolbar/displayState', 'none');
  403.                         });
  404.                         addEventListener(document.getElementById('sfToolbarMiniToggler-' + newToken), 'click', function (event) {
  405.                             event.preventDefault();
  406.                             var elem = this.parentNode;
  407.                             if (elem.style.display == 'none') {
  408.                                 document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'none';
  409.                                 document.getElementById('sfToolbarClearer-' + newToken).style.display = 'none';
  410.                                 elem.style.display = 'block';
  411.                             } else {
  412.                                 document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'block';
  413.                                 document.getElementById('sfToolbarClearer-' + newToken).style.display = 'block';
  414.                                 elem.style.display = 'none'
  415.                             }
  416.                             setPreference('toolbar/displayState', 'block');
  417.                         });
  418.                         renderAjaxRequests();
  419.                         addEventListener(document.querySelector('.sf-toolbar-block-ajax > .sf-toolbar-icon'), 'click', function (event) {
  420.                             event.preventDefault();
  421.                             toggleClass(this.parentNode, 'hover');
  422.                         });
  423.                         var dumpInfo = document.querySelector('.sf-toolbar-block-dump .sf-toolbar-info');
  424.                         if (null !== dumpInfo) {
  425.                             addEventListener(dumpInfo, 'sfbeforedumpcollapse', function () {
  426.                                 dumpInfo.style.minHeight = dumpInfo.getBoundingClientRect().height+'px';
  427.                             });
  428.                             addEventListener(dumpInfo, 'mouseleave', function () {
  429.                                 dumpInfo.style.minHeight = '';
  430.                             });
  431.                         }
  432.                     },
  433.                     function(xhr) {
  434.                         if (xhr.status !== 0) {
  435.                             var sfwdt = document.getElementById('sfwdt' + token);
  436.                             sfwdt.innerHTML = '\
  437.                                 <div class="sf-toolbarreset">\
  438.                                     <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>\
  439.                                     An error occurred while loading the web debug toolbar. <a href="{{ path("_profiler_home") }}' + newToken + '>Open the web profiler.</a>\
  440.                                 </div>\
  441.                             ';
  442.                             sfwdt.setAttribute('class', 'sf-toolbar sf-error-toolbar');
  443.                         }
  444.                     },
  445.                     { maxTries: 5 }
  446.                 );
  447.                 return this;
  448.             },
  449.             toggle: function(selector, elOn, elOff) {
  450.                 var tmp = elOn.style.display,
  451.                     el = document.getElementById(selector);
  452.                 elOn.style.display = elOff.style.display;
  453.                 elOff.style.display = tmp;
  454.                 if (el) {
  455.                     el.style.display = 'none' === tmp ? 'none' : 'block';
  456.                 }
  457.                 return this;
  458.             },
  459.             createTabs: function() {
  460.                 var tabGroups = document.querySelectorAll('.sf-tabs:not([data-processed=true])');
  461.                 /* create the tab navigation for each group of tabs */
  462.                 for (var i = 0; i < tabGroups.length; i++) {
  463.                     var tabs = tabGroups[i].querySelectorAll('.tab');
  464.                     var tabNavigation = document.createElement('ul');
  465.                     tabNavigation.className = 'tab-navigation';
  466.                     var selectedTabId = 'tab-' + i + '-0'; /* select the first tab by default */
  467.                     for (var j = 0; j < tabs.length; j++) {
  468.                         var tabId = 'tab-' + i + '-' + j;
  469.                         var tabTitle = tabs[j].querySelector('.tab-title').innerHTML;
  470.                         var tabNavigationItem = document.createElement('li');
  471.                         tabNavigationItem.setAttribute('data-tab-id', tabId);
  472.                         if (hasClass(tabs[j], 'active')) { selectedTabId = tabId; }
  473.                         if (hasClass(tabs[j], 'disabled')) { addClass(tabNavigationItem, 'disabled'); }
  474.                         tabNavigationItem.innerHTML = tabTitle;
  475.                         tabNavigation.appendChild(tabNavigationItem);
  476.                         var tabContent = tabs[j].querySelector('.tab-content');
  477.                         tabContent.parentElement.setAttribute('id', tabId);
  478.                     }
  479.                     tabGroups[i].insertBefore(tabNavigation, tabGroups[i].firstChild);
  480.                     addClass(document.querySelector('[data-tab-id="' + selectedTabId + '"]'), 'active');
  481.                 }
  482.                 /* display the active tab and add the 'click' event listeners */
  483.                 for (i = 0; i < tabGroups.length; i++) {
  484.                     tabNavigation = tabGroups[i].querySelectorAll('.tab-navigation li');
  485.                     for (j = 0; j < tabNavigation.length; j++) {
  486.                         tabId = tabNavigation[j].getAttribute('data-tab-id');
  487.                         document.getElementById(tabId).querySelector('.tab-title').className = 'hidden';
  488.                         if (hasClass(tabNavigation[j], 'active')) {
  489.                             document.getElementById(tabId).className = 'block';
  490.                         } else {
  491.                             document.getElementById(tabId).className = 'hidden';
  492.                         }
  493.                         tabNavigation[j].addEventListener('click', function(e) {
  494.                             var activeTab = e.target || e.srcElement;
  495.                             /* needed because when the tab contains HTML contents, user can click */
  496.                             /* on any of those elements instead of their parent '<li>' element */
  497.                             while (activeTab.tagName.toLowerCase() !== 'li') {
  498.                                 activeTab = activeTab.parentNode;
  499.                             }
  500.                             /* get the full list of tabs through the parent of the active tab element */
  501.                             var tabNavigation = activeTab.parentNode.children;
  502.                             for (var k = 0; k < tabNavigation.length; k++) {
  503.                                 var tabId = tabNavigation[k].getAttribute('data-tab-id');
  504.                                 document.getElementById(tabId).className = 'hidden';
  505.                                 removeClass(tabNavigation[k], 'active');
  506.                             }
  507.                             addClass(activeTab, 'active');
  508.                             var activeTabId = activeTab.getAttribute('data-tab-id');
  509.                             document.getElementById(activeTabId).className = 'block';
  510.                         });
  511.                     }
  512.                     tabGroups[i].setAttribute('data-processed', 'true');
  513.                 }
  514.             },
  515.             createToggles: function() {
  516.                 var toggles = document.querySelectorAll('.sf-toggle:not([data-processed=true])');
  517.                 for (var i = 0; i < toggles.length; i++) {
  518.                     var elementSelector = toggles[i].getAttribute('data-toggle-selector');
  519.                     var element = document.querySelector(elementSelector);
  520.                     addClass(element, 'sf-toggle-content');
  521.                     if (toggles[i].hasAttribute('data-toggle-initial') && toggles[i].getAttribute('data-toggle-initial') == 'display') {
  522.                         addClass(toggles[i], 'sf-toggle-on');
  523.                         addClass(element, 'sf-toggle-visible');
  524.                     } else {
  525.                         addClass(toggles[i], 'sf-toggle-off');
  526.                         addClass(element, 'sf-toggle-hidden');
  527.                     }
  528.                     addEventListener(toggles[i], 'click', function(e) {
  529.                         e.preventDefault();
  530.                         if ('' !== window.getSelection().toString()) {
  531.                             /* Don't do anything on text selection */
  532.                             return;
  533.                         }
  534.                         var toggle = e.target || e.srcElement;
  535.                         /* needed because when the toggle contains HTML contents, user can click */
  536.                         /* on any of those elements instead of their parent '.sf-toggle' element */
  537.                         while (!hasClass(toggle, 'sf-toggle')) {
  538.                             toggle = toggle.parentNode;
  539.                         }
  540.                         var element = document.querySelector(toggle.getAttribute('data-toggle-selector'));
  541.                         toggleClass(toggle, 'sf-toggle-on');
  542.                         toggleClass(toggle, 'sf-toggle-off');
  543.                         toggleClass(element, 'sf-toggle-hidden');
  544.                         toggleClass(element, 'sf-toggle-visible');
  545.                         /* the toggle doesn't change its contents when clicking on it */
  546.                         if (!toggle.hasAttribute('data-toggle-alt-content')) {
  547.                             return;
  548.                         }
  549.                         if (!toggle.hasAttribute('data-toggle-original-content')) {
  550.                             toggle.setAttribute('data-toggle-original-content', toggle.innerHTML);
  551.                         }
  552.                         var currentContent = toggle.innerHTML;
  553.                         var originalContent = toggle.getAttribute('data-toggle-original-content');
  554.                         var altContent = toggle.getAttribute('data-toggle-alt-content');
  555.                         toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
  556.                     });
  557.                     /* Prevents from disallowing clicks on links inside toggles */
  558.                     var toggleLinks = toggles[i].querySelectorAll('a');
  559.                     for (var j = 0; j < toggleLinks.length; j++) {
  560.                         addEventListener(toggleLinks[j], 'click', function(e) {
  561.                             e.stopPropagation();
  562.                         });
  563.                     }
  564.                     toggles[i].setAttribute('data-processed', 'true');
  565.                 }
  566.             }
  567.         };
  568.     })();
  569.     Sfjs.addEventListener(document, 'DOMContentLoaded', function() {
  570.         Sfjs.createTabs();
  571.         Sfjs.createToggles();
  572.     });
  573. /*]]>*/</script>