tarteaucitron.js 60 KB

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