tarteaucitron.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. /*jslint browser: true, evil: true */
  2. // define correct path for files inclusion
  3. var scripts = document.getElementsByTagName('script'),
  4. path = scripts[scripts.length - 1].src.split('?')[0],
  5. cdn = path.split('/').slice(0, -1).join('/') + '/',
  6. alreadyLaunch = (alreadyLaunch === undefined) ? 0 : alreadyLaunch,
  7. tarteaucitronForceLanguage = (tarteaucitronForceLanguage === undefined) ? '' : tarteaucitronForceLanguage,
  8. tarteaucitronProLoadServices,
  9. tarteaucitronNoAdBlocker = false;
  10. var tarteaucitron = {
  11. "version": 201.3,
  12. "cdn": cdn,
  13. "user": {},
  14. "lang": {},
  15. "services": {},
  16. "added": [],
  17. "idprocessed": [],
  18. "state": [],
  19. "launch": [],
  20. "parameters": {},
  21. "isAjax": false,
  22. "reloadThePage": false,
  23. "init": function (params) {
  24. "use strict";
  25. var origOpen;
  26. tarteaucitron.parameters = params;
  27. if (alreadyLaunch === 0) {
  28. alreadyLaunch = 1;
  29. if (window.addEventListener) {
  30. window.addEventListener("load", function () {
  31. tarteaucitron.load();
  32. }, false);
  33. window.addEventListener("keydown", function (evt) {
  34. if (evt.keyCode === 27) {
  35. tarteaucitron.userInterface.closePanel();
  36. }
  37. }, false);
  38. window.addEventListener("hashchange", function () {
  39. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  40. tarteaucitron.userInterface.openPanel();
  41. }
  42. }, false);
  43. window.addEventListener("resize", function () {
  44. if (document.getElementById('tarteaucitron').style.display === 'block') {
  45. tarteaucitron.userInterface.jsSizing('main');
  46. } else if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
  47. tarteaucitron.userInterface.jsSizing('cookie');
  48. }
  49. }, false);
  50. } else {
  51. window.attachEvent("onload", function () {
  52. tarteaucitron.load();
  53. });
  54. window.attachEvent("onkeydown", function (evt) {
  55. if (evt.keyCode === 27) {
  56. tarteaucitron.userInterface.closePanel();
  57. }
  58. });
  59. window.attachEvent("onhashchange", function () {
  60. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  61. tarteaucitron.userInterface.openPanel();
  62. }
  63. });
  64. window.attachEvent("onresize", function () {
  65. if (document.getElementById('tarteaucitron').style.display === 'block') {
  66. tarteaucitron.userInterface.jsSizing('main');
  67. } else if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
  68. tarteaucitron.userInterface.jsSizing('cookie');
  69. }
  70. });
  71. }
  72. if (typeof XMLHttpRequest !== 'undefined') {
  73. origOpen = XMLHttpRequest.prototype.open;
  74. XMLHttpRequest.prototype.open = function () {
  75. if (window.addEventListener) {
  76. this.addEventListener("load", function () {
  77. if (typeof tarteaucitronProLoadServices === 'function') {
  78. tarteaucitronProLoadServices();
  79. }
  80. }, false);
  81. } else if (typeof this.attachEvent !== 'undefined') {
  82. this.attachEvent("onload", function () {
  83. if (typeof tarteaucitronProLoadServices === 'function') {
  84. tarteaucitronProLoadServices();
  85. }
  86. });
  87. } else {
  88. if (typeof tarteaucitronProLoadServices === 'function') {
  89. setTimeout(tarteaucitronProLoadServices, 1000);
  90. }
  91. }
  92. try {
  93. origOpen.apply(this, arguments);
  94. } catch (err) {}
  95. };
  96. }
  97. }
  98. },
  99. "load": function () {
  100. "use strict";
  101. var cdn = tarteaucitron.cdn,
  102. language = tarteaucitron.getLanguage(),
  103. pathToLang = cdn + 'lang/tarteaucitron.' + language + '.js?v=' + tarteaucitron.version,
  104. pathToServices = cdn + 'tarteaucitron.services.js?v=' + tarteaucitron.version,
  105. linkElement = document.createElement('link'),
  106. defaults = {
  107. "adblocker": false,
  108. "hashtag": '#tarteaucitron',
  109. "highPrivacy": false,
  110. "orientation": "top",
  111. "removeCredit": false,
  112. "showAlertSmall": true,
  113. "cookieslist": true
  114. },
  115. params = tarteaucitron.parameters;
  116. // Step 0: get params
  117. if (params !== undefined) {
  118. tarteaucitron.extend(defaults, params);
  119. }
  120. // global
  121. tarteaucitron.hashtag = defaults.hashtag;
  122. tarteaucitron.highPrivacy = defaults.highPrivacy;
  123. // Step 1: load css
  124. linkElement.rel = 'stylesheet';
  125. linkElement.type = 'text/css';
  126. linkElement.href = cdn + 'css/tarteaucitron.css?v=' + tarteaucitron.version;
  127. document.getElementsByTagName('head')[0].appendChild(linkElement);
  128. // Step 2: load language and services
  129. tarteaucitron.addScript(pathToLang, '', function () {
  130. tarteaucitron.addScript(pathToServices, '', function () {
  131. var body = document.body,
  132. div = document.createElement('div'),
  133. html = '',
  134. index,
  135. orientation = 'Top',
  136. cat = ['ads', 'analytic', 'api', 'comment', 'social', 'support', 'video'],
  137. i;
  138. cat = cat.sort(function (a, b) {
  139. if (tarteaucitron.lang[a].title > tarteaucitron.lang[b].title) { return 1; }
  140. if (tarteaucitron.lang[a].title < tarteaucitron.lang[b].title) { return -1; }
  141. return 0;
  142. });
  143. // Step 3: prepare the html
  144. html += '<div id="tarteaucitronPremium"></div>';
  145. html += '<div id="tarteaucitronBack" onclick="tarteaucitron.userInterface.closePanel();"></div>';
  146. html += '<div id="tarteaucitron">';
  147. html += ' <div id="tarteaucitronClosePanel" onclick="tarteaucitron.userInterface.closePanel();">';
  148. html += ' ' + tarteaucitron.lang.close;
  149. html += ' </div>';
  150. html += ' <div id="tarteaucitronServices">';
  151. html += ' <div class="tarteaucitronLine tarteaucitronMainLine" id="tarteaucitronMainLineOffset">';
  152. html += ' <div class="tarteaucitronName">';
  153. html += ' <b><a href="#" onclick="tarteaucitron.userInterface.toggle(\'tarteaucitronInfo\', \'tarteaucitronInfoBox\');return false">&#10798;</a> ' + tarteaucitron.lang.all + '</b>';
  154. html += ' </div>';
  155. html += ' <div class="tarteaucitronAsk" id="tarteaucitronScrollbarAdjust">';
  156. html += ' <div id="tarteaucitronAllAllowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respondAll(true);">';
  157. html += ' &#10004; ' + tarteaucitron.lang.allow;
  158. html += ' </div> ';
  159. html += ' <div id="tarteaucitronAllDenied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respondAll(false);">';
  160. html += ' &#10007; ' + tarteaucitron.lang.deny;
  161. html += ' </div>';
  162. html += ' </div>';
  163. html += ' </div>';
  164. html += ' <div id="tarteaucitronInfo" class="tarteaucitronInfoBox">';
  165. html += ' ' + tarteaucitron.lang.disclaimer;
  166. if (defaults.removeCredit === false) {
  167. html += ' <br/><br/>';
  168. html += ' <a href="https://opt-out.ferank.eu/" rel="nofollow" target="_blank">' + tarteaucitron.lang.credit + '</a>';
  169. }
  170. html += ' </div>';
  171. html += ' <div class="tarteaucitronBorder" id="tarteaucitronScrollbarParent">';
  172. html += ' <div class="clear"></div>';
  173. for (i = 0; i < cat.length; i += 1) {
  174. html += ' <div id="tarteaucitronServicesTitle_' + cat[i] + '" class="tarteaucitronHidden">';
  175. html += ' <div class="tarteaucitronTitle">';
  176. html += ' <a href="#" onclick="tarteaucitron.userInterface.toggle(\'tarteaucitronDetails' + cat[i] + '\', \'tarteaucitronInfoBox\');return false">&#10798;</a> ' + tarteaucitron.lang[cat[i]].title;
  177. html += ' </div>';
  178. html += ' <div id="tarteaucitronDetails' + cat[i] + '" class="tarteaucitronDetails tarteaucitronInfoBox">';
  179. html += ' ' + tarteaucitron.lang[cat[i]].details;
  180. html += ' </div>';
  181. html += ' </div>';
  182. html += ' <div id="tarteaucitronServices_' + cat[i] + '"></div>';
  183. }
  184. html += ' <div class="tarteaucitronHidden" id="tarteaucitronScrollbarChild" style="height:20px;display:block"></div>';
  185. html += ' </div>';
  186. html += ' </div>';
  187. html += '</div>';
  188. if (defaults.orientation === 'bottom') {
  189. orientation = 'Bottom';
  190. }
  191. if (defaults.highPrivacy) {
  192. html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
  193. html += ' <span id="tarteaucitronDisclaimerAlert">';
  194. html += ' ' + tarteaucitron.lang.alertBigPrivacy;
  195. html += ' </span>';
  196. html += ' <span id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.openPanel();">';
  197. html += ' ' + tarteaucitron.lang.personalize;
  198. html += ' </span>';
  199. html += '</div>';
  200. } else {
  201. html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
  202. html += ' <span id="tarteaucitronDisclaimerAlert">';
  203. html += ' ' + tarteaucitron.lang.alertBig;
  204. html += ' </span>';
  205. html += ' <span id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.respondAll(true);">';
  206. html += ' &#10004; ' + tarteaucitron.lang.acceptAll;
  207. html += ' </span>';
  208. html += ' <span id="tarteaucitronCloseAlert" onclick="tarteaucitron.userInterface.openPanel();">';
  209. html += ' ' + tarteaucitron.lang.personalize;
  210. html += ' </span>';
  211. html += '</div>';
  212. }
  213. if (defaults.showAlertSmall === true) {
  214. html += '<div id="tarteaucitronAlertSmall">';
  215. html += ' <div id="tarteaucitronManager" onclick="tarteaucitron.userInterface.openPanel();">';
  216. html += ' ' + tarteaucitron.lang.alertSmall;
  217. html += ' <div id="tarteaucitronDot">';
  218. html += ' <span id="tarteaucitronDotGreen"></span>';
  219. html += ' <span id="tarteaucitronDotYellow"></span>';
  220. html += ' <span id="tarteaucitronDotRed"></span>';
  221. html += ' </div>';
  222. if (defaults.cookieslist === true) {
  223. html += ' </div><!-- @whitespace';
  224. html += ' --><div id="tarteaucitronCookiesNumber" onclick="tarteaucitron.userInterface.toggleCookiesList();">';
  225. html += ' 0';
  226. html += ' </div>';
  227. html += ' <div id="tarteaucitronCookiesListContainer">';
  228. html += ' <div id="tarteaucitronClosePanelCookie" onclick="tarteaucitron.userInterface.closePanel();">';
  229. html += ' ' + tarteaucitron.lang.close;
  230. html += ' </div>';
  231. html += ' <div class="tarteaucitronCookiesListMain" id="tarteaucitronCookiesTitle">';
  232. html += ' <b id="tarteaucitronCookiesNumberBis">0 cookie</b>';
  233. html += ' </div>';
  234. html += ' <div id="tarteaucitronCookiesList"></div>';
  235. html += ' </div>';
  236. } else {
  237. html += ' </div>';
  238. }
  239. html += '</div>';
  240. }
  241. tarteaucitron.addScript(tarteaucitron.cdn + 'advertising.js?v=' + tarteaucitron.version, '', function () {
  242. if (tarteaucitronNoAdBlocker === true || defaults.adblocker === false) {
  243. div.id = 'tarteaucitronRoot';
  244. body.appendChild(div, body);
  245. div.innerHTML = html;
  246. if (tarteaucitron.job !== undefined) {
  247. tarteaucitron.job = tarteaucitron.cleanArray(tarteaucitron.job);
  248. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  249. tarteaucitron.addService(tarteaucitron.job[index]);
  250. }
  251. }
  252. tarteaucitron.isAjax = true;
  253. tarteaucitron.job.push = function (id) {
  254. // ie <9 hack
  255. if (typeof tarteaucitron.job.indexOf === 'undefined') {
  256. tarteaucitron.job.indexOf = function (obj, start) {
  257. var i,
  258. j = this.length;
  259. for (i = (start || 0); i < j; i += 1) {
  260. if (this[i] === obj) { return i; }
  261. }
  262. return -1;
  263. };
  264. }
  265. if (tarteaucitron.job.indexOf(id) === -1) {
  266. Array.prototype.push.call(this, id);
  267. }
  268. tarteaucitron.launch[id] = false;
  269. tarteaucitron.addService(id);
  270. };
  271. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  272. tarteaucitron.userInterface.openPanel();
  273. }
  274. tarteaucitron.cookie.number();
  275. setInterval(tarteaucitron.cookie.number, 60000);
  276. }
  277. }, defaults.adblocker);
  278. if (defaults.adblocker === true) {
  279. setTimeout(function () {
  280. if (tarteaucitronNoAdBlocker === false) {
  281. html = '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '" style="display:block">';
  282. html += ' <span id="tarteaucitronDisclaimerAlert">';
  283. html += ' ' + tarteaucitron.lang.adblock + '<br/>';
  284. html += ' <b>' + tarteaucitron.lang.adblock_call + '</b>';
  285. html += ' </span>';
  286. html += ' <span id="tarteaucitronPersonalize" onclick="location.reload();">';
  287. html += ' ' + tarteaucitron.lang.reload;
  288. html += ' </span>';
  289. html += '</div>';
  290. html += '<div id="tarteaucitronPremium"></div>';
  291. div.id = 'tarteaucitronRoot';
  292. body.appendChild(div, body);
  293. div.innerHTML = html;
  294. tarteaucitron.pro('!adblocker=true');
  295. } else {
  296. tarteaucitron.pro('!adblocker=false');
  297. }
  298. }, 1500);
  299. }
  300. });
  301. });
  302. },
  303. "addService": function (serviceId) {
  304. "use strict";
  305. var html = '',
  306. s = tarteaucitron.services,
  307. service = s[serviceId],
  308. cookie = tarteaucitron.cookie.read(),
  309. hostname = document.location.hostname,
  310. hostRef = document.referrer.split('/')[2],
  311. isNavigating = (hostRef === hostname) ? true : false,
  312. isAutostart = (!service.needConsent) ? true : false,
  313. isWaiting = (cookie.indexOf(service.key + '=wait') >= 0) ? true : false,
  314. isDenied = (cookie.indexOf(service.key + '=false') >= 0) ? true : false,
  315. isAllowed = (cookie.indexOf(service.key + '=true') >= 0) ? true : false,
  316. isResponded = (cookie.indexOf(service.key + '=false') >= 0 || cookie.indexOf(service.key + '=true') >= 0) ? true : false;
  317. if (tarteaucitron.added[service.key] !== true) {
  318. tarteaucitron.added[service.key] = true;
  319. html += '<div id="' + service.key + 'Line" class="tarteaucitronLine">';
  320. html += ' <div class="tarteaucitronName">';
  321. html += ' <b>' + service.name + '</b><br/>';
  322. html += ' <span id="tacCL' + service.key + '" class="tarteaucitronListCookies"></span><br/>';
  323. html += ' <a href="https://opt-out.ferank.eu/service/' + service.key + '/" target="_blank">';
  324. html += ' ' + tarteaucitron.lang.more;
  325. html += ' </a>';
  326. html += ' - ';
  327. html += ' <a href="' + service.uri + '" target="_blank">';
  328. html += ' ' + tarteaucitron.lang.source;
  329. html += ' </a>';
  330. html += ' </div>';
  331. html += ' <div class="tarteaucitronAsk">';
  332. html += ' <div id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  333. html += ' &#10004; ' + tarteaucitron.lang.allow;
  334. html += ' </div> ';
  335. html += ' <div id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  336. html += ' &#10007; ' + tarteaucitron.lang.deny;
  337. html += ' </div>';
  338. html += ' </div>';
  339. html += '</div>';
  340. tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
  341. if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
  342. document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
  343. }
  344. tarteaucitron.userInterface.order(service.type);
  345. }
  346. // allow by default for non EU
  347. if (isResponded === false && tarteaucitron.user.bypass === true) {
  348. isAllowed = true;
  349. tarteaucitron.cookie.create(service.key, true);
  350. }
  351. if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
  352. if (!isAllowed) {
  353. tarteaucitron.cookie.create(service.key, true);
  354. }
  355. if (tarteaucitron.launch[service.key] !== true) {
  356. tarteaucitron.launch[service.key] = true;
  357. service.js();
  358. }
  359. tarteaucitron.state[service.key] = true;
  360. tarteaucitron.userInterface.color(service.key, true);
  361. } else if (isDenied) {
  362. if (typeof service.fallback === 'function') {
  363. service.fallback();
  364. }
  365. tarteaucitron.state[service.key] = false;
  366. tarteaucitron.userInterface.color(service.key, false);
  367. } else if (!isResponded) {
  368. tarteaucitron.cookie.create(service.key, 'wait');
  369. if (typeof service.fallback === 'function') {
  370. service.fallback();
  371. }
  372. tarteaucitron.userInterface.color(service.key, 'wait');
  373. tarteaucitron.userInterface.openAlert();
  374. }
  375. tarteaucitron.cookie.checkCount(service.key);
  376. },
  377. "cleanArray": function cleanArray(arr) {
  378. "use strict";
  379. var i,
  380. len = arr.length,
  381. out = [],
  382. obj = {},
  383. s = tarteaucitron.services;
  384. for (i = 0; i < len; i += 1) {
  385. if (!obj[arr[i]]) {
  386. obj[arr[i]] = {};
  387. if (tarteaucitron.services[arr[i]] !== undefined) {
  388. out.push(arr[i]);
  389. }
  390. }
  391. }
  392. out = out.sort(function (a, b) {
  393. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  394. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  395. return 0;
  396. });
  397. return out;
  398. },
  399. "userInterface": {
  400. "css": function (id, property, value) {
  401. "use strict";
  402. if (document.getElementById(id) !== null) {
  403. document.getElementById(id).style[property] = value;
  404. }
  405. },
  406. "respondAll": function (status) {
  407. "use strict";
  408. var s = tarteaucitron.services,
  409. service,
  410. key,
  411. index = 0;
  412. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  413. service = s[tarteaucitron.job[index]];
  414. key = service.key;
  415. if (tarteaucitron.state[key] !== status) {
  416. if (status === false && tarteaucitron.launch[key] === true) {
  417. tarteaucitron.reloadThePage = true;
  418. }
  419. if (tarteaucitron.launch[key] !== true && status === true) {
  420. tarteaucitron.launch[key] = true;
  421. tarteaucitron.services[key].js();
  422. }
  423. tarteaucitron.state[key] = status;
  424. tarteaucitron.cookie.create(key, status);
  425. tarteaucitron.userInterface.color(key, status);
  426. }
  427. }
  428. },
  429. "respond": function (el, status) {
  430. "use strict";
  431. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  432. // return if same state
  433. if (tarteaucitron.state[key] === status) {
  434. return;
  435. }
  436. if (status === false && tarteaucitron.launch[key] === true) {
  437. tarteaucitron.reloadThePage = true;
  438. }
  439. // if not already launched... launch the service
  440. if (status === true) {
  441. if (tarteaucitron.launch[key] !== true) {
  442. tarteaucitron.launch[key] = true;
  443. tarteaucitron.services[key].js();
  444. }
  445. }
  446. tarteaucitron.state[key] = status;
  447. tarteaucitron.cookie.create(key, status);
  448. tarteaucitron.userInterface.color(key, status);
  449. },
  450. "color": function (key, status) {
  451. "use strict";
  452. var gray = '#808080',
  453. greenDark = '#1B870B',
  454. greenLight = '#E6FFE2',
  455. redDark = '#9C1A1A',
  456. redLight = '#FFE2E2',
  457. yellowDark = '#FBDA26',
  458. c = 'tarteaucitron',
  459. nbDenied = 0,
  460. nbPending = 0,
  461. nbAllowed = 0,
  462. sum = tarteaucitron.job.length,
  463. index;
  464. if (status === true) {
  465. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  466. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  467. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  468. } else if (status === false) {
  469. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  470. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  471. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  472. }
  473. // check if all services are allowed
  474. for (index = 0; index < sum; index += 1) {
  475. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  476. nbDenied += 1;
  477. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  478. nbPending += 1;
  479. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  480. nbAllowed += 1;
  481. }
  482. }
  483. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  484. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  485. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  486. if (nbDenied === 0 && nbPending === 0) {
  487. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  488. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  489. } else if (nbAllowed === 0 && nbPending === 0) {
  490. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  491. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  492. } else {
  493. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  494. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  495. }
  496. // close the alert if all service have been reviewed
  497. if (nbPending === 0) {
  498. tarteaucitron.userInterface.closeAlert();
  499. }
  500. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  501. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  502. }
  503. if (status === true) {
  504. if (document.getElementById('tacCL' + key) !== null) {
  505. document.getElementById('tacCL' + key).innerHTML = '...';
  506. }
  507. setTimeout(function () {
  508. tarteaucitron.cookie.checkCount(key);
  509. }, 2500);
  510. } else {
  511. tarteaucitron.cookie.checkCount(key);
  512. }
  513. },
  514. "openPanel": function () {
  515. "use strict";
  516. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  517. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  518. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  519. tarteaucitron.userInterface.jsSizing('main');
  520. },
  521. "closePanel": function () {
  522. "use strict";
  523. if (document.location.hash === tarteaucitron.hashtag) {
  524. document.location.hash = '';
  525. }
  526. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  527. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  528. if (tarteaucitron.reloadThePage === true) {
  529. window.location.reload();
  530. } else {
  531. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  532. }
  533. },
  534. "openAlert": function () {
  535. "use strict";
  536. var c = 'tarteaucitron';
  537. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  538. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  539. },
  540. "closeAlert": function () {
  541. "use strict";
  542. var c = 'tarteaucitron';
  543. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  544. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  545. },
  546. "toggleCookiesList": function () {
  547. "use strict";
  548. var div = document.getElementById('tarteaucitronCookiesListContainer');
  549. if (div === null) {
  550. return;
  551. }
  552. if (div.style.display !== 'block') {
  553. tarteaucitron.cookie.number();
  554. div.style.display = 'block';
  555. tarteaucitron.userInterface.jsSizing('cookie');
  556. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  557. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  558. } else {
  559. div.style.display = 'none';
  560. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  561. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  562. }
  563. },
  564. "toggle": function (id, closeClass) {
  565. "use strict";
  566. var div = document.getElementById(id);
  567. if (div === null) {
  568. return;
  569. }
  570. if (closeClass !== undefined) {
  571. tarteaucitron.fallback([closeClass], function (elem) {
  572. if (elem.id !== id) {
  573. elem.style.display = 'none';
  574. }
  575. }, true);
  576. }
  577. if (div.style.display !== 'block') {
  578. div.style.display = 'block';
  579. } else {
  580. div.style.display = 'none';
  581. }
  582. },
  583. "order": function (id) {
  584. "use strict";
  585. var main = document.getElementById('tarteaucitronServices_' + id),
  586. allDivs = main.childNodes,
  587. store = [],
  588. i;
  589. if (main === null) {
  590. return;
  591. }
  592. if (typeof Array.prototype.map === 'function') {
  593. Array.prototype.map.call(main.children, Object).sort(function (a, b) {
  594. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
  595. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; }
  596. return 0;
  597. }).forEach(function (element) {
  598. main.appendChild(element);
  599. });
  600. }
  601. },
  602. "jsSizing": function (type) {
  603. "use strict";
  604. var start = 10,
  605. parent,
  606. child,
  607. e = window,
  608. a = 'inner';
  609. if (type === 'main') {
  610. // height services list container
  611. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', 'auto');
  612. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', (document.getElementById('tarteaucitron').offsetHeight - document.getElementById('tarteaucitronClosePanel').offsetHeight - document.getElementById('tarteaucitronMainLineOffset').offsetHeight + 1) + 'px');
  613. if (window.innerWidth === undefined) {
  614. a = 'client';
  615. e = document.documentElement || document.body;
  616. }
  617. if (e[a + 'Width'] <= 767) {
  618. start = 12;
  619. }
  620. // indent the global allow/deny buttons
  621. parent = document.getElementById('tarteaucitronScrollbarParent').offsetWidth;
  622. child = document.getElementById('tarteaucitronScrollbarChild').offsetWidth;
  623. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((parent - child) + start) + 'px');
  624. if (e[a + 'Width'] <= 479) {
  625. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px');
  626. }
  627. } else if (type === 'cookie') {
  628. // height cookies list container
  629. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (parseInt(document.getElementById('tarteaucitronAlertSmall').offsetHeight, 10) + 10) + 'px');
  630. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto');
  631. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (document.getElementById('tarteaucitronCookiesListContainer').offsetHeight - document.getElementById('tarteaucitronClosePanelCookie').offsetHeight - document.getElementById('tarteaucitronCookiesTitle').offsetHeight - 2) + 'px');
  632. }
  633. }
  634. },
  635. "cookie": {
  636. "owner": {},
  637. "create": function (key, status) {
  638. "use strict";
  639. var d = new Date(),
  640. time = d.getTime(),
  641. expireTime = time + 31536000000, // 365 days
  642. regex = new RegExp("!" + key + "=(wait|true|false)", "g"),
  643. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  644. value = 'tarteaucitron=' + cookie + '!' + key + '=' + status;
  645. if (tarteaucitron.cookie.read().indexOf(key + '=' + status) === -1) {
  646. tarteaucitron.pro('!' + key + '=' + status);
  647. }
  648. d.setTime(expireTime);
  649. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;';
  650. },
  651. "read": function () {
  652. "use strict";
  653. var nameEQ = "tarteaucitron=",
  654. ca = document.cookie.split(';'),
  655. i,
  656. c;
  657. for (i = 0; i < ca.length; i += 1) {
  658. c = ca[i];
  659. while (c.charAt(0) === ' ') {
  660. c = c.substring(1, c.length);
  661. }
  662. if (c.indexOf(nameEQ) === 0) {
  663. return c.substring(nameEQ.length, c.length);
  664. }
  665. }
  666. return '';
  667. },
  668. "purge": function (arr) {
  669. "use strict";
  670. var i;
  671. for (i = 0; i < arr.length; i += 1) {
  672. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  673. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  674. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  675. }
  676. },
  677. "checkCount": function (key) {
  678. "use strict";
  679. var arr = tarteaucitron.services[key].cookies,
  680. nb = arr.length,
  681. nbCurrent = 0,
  682. html = '',
  683. i,
  684. status = document.cookie.indexOf(key + '=true');
  685. if (status >= 0 && nb === 0) {
  686. html += tarteaucitron.lang.useNoCookie;
  687. } else if (status >= 0) {
  688. for (i = 0; i < nb; i += 1) {
  689. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  690. nbCurrent += 1;
  691. if (tarteaucitron.cookie.owner[arr[i]] === undefined) {
  692. tarteaucitron.cookie.owner[arr[i]] = [];
  693. }
  694. if (tarteaucitron.cookie.crossIndexOf(tarteaucitron.cookie.owner[arr[i]], tarteaucitron.services[key].name) === false) {
  695. tarteaucitron.cookie.owner[arr[i]].push(tarteaucitron.services[key].name);
  696. }
  697. }
  698. }
  699. if (nbCurrent > 0) {
  700. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  701. if (nbCurrent > 1) {
  702. html += 's';
  703. }
  704. html += '.';
  705. } else {
  706. html += tarteaucitron.lang.useNoCookie;
  707. }
  708. } else if (nb === 0) {
  709. html = tarteaucitron.lang.noCookie;
  710. } else {
  711. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  712. if (nb > 1) {
  713. html += 's';
  714. }
  715. html += '.';
  716. }
  717. if (document.getElementById('tacCL' + key) !== null) {
  718. document.getElementById('tacCL' + key).innerHTML = html;
  719. }
  720. },
  721. "crossIndexOf": function (arr, match) {
  722. "use strict";
  723. var i;
  724. for (i = 0; i < arr.length; i += 1) {
  725. if (arr[i] === match) {
  726. return true;
  727. }
  728. }
  729. return false;
  730. },
  731. "number": function () {
  732. "use strict";
  733. var cookies = document.cookie.split(';'),
  734. nb = (document.cookie !== '') ? cookies.length : 0,
  735. html = '',
  736. i,
  737. name,
  738. namea,
  739. nameb,
  740. c,
  741. d,
  742. s = (nb > 1) ? 's' : '',
  743. savedname,
  744. host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : tarteaucitron.cdn;
  745. cookies = cookies.sort(function (a, b) {
  746. namea = a.split('=', 1).toString().replace(/ /g, '');
  747. nameb = b.split('=', 1).toString().replace(/ /g, '');
  748. c = (tarteaucitron.cookie.owner[namea] !== undefined) ? tarteaucitron.cookie.owner[namea] : '0';
  749. d = (tarteaucitron.cookie.owner[nameb] !== undefined) ? tarteaucitron.cookie.owner[nameb] : '0';
  750. if (c + a > d + b) { return 1; }
  751. if (c + a < d + b) { return -1; }
  752. return 0;
  753. });
  754. if (document.cookie !== '') {
  755. for (i = 0; i < nb; i += 1) {
  756. name = cookies[i].split('=', 1).toString().replace(/ /g, '');
  757. if (tarteaucitron.cookie.owner[name] !== undefined && tarteaucitron.cookie.owner[name].join(' // ') !== savedname) {
  758. savedname = tarteaucitron.cookie.owner[name].join(' // ');
  759. html += '<div class="tarteaucitronHidden">';
  760. html += ' <div class="tarteaucitronTitle">';
  761. html += ' ' + tarteaucitron.cookie.owner[name].join(' // ');
  762. html += ' </div>';
  763. html += '</div>';
  764. } else if (tarteaucitron.cookie.owner[name] === undefined && host !== savedname) {
  765. savedname = host;
  766. html += '<div class="tarteaucitronHidden">';
  767. html += ' <div class="tarteaucitronTitle">';
  768. html += ' ' + host;
  769. html += ' </div>';
  770. html += '</div>';
  771. }
  772. html += '<div class="tarteaucitronCookiesListMain">';
  773. html += ' <div class="tarteaucitronCookiesListLeft"><a href="#" onclick="tarteaucitron.cookie.purge([\'' + cookies[i].split('=', 1) + '\']);tarteaucitron.cookie.number();tarteaucitron.userInterface.jsSizing(\'cookie\');return false"><b>&times;</b></a> <b>' + name + '</b>';
  774. html += ' </div>';
  775. html += ' <div class="tarteaucitronCookiesListRight">' + cookies[i].split('=').slice(1).join('=') + '</div>';
  776. html += '</div>';
  777. }
  778. } else {
  779. html += '<div class="tarteaucitronCookiesListMain">';
  780. html += ' <div class="tarteaucitronCookiesListLeft"><b>-</b></div>';
  781. html += ' <div class="tarteaucitronCookiesListRight"></div>';
  782. html += '</div>';
  783. }
  784. html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
  785. if (document.getElementById('tarteaucitronCookiesList') !== null) {
  786. document.getElementById('tarteaucitronCookiesList').innerHTML = html;
  787. }
  788. if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
  789. document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
  790. }
  791. if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) {
  792. document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
  793. }
  794. }
  795. },
  796. "getLanguage": function () {
  797. "use strict";
  798. if (!navigator) { return 'en'; }
  799. var availableLanguages = 'en,fr,es,it,de,pt,pl',
  800. defaultLanguage = 'en',
  801. lang = navigator.language || navigator.browserLanguage ||
  802. navigator.systemLanguage || navigator.userLang || null,
  803. userLanguage = lang.substr(0, 2);
  804. if (tarteaucitronForceLanguage !== '') {
  805. if (availableLanguages.indexOf(tarteaucitronForceLanguage) !== -1) {
  806. return tarteaucitronForceLanguage;
  807. }
  808. }
  809. if (availableLanguages.indexOf(userLanguage) === -1) {
  810. return defaultLanguage;
  811. }
  812. return userLanguage;
  813. },
  814. "getLocale": function () {
  815. "use strict";
  816. if (!navigator) { return 'en_US'; }
  817. var lang = navigator.language || navigator.browserLanguage ||
  818. navigator.systemLanguage || navigator.userLang || null,
  819. userLanguage = lang.substr(0, 2);
  820. if (userLanguage === 'fr') {
  821. return 'fr_FR';
  822. } else if (userLanguage === 'en') {
  823. return 'en_US';
  824. } else if (userLanguage === 'de') {
  825. return 'de_DE';
  826. } else if (userLanguage === 'es') {
  827. return 'es_ES';
  828. } else if (userLanguage === 'it') {
  829. return 'it_IT';
  830. } else if (userLanguage === 'pt') {
  831. return 'pt_PT';
  832. } else {
  833. return 'en_US';
  834. }
  835. },
  836. "addScript": function (url, id, callback, execute) {
  837. "use strict";
  838. var script,
  839. done = false;
  840. if (execute === false) {
  841. if (typeof callback === 'function') {
  842. callback();
  843. }
  844. } else {
  845. script = document.createElement('script');
  846. script.type = 'text/javascript';
  847. script.id = (id !== undefined) ? id : '';
  848. script.async = true;
  849. script.src = url;
  850. if (typeof callback === 'function') {
  851. script.onreadystatechange = script.onload = function () {
  852. var state = script.readyState;
  853. if (!done && (!state || /loaded|complete/.test(state))) {
  854. done = true;
  855. callback();
  856. }
  857. };
  858. }
  859. document.getElementsByTagName('head')[0].appendChild(script);
  860. }
  861. },
  862. "makeAsync": {
  863. "antiGhost": 0,
  864. "buffer": '',
  865. "init": function (url, id) {
  866. "use strict";
  867. var savedWrite = document.write,
  868. savedWriteln = document.writeln;
  869. document.write = function (content) {
  870. tarteaucitron.makeAsync.buffer += content;
  871. };
  872. document.writeln = function (content) {
  873. tarteaucitron.makeAsync.buffer += content.concat("\n");
  874. };
  875. setTimeout(function () {
  876. document.write = savedWrite;
  877. document.writeln = savedWriteln;
  878. }, 20000);
  879. tarteaucitron.makeAsync.getAndParse(url, id);
  880. },
  881. "getAndParse": function (url, id) {
  882. "use strict";
  883. if (tarteaucitron.makeAsync.antiGhost > 9) {
  884. tarteaucitron.makeAsync.antiGhost = 0;
  885. return;
  886. }
  887. tarteaucitron.makeAsync.antiGhost += 1;
  888. tarteaucitron.addScript(url, '', function () {
  889. if (document.getElementById(id) !== null) {
  890. document.getElementById(id).innerHTML += "<span style='display:none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
  891. tarteaucitron.makeAsync.buffer = '';
  892. tarteaucitron.makeAsync.execJS(id);
  893. }
  894. });
  895. },
  896. "execJS": function (id) {
  897. /* not strict because third party scripts may have errors */
  898. var i,
  899. scripts,
  900. childId,
  901. type;
  902. if (document.getElementById(id) === null) {
  903. return;
  904. }
  905. scripts = document.getElementById(id).getElementsByTagName('script');
  906. for (i = 0; i < scripts.length; i += 1) {
  907. type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : '';
  908. if (type === '') {
  909. type = (scripts[i].getAttribute('language') !== null) ? scripts[i].getAttribute('language') : '';
  910. }
  911. if (scripts[i].getAttribute('src') !== null && scripts[i].getAttribute('src') !== '') {
  912. childId = id + Math.floor(Math.random() * 99999999999);
  913. document.getElementById(id).innerHTML += '<div id="' + childId + '"></div>';
  914. tarteaucitron.makeAsync.getAndParse(scripts[i].getAttribute('src'), childId);
  915. } else if (type.indexOf('javascript') !== -1 || type === '') {
  916. eval(scripts[i].innerHTML);
  917. }
  918. }
  919. }
  920. },
  921. "fallback": function (matchClass, content, noInner) {
  922. "use strict";
  923. var elems = document.getElementsByTagName('*'),
  924. i,
  925. index = 0;
  926. for (i in elems) {
  927. if (elems[i] !== undefined) {
  928. for (index = 0; index < matchClass.length; index += 1) {
  929. if ((' ' + elems[i].className + ' ')
  930. .indexOf(' ' + matchClass[index] + ' ') > -1) {
  931. if (typeof content === 'function') {
  932. if (noInner === true) {
  933. content(elems[i]);
  934. } else {
  935. elems[i].innerHTML = content(elems[i]);
  936. }
  937. } else {
  938. elems[i].innerHTML = content;
  939. }
  940. }
  941. }
  942. }
  943. }
  944. },
  945. "engage": function (id) {
  946. "use strict";
  947. var html = '',
  948. r = Math.floor(Math.random() * 100000);
  949. html += '<div class="tac_activate">';
  950. html += ' <div class="tac_float">';
  951. html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback;
  952. html += ' <div class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
  953. html += ' &#10004; ' + tarteaucitron.lang.allow;
  954. html += ' </div>';
  955. html += ' </div>';
  956. html += '</div>';
  957. return html;
  958. },
  959. "extend": function (a, b) {
  960. "use strict";
  961. var prop;
  962. for (prop in b) {
  963. if (b.hasOwnProperty(prop)) {
  964. a[prop] = b[prop];
  965. }
  966. }
  967. },
  968. "proTemp": '',
  969. "proTimer": function () {
  970. "use strict";
  971. setTimeout(tarteaucitron.proPing, 1000);
  972. },
  973. "pro": function (list) {
  974. "use strict";
  975. tarteaucitron.proTemp += list;
  976. clearTimeout(tarteaucitron.proTimer);
  977. tarteaucitron.proTimer = setTimeout(tarteaucitron.proPing, 2500);
  978. },
  979. "proPing": function () {
  980. "use strict";
  981. if (tarteaucitron.uuid !== '' && tarteaucitron.uuid !== undefined && tarteaucitron.proTemp !== '') {
  982. var div = document.getElementById('tarteaucitronPremium'),
  983. timestamp = new Date().getTime(),
  984. url = '//opt-out.ferank.eu/premium.php?';
  985. if (div === null) {
  986. return;
  987. }
  988. url += 'domain=' + tarteaucitron.domain + '&';
  989. url += 'uuid=' + tarteaucitron.uuid + '&';
  990. url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
  991. url += '_' + timestamp;
  992. div.innerHTML = '<img src="' + url + '" style="display:none" />';
  993. tarteaucitron.proTemp = '';
  994. }
  995. tarteaucitron.cookie.number();
  996. }
  997. };