/* @Author: Albert Soriano @Description: HTML parser in order to setup dinamically the correct structure of the new privacy policy page */ $(document).ready(function () { var exp_html; var dummy; var headings = [[]]; var h4 = new Object(); var h4s = []; var h4s_parents = []; var h4s_elements = []; fetchData(); /* @Description: Fetch data from the Google Doc exported using the script (j/gdoc-script.js) */ function fetchData() { var html; fetch('https://f.hubspotusercontent40.net/hubfs/4650993/Legal/Avast/html/UK/UK_COOKIES.html?q') .then(response => response.text()) .then((data) => { parseFetchedData(data); html = data; }) } /* @Description: Save data from the fetch and start data processing */ function parseFetchedData(data_html) { exp_html = data_html; processData(); } /* @Description: Data processing manager, all functions are listed here in order */ function processData() { dummyCreation(); getHeaders(); innerHeaders(); divideContent(); replaceIdentifiers(); generateAccordion(); toggleContent(); changeHTMLTag(); addOnetrust(); } /* @Description: Creating of a dummy element with the exported html in order to better process the data */ function dummyCreation() { dummy = $('
'); dummy.html(exp_html); } /* @Description: Parse of headings. Heading will be used as titles for the left navigation */ function getHeaders() { var x = 0; var y = 0; var auxtext; var parsed = false; $('h1', dummy).each(function (item) { headings[x] = []; auxtext = $(this).text(); headings[x].push($(this).text()); $(this).nextUntil('h1', 'h2').each(function () { headings[x][y] = []; if (!parsed) { parsed = true; headings[x][y] = auxtext; y++; headings[x][y] = []; } headings[x][y] = $(this).text(); y++; }) x++; y = 0; parsed = false; }) //H4s x = 0; y = 0; $('h2', dummy).each(function (item) { h4.parent = $(this).text(); h4.elements = []; $(this).nextUntil('h2').each(function () { if ($(this)[0].nodeName == 'H3') { h4.elements[x] = []; h4.elements[x] = $(this).text(); x++; } }) if (h4.elements[0]) { h4s_parents[y] = h4.parent; h4s_elements[y] = h4.elements; h4s[y] = h4; y++; } x = 0; }) } /* @Description: Append left navigation elements into the HTML code */ function innerHeaders() { var h_aux; var x = 0; var h3_id = 0; var h4_id = 0; var hasChild = false; var child = 0; $.each(headings, function () { if (headings[x].length > 1) { h_aux = '