1/** 2 * RGPD.js 3 * Author: Tisserand David 4 * Freshcore 5 * Need JQuery 6 */ 7 8function RGPD(options) { 9 10 this.ergonomic = function() { 11 /* Put here the ergonomic scripts*/ 12 13 } 14 this.social = function() { 15 /* Put here the social scripts*/ 16 17 } 18 this.targeting = function() { 19 /* Put here the targeting scripts*/ 20 GoogleAnalytics('UA-90541045-1', (server != undefined ? server.host+'mentions-legales' : false)) 21 } 22 23 this.cookies = { 24 'mandatory': true, 25 'ergonomic': false, 26 'social': false, 27 'targeting': false 28 } 29 this.done = options.done || function() {}; 30 31 let rgpd = JSON.parse(this.getCookie('rgpd')); 32 /* Contrôle de l'existence du cookie principal */ 33 if (this.empty(rgpd) || this.empty(rgpd.validation)) { 34 /* Génération de la fenetre */ 35 $.ajax({ 36 method: 'POST', 37 url: server.host+'ajax/rgpd', 38 }).done(function(r){ 39 if (r && r.success) { 40 $('body').append(r.html); 41 } 42 $('[name^=rgpd_]').on('change', function() { 43 if($('[name^=rgpd_]:checked').length == $('[name^=rgpd_]:not(:checked)').length) { 44 $('.rgpd-save').attr('disabled', false); 45 } 46 }); 47 }).fail(function() { 48 console.log('Failed to get RGPD template'); 49 }); 50 51 } else { 52 this.launchScripts(); 53 } 54} 55 56 57RGPD.prototype.getCookie = function(cname) { 58 var name = cname + "="; 59 var decodedCookie = decodeURIComponent(document.cookie); 60 var ca = decodedCookie.split(';'); 61 for(var i = 0; i <ca.length; i++) { 62 var c = ca[i]; 63 while (c.charAt(0) == ' ') { 64 c = c.substring(1); 65 } 66 if (c.indexOf(name) == 0) { 67 return c.substring(name.length, c.length); 68 } 69 } 70 return false; 71} 72RGPD.prototype.setCookie = function(cname, cvalue, exdays) { 73 var d = new Date(); 74 d.setTime(d.getTime() + (exdays*24*60*60*1000)); 75 var expires = "expires="+ d.toUTCString(); 76 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 77} 78RGPD.prototype.delCookie = function(cname) { 79 document.cookie = cname + "=false;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/"; 80} 81RGPD.prototype.empty = function(data) { 82 if (typeof(data) == 'object') { 83 return !Object.keys(data).length 84 } else if (typeof(data) == 'string') { 85 return !data.trim().length 86 } else { 87 return !data; 88 } 89} 90RGPD.prototype.refuseAll = function() { 91 this.cookies = { 92 'mandatory': true, 93 'ergonomic': false, 94 'social': false, 95 'targeting': false 96 } 97 this.saveCookies(); 98} 99RGPD.prototype.acceptAll = function() { 100 this.cookies = { 101 'mandatory': true, 102 'ergonomic': true, 103 'social': true, 104 'targeting': true 105 } 106 this.saveCookies(); 107 this.launchScripts(); 108} 109RGPD.prototype.save = function() { 110 let cookies = this.cookies; 111 $('[name^=rgpd_]').each(function() { 112 if ($(this).prop('checked')) { 113 let cookie = $(this).attr('name').replace('rgpd_', ''); 114 let value = $(this).val()=="1" ? true : false; 115 cookies[cookie] = value; 116 } 117 }); 118 this.cookies = cookies; 119 this.saveCookies(); 120 this.launchScripts(); 121} 122RGPD.prototype.set = function() { 123 $('#rgpd-warning').hide(); 124 $('#rgpd-params').show(); 125} 126RGPD.prototype.saveCookies = function() { 127 this.cookies.validation = Date.now(); 128 this.setCookie('rgpd', JSON.stringify(this.cookies), 365); 129 this.done(); 130} 131RGPD.prototype.launchScripts = function() { 132 let cookies = JSON.parse(this.getCookie('rgpd')); 133 if (cookies.ergonomic) 134 this.ergonomic(); 135 if (cookies.social) 136 this.social(); 137 if (cookies.targeting) 138 this.targeting(); 139} 140 141/* Init */ 142let rgpd = new RGPD({ 143 /* Personalize this */ 144 done: function() { 145 $('#modalRGPD').modal('hide'); 146 } 147});
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.