tarteaucitron.js 60 KB

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