1(function ($, Drupal, drupalSettings) { 2 3 'use strict'; 4 5 Drupal.behaviors.veoliaSiteHideBlocks = { 6 attach: function (context, settings) { 7 $(once('veoliaSiteHideBlocks', 'body', context)).ready(function () { 8 // Create the "didomiOnReady" listener 9 window.didomiOnReady = window.didomiOnReady || []; 10 window.didomiOnReady.push(function (Didomi) { 11 // get currentStatus for Twitter 12 let currentStatus = Didomi.getCurrentUserStatus(); 13 // pass the currentStatus to toggleTwitterBlock 14 toggleTwitterBlock(currentStatus.vendors['twitter'] && currentStatus.vendors['twitter'].enabled); 15 // Event Listner for Twitter. 16 Didomi.addVendorStatusListener('twitter', consentStatus => { 17 // Check if the "consentStatus" is true (eg. the user agreed to the vendor & his purposes) 18 toggleTwitterBlock(consentStatus.enabled); 19 }) 20 }); 21 }); 22 23 // Unset or add the script. 24 const toggleTwitterBlock = (consentStatus) => { 25 $('.container--social-timeline-widget.block-veolia-site-core-twitter-block').each(function(index, element) { 26 if (consentStatus === true) { 27 let scriptToLoad = 'https://platform.twitter.com/widgets.js'; 28 $(element).show(); 29 loadJavaScript(scriptToLoad); 30 } 31 if (consentStatus === false) { 32 let scriptToRemove = 'https://platform.twitter.com/'; 33 $(element).hide(); 34 unsetJavascript(scriptToRemove); 35 } 36 }); 37 }; 38 39 // Add the script. 40 const loadJavaScript = (url) => { 41 var script = document.createElement('script'); 42 script.src = url; 43 if (!($('script[src*="' + script.src + '"]').length)) { 44 $('head').append(script); 45 } 46 }; 47 48 // Unset the script. 49 const unsetJavascript = (url) => { 50 if ($('script[src*="' + url + '"]').length) { 51 $('script[src*="' + url + '"]').remove(); 52 } 53 }; 54 } 55 }; 56})(jQuery, Drupal, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.