1(function ($, Drupal) { 2 3 Drupal.GmAxeptio = {}; 4 5 /** 6 * 7 * @returns {GmAxeptio} 8 * @constructor 9 */ 10 let GmAxeptio = function () { 11 this.choices = {}; 12 13 return this; 14 }; 15 16 GmAxeptio.prototype = { 17 /** 18 * 19 * @param vendors 20 * @returns {GmAxeptio} 21 */ 22 setChoices: function (vendors) { 23 let self = this; 24 25 let $wrapper = $('html'); 26 27 $.each(vendors, function (vendor, values) { 28 if (vendor[0] !== '$') { 29 $wrapper.attr('data-choice--' + vendor, values); 30 self.choices[vendor.toLowerCase()] = values; 31 32 if (values === true) { 33 $('.axeptio-wrapper[data-choice="' + vendor + '"]').hide(); 34 } 35 } 36 }); 37 38 return this; 39 }, 40 /** 41 * 42 * @param vendor 43 * @returns {boolean} 44 */ 45 hasConsentTo: function (vendor) { 46 return this.choices[vendor.toLowerCase()] === true; 47 }, 48 49 /** 50 * 51 * @param vendor 52 * @returns {string} 53 */ 54 buildAxeptioCta: function (vendor) { 55 let $html = $('<button>', { 56 'class': 'btn btn--primary', 57 'type': 'button', 58 'data-choice': vendor, 59 'html': '<span>' + Drupal.t('Enable "@vendor" cookies to display the content', { '@vendor': vendor }) + '</span>', 60 }); 61 $html.on('click', function () { 62 window.axeptioSDK.requestConsent(vendor); 63 }); 64 65 let $wrapper = $('<div class="block--axeptio" data-choice="' + vendor + '"></div>').append($html); 66 67 return $wrapper; 68 }, 69 70 /** 71 * 72 * @param $wrapper 73 */ 74 removeAxeptioCta: function ($wrapper) { 75 $wrapper.find('.block--axeptio').remove(); 76 }, 77 78 /** 79 * 80 * @returns {*} 81 */ 82 getSettings: function () { 83 return window.axeptioSettings; 84 }, 85 86 /** 87 * 88 * @param action 89 * @param category 90 * @param label 91 */ 92 trackEvent: function (action, category, label, parameters) { 93 if (!this.isGtagAvailable()) { 94 console.error('gtag undefined'); 95 return; 96 } 97 98 let args = { 99 'event_category': category, 100 'event_label': label, 101 }; 102 $.extend(args, parameters); 103 104 gtag('event', action, args); 105 106 if (drupalSettings.env !== 'prod') { 107 console.debug('Gtag :: ' + JSON.stringify(args)); 108 } 109 }, 110 111 /** 112 * 113 * @param data 114 */ 115 dataLayerPush: function (data) { 116 window.dataLayer = window.dataLayer || []; 117 window.dataLayer.push(data); 118 119 if (drupalSettings.env !== 'prod') { 120 console.debug('DataLyer :: ' + JSON.stringify(data)); 121 } 122 }, 123 124 /** 125 * 126 * @returns {boolean} 127 */ 128 isGtagAvailable: function () { 129 return typeof gtag !== 'undefined'; 130 }, 131 }; 132 133 /** 134 * 135 * @see axeptio.js 136 * 137 * @type {{attach(*, *): void, choices: {}}} 138 */ 139 Drupal.behaviors.gmSiteAxeptio = { 140 /** 141 * 142 * @param context 143 * @param settings 144 */ 145 attach(context, settings) { 146 Drupal.GmAxeptio = new GmAxeptio(); 147 148 if (context.body === undefined) { 149 return; 150 } 151 152 window._axcb.push(function (axeptio) { 153 axeptio.on('cookies:complete', function (choices) { 154 Drupal.GmAxeptio.setChoices(choices); 155 156 // 157 if (Drupal.GmAxeptio.isGtagAvailable()) { 158 if (Drupal.GmAxeptio.getSettings().googleConsentMode.default !== undefined) { 159 gtag('consent', 'default', window.axeptioSettings.googleConsentMode.default); 160 } 161 162 if (Drupal.GmAxeptio.hasConsentTo('google_analytics')) { 163 // gtag('send', 'pageview'); 164 } 165 } 166 }); 167 }); 168 }, 169 170 }; 171})(jQuery, Drupal);
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.