tarteaucitron.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  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. if(service.readmore !== undefined && service.readmore === false) {
  386. html += ' <a href="https://opt-out.ferank.eu/service/' + service.key + '/" target="_blank" rel="noopener">';
  387. html += ' ' + tarteaucitron.lang.more;
  388. html += ' </a>';
  389. html += ' - ';
  390. }
  391. html += ' <a href="' + service.uri + '" target="_blank" rel="noopener">';
  392. html += ' ' + tarteaucitron.lang.source;
  393. html += ' </a>';
  394. html += ' </div>';
  395. html += ' <div class="tarteaucitronAsk">';
  396. html += ' <div id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  397. html += ' &#10003; ' + tarteaucitron.lang.allow;
  398. html += ' </div> ';
  399. html += ' <div id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  400. html += ' &#10007; ' + tarteaucitron.lang.deny;
  401. html += ' </div>';
  402. html += ' </div>';
  403. html += '</div>';
  404. tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
  405. if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
  406. document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
  407. }
  408. tarteaucitron.userInterface.order(service.type);
  409. }
  410. // allow by default for non EU
  411. if (isResponded === false && tarteaucitron.user.bypass === true) {
  412. isAllowed = true;
  413. tarteaucitron.cookie.create(service.key, true);
  414. }
  415. if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
  416. if (!isAllowed) {
  417. tarteaucitron.cookie.create(service.key, true);
  418. }
  419. if (tarteaucitron.launch[service.key] !== true) {
  420. tarteaucitron.launch[service.key] = true;
  421. service.js();
  422. }
  423. tarteaucitron.state[service.key] = true;
  424. tarteaucitron.userInterface.color(service.key, true);
  425. } else if (isDenied) {
  426. if (typeof service.fallback === 'function') {
  427. service.fallback();
  428. }
  429. tarteaucitron.state[service.key] = false;
  430. tarteaucitron.userInterface.color(service.key, false);
  431. } else if (!isResponded) {
  432. tarteaucitron.cookie.create(service.key, 'wait');
  433. if (typeof service.fallback === 'function') {
  434. service.fallback();
  435. }
  436. tarteaucitron.userInterface.color(service.key, 'wait');
  437. tarteaucitron.userInterface.openAlert();
  438. }
  439. tarteaucitron.cookie.checkCount(service.key);
  440. },
  441. "cleanArray": function cleanArray(arr) {
  442. "use strict";
  443. var i,
  444. len = arr.length,
  445. out = [],
  446. obj = {},
  447. s = tarteaucitron.services;
  448. for (i = 0; i < len; i += 1) {
  449. if (!obj[arr[i]]) {
  450. obj[arr[i]] = {};
  451. if (tarteaucitron.services[arr[i]] !== undefined) {
  452. out.push(arr[i]);
  453. }
  454. }
  455. }
  456. out = out.sort(function (a, b) {
  457. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  458. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  459. return 0;
  460. });
  461. return out;
  462. },
  463. "userInterface": {
  464. "css": function (id, property, value) {
  465. "use strict";
  466. if (document.getElementById(id) !== null) {
  467. document.getElementById(id).style[property] = value;
  468. }
  469. },
  470. "respondAll": function (status) {
  471. "use strict";
  472. var s = tarteaucitron.services,
  473. service,
  474. key,
  475. index = 0;
  476. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  477. service = s[tarteaucitron.job[index]];
  478. key = service.key;
  479. if (tarteaucitron.state[key] !== status) {
  480. if (status === false && tarteaucitron.launch[key] === true) {
  481. tarteaucitron.reloadThePage = true;
  482. }
  483. if (tarteaucitron.launch[key] !== true && status === true) {
  484. tarteaucitron.launch[key] = true;
  485. tarteaucitron.services[key].js();
  486. }
  487. tarteaucitron.state[key] = status;
  488. tarteaucitron.cookie.create(key, status);
  489. tarteaucitron.userInterface.color(key, status);
  490. }
  491. }
  492. },
  493. "respond": function (el, status) {
  494. "use strict";
  495. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  496. // return if same state
  497. if (tarteaucitron.state[key] === status) {
  498. return;
  499. }
  500. if (status === false && tarteaucitron.launch[key] === true) {
  501. tarteaucitron.reloadThePage = true;
  502. }
  503. // if not already launched... launch the service
  504. if (status === true) {
  505. if (tarteaucitron.launch[key] !== true) {
  506. tarteaucitron.launch[key] = true;
  507. tarteaucitron.services[key].js();
  508. }
  509. }
  510. tarteaucitron.state[key] = status;
  511. tarteaucitron.cookie.create(key, status);
  512. tarteaucitron.userInterface.color(key, status);
  513. },
  514. "color": function (key, status) {
  515. "use strict";
  516. var gray = '#808080',
  517. greenDark = '#1B870B',
  518. greenLight = '#E6FFE2',
  519. redDark = '#9C1A1A',
  520. redLight = '#FFE2E2',
  521. yellowDark = '#FBDA26',
  522. c = 'tarteaucitron',
  523. nbDenied = 0,
  524. nbPending = 0,
  525. nbAllowed = 0,
  526. sum = tarteaucitron.job.length,
  527. index;
  528. if (status === true) {
  529. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  530. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  531. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  532. } else if (status === false) {
  533. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  534. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  535. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  536. }
  537. // check if all services are allowed
  538. for (index = 0; index < sum; index += 1) {
  539. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  540. nbDenied += 1;
  541. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  542. nbPending += 1;
  543. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  544. nbAllowed += 1;
  545. }
  546. }
  547. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  548. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  549. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  550. if (nbDenied === 0 && nbPending === 0) {
  551. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  552. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  553. } else if (nbAllowed === 0 && nbPending === 0) {
  554. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  555. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  556. } else {
  557. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  558. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  559. }
  560. // close the alert if all service have been reviewed
  561. if (nbPending === 0) {
  562. tarteaucitron.userInterface.closeAlert();
  563. }
  564. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  565. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  566. }
  567. if (status === true) {
  568. if (document.getElementById('tacCL' + key) !== null) {
  569. document.getElementById('tacCL' + key).innerHTML = '...';
  570. }
  571. setTimeout(function () {
  572. tarteaucitron.cookie.checkCount(key);
  573. }, 2500);
  574. } else {
  575. tarteaucitron.cookie.checkCount(key);
  576. }
  577. },
  578. "openPanel": function () {
  579. "use strict";
  580. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  581. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  582. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  583. tarteaucitron.userInterface.jsSizing('main');
  584. },
  585. "closePanel": function () {
  586. "use strict";
  587. if (document.location.hash === tarteaucitron.hashtag) {
  588. document.location.hash = '';
  589. }
  590. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  591. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  592. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  593. elem.style.display = 'none';
  594. }, true);
  595. if (tarteaucitron.reloadThePage === true) {
  596. window.location.reload();
  597. } else {
  598. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  599. }
  600. },
  601. "openAlert": function () {
  602. "use strict";
  603. var c = 'tarteaucitron';
  604. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'block');
  605. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  606. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  607. },
  608. "closeAlert": function () {
  609. "use strict";
  610. var c = 'tarteaucitron';
  611. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'none');
  612. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  613. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  614. tarteaucitron.userInterface.jsSizing('box');
  615. },
  616. "toggleCookiesList": function () {
  617. "use strict";
  618. var div = document.getElementById('tarteaucitronCookiesListContainer');
  619. if (div === null) {
  620. return;
  621. }
  622. if (div.style.display !== 'block') {
  623. tarteaucitron.cookie.number();
  624. div.style.display = 'block';
  625. tarteaucitron.userInterface.jsSizing('cookie');
  626. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  627. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  628. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  629. elem.style.display = 'none';
  630. }, true);
  631. } else {
  632. div.style.display = 'none';
  633. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  634. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  635. }
  636. },
  637. "toggle": function (id, closeClass) {
  638. "use strict";
  639. var div = document.getElementById(id);
  640. if (div === null) {
  641. return;
  642. }
  643. if (closeClass !== undefined) {
  644. tarteaucitron.fallback([closeClass], function (elem) {
  645. if (elem.id !== id) {
  646. elem.style.display = 'none';
  647. }
  648. }, true);
  649. }
  650. if (div.style.display !== 'block') {
  651. div.style.display = 'block';
  652. } else {
  653. div.style.display = 'none';
  654. }
  655. },
  656. "order": function (id) {
  657. "use strict";
  658. var main = document.getElementById('tarteaucitronServices_' + id),
  659. allDivs,
  660. store = [],
  661. i;
  662. if (main === null) {
  663. return;
  664. }
  665. allDivs = main.childNodes;
  666. if (typeof Array.prototype.map === 'function') {
  667. Array.prototype.map.call(main.children, Object).sort(function (a, b) {
  668. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
  669. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; }
  670. return 0;
  671. }).forEach(function (element) {
  672. main.appendChild(element);
  673. });
  674. }
  675. },
  676. "jsSizing": function (type) {
  677. "use strict";
  678. var scrollbarMarginRight = 10,
  679. scrollbarWidthParent,
  680. scrollbarWidthChild,
  681. servicesHeight,
  682. e = window,
  683. a = 'inner',
  684. windowInnerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
  685. mainTop,
  686. mainHeight,
  687. closeButtonHeight,
  688. headerHeight,
  689. cookiesListHeight,
  690. cookiesCloseHeight,
  691. cookiesTitleHeight,
  692. paddingBox,
  693. alertSmallHeight,
  694. cookiesNumberHeight;
  695. if (type === 'box') {
  696. if (document.getElementById('tarteaucitronAlertSmall') !== null && document.getElementById('tarteaucitronCookiesNumber') !== null) {
  697. // reset
  698. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', '0px 10px');
  699. // calculate
  700. alertSmallHeight = document.getElementById('tarteaucitronAlertSmall').offsetHeight;
  701. cookiesNumberHeight = document.getElementById('tarteaucitronCookiesNumber').offsetHeight;
  702. paddingBox = (alertSmallHeight - cookiesNumberHeight) / 2;
  703. // apply
  704. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', paddingBox + 'px 10px');
  705. }
  706. } else if (type === 'main') {
  707. // get the real window width for media query
  708. if (window.innerWidth === undefined) {
  709. a = 'client';
  710. e = document.documentElement || document.body;
  711. }
  712. // height of the services list container
  713. if (document.getElementById('tarteaucitron') !== null && document.getElementById('tarteaucitronClosePanel') !== null && document.getElementById('tarteaucitronMainLineOffset') !== null) {
  714. // reset
  715. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', 'auto');
  716. // calculate
  717. mainHeight = document.getElementById('tarteaucitron').offsetHeight;
  718. closeButtonHeight = document.getElementById('tarteaucitronClosePanel').offsetHeight;
  719. headerHeight = document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  720. // apply
  721. servicesHeight = (mainHeight - closeButtonHeight - headerHeight + 1);
  722. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', servicesHeight + 'px');
  723. }
  724. // align the main allow/deny button depending on scrollbar width
  725. if (document.getElementById('tarteaucitronScrollbarParent') !== null && document.getElementById('tarteaucitronScrollbarChild') !== null) {
  726. // media query
  727. if (e[a + 'Width'] <= 479) {
  728. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px');
  729. } else if (e[a + 'Width'] <= 767) {
  730. scrollbarMarginRight = 12;
  731. }
  732. scrollbarWidthParent = document.getElementById('tarteaucitronScrollbarParent').offsetWidth;
  733. scrollbarWidthChild = document.getElementById('tarteaucitronScrollbarChild').offsetWidth;
  734. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((scrollbarWidthParent - scrollbarWidthChild) + scrollbarMarginRight) + 'px');
  735. }
  736. // center the main panel
  737. if (document.getElementById('tarteaucitron') !== null) {
  738. // media query
  739. if (e[a + 'Width'] <= 767) {
  740. mainTop = 0;
  741. } else {
  742. mainTop = ((windowInnerHeight - document.getElementById('tarteaucitron').offsetHeight) / 2) - 21;
  743. }
  744. // correct
  745. if (mainTop < 0) {
  746. mainTop = 0;
  747. }
  748. if (document.getElementById('tarteaucitronMainLineOffset') !== null) {
  749. if (document.getElementById('tarteaucitron').offsetHeight < (windowInnerHeight / 2)) {
  750. mainTop -= document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  751. }
  752. }
  753. // apply
  754. tarteaucitron.userInterface.css('tarteaucitron', 'top', mainTop + 'px');
  755. }
  756. } else if (type === 'cookie') {
  757. // put cookies list at bottom
  758. if (document.getElementById('tarteaucitronAlertSmall') !== null) {
  759. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (document.getElementById('tarteaucitronAlertSmall').offsetHeight) + 'px');
  760. }
  761. // height of cookies list
  762. if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
  763. // reset
  764. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto');
  765. // calculate
  766. cookiesListHeight = document.getElementById('tarteaucitronCookiesListContainer').offsetHeight;
  767. cookiesCloseHeight = document.getElementById('tarteaucitronClosePanelCookie').offsetHeight;
  768. cookiesTitleHeight = document.getElementById('tarteaucitronCookiesTitle').offsetHeight;
  769. // apply
  770. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (cookiesListHeight - cookiesCloseHeight - cookiesTitleHeight - 2) + 'px');
  771. }
  772. }
  773. }
  774. },
  775. "cookie": {
  776. "owner": {},
  777. "create": function (key, status) {
  778. "use strict";
  779. var d = new Date(),
  780. time = d.getTime(),
  781. expireTime = time + 31536000000, // 365 days
  782. regex = new RegExp("!" + key + "=(wait|true|false)", "g"),
  783. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  784. value = 'tarteaucitron=' + cookie + '!' + key + '=' + status;
  785. if (tarteaucitron.cookie.read().indexOf(key + '=' + status) === -1) {
  786. tarteaucitron.pro('!' + key + '=' + status);
  787. }
  788. d.setTime(expireTime);
  789. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;';
  790. },
  791. "read": function () {
  792. "use strict";
  793. var nameEQ = "tarteaucitron=",
  794. ca = document.cookie.split(';'),
  795. i,
  796. c;
  797. for (i = 0; i < ca.length; i += 1) {
  798. c = ca[i];
  799. while (c.charAt(0) === ' ') {
  800. c = c.substring(1, c.length);
  801. }
  802. if (c.indexOf(nameEQ) === 0) {
  803. return c.substring(nameEQ.length, c.length);
  804. }
  805. }
  806. return '';
  807. },
  808. "purge": function (arr) {
  809. "use strict";
  810. var i;
  811. for (i = 0; i < arr.length; i += 1) {
  812. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  813. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  814. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  815. }
  816. },
  817. "checkCount": function (key) {
  818. "use strict";
  819. var arr = tarteaucitron.services[key].cookies,
  820. nb = arr.length,
  821. nbCurrent = 0,
  822. html = '',
  823. i,
  824. status = document.cookie.indexOf(key + '=true');
  825. if (status >= 0 && nb === 0) {
  826. html += tarteaucitron.lang.useNoCookie;
  827. } else if (status >= 0) {
  828. for (i = 0; i < nb; i += 1) {
  829. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  830. nbCurrent += 1;
  831. if (tarteaucitron.cookie.owner[arr[i]] === undefined) {
  832. tarteaucitron.cookie.owner[arr[i]] = [];
  833. }
  834. if (tarteaucitron.cookie.crossIndexOf(tarteaucitron.cookie.owner[arr[i]], tarteaucitron.services[key].name) === false) {
  835. tarteaucitron.cookie.owner[arr[i]].push(tarteaucitron.services[key].name);
  836. }
  837. }
  838. }
  839. if (nbCurrent > 0) {
  840. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  841. if (nbCurrent > 1) {
  842. html += 's';
  843. }
  844. html += '.';
  845. } else {
  846. html += tarteaucitron.lang.useNoCookie;
  847. }
  848. } else if (nb === 0) {
  849. html = tarteaucitron.lang.noCookie;
  850. } else {
  851. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  852. if (nb > 1) {
  853. html += 's';
  854. }
  855. html += '.';
  856. }
  857. if (document.getElementById('tacCL' + key) !== null) {
  858. document.getElementById('tacCL' + key).innerHTML = html;
  859. }
  860. },
  861. "crossIndexOf": function (arr, match) {
  862. "use strict";
  863. var i;
  864. for (i = 0; i < arr.length; i += 1) {
  865. if (arr[i] === match) {
  866. return true;
  867. }
  868. }
  869. return false;
  870. },
  871. "number": function () {
  872. "use strict";
  873. var cookies = document.cookie.split(';'),
  874. nb = (document.cookie !== '') ? cookies.length : 0,
  875. html = '',
  876. i,
  877. name,
  878. namea,
  879. nameb,
  880. c,
  881. d,
  882. s = (nb > 1) ? 's' : '',
  883. savedname,
  884. regex = /^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i,
  885. regexedDomain = (tarteaucitron.cdn.match(regex) !== null) ? tarteaucitron.cdn.match(regex)[1] : tarteaucitron.cdn,
  886. host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : regexedDomain;
  887. cookies = cookies.sort(function (a, b) {
  888. namea = a.split('=', 1).toString().replace(/ /g, '');
  889. nameb = b.split('=', 1).toString().replace(/ /g, '');
  890. c = (tarteaucitron.cookie.owner[namea] !== undefined) ? tarteaucitron.cookie.owner[namea] : '0';
  891. d = (tarteaucitron.cookie.owner[nameb] !== undefined) ? tarteaucitron.cookie.owner[nameb] : '0';
  892. if (c + a > d + b) { return 1; }
  893. if (c + a < d + b) { return -1; }
  894. return 0;
  895. });
  896. if (document.cookie !== '') {
  897. for (i = 0; i < nb; i += 1) {
  898. name = cookies[i].split('=', 1).toString().replace(/ /g, '');
  899. if (tarteaucitron.cookie.owner[name] !== undefined && tarteaucitron.cookie.owner[name].join(' // ') !== savedname) {
  900. savedname = tarteaucitron.cookie.owner[name].join(' // ');
  901. html += '<div class="tarteaucitronHidden">';
  902. html += ' <div class="tarteaucitronTitle">';
  903. html += ' ' + tarteaucitron.cookie.owner[name].join(' // ');
  904. html += ' </div>';
  905. html += '</div>';
  906. } else if (tarteaucitron.cookie.owner[name] === undefined && host !== savedname) {
  907. savedname = host;
  908. html += '<div class="tarteaucitronHidden">';
  909. html += ' <div class="tarteaucitronTitle">';
  910. html += ' ' + host;
  911. html += ' </div>';
  912. html += '</div>';
  913. }
  914. html += '<div class="tarteaucitronCookiesListMain">';
  915. 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>';
  916. html += ' </div>';
  917. html += ' <div class="tarteaucitronCookiesListRight">' + cookies[i].split('=').slice(1).join('=') + '</div>';
  918. html += '</div>';
  919. }
  920. } else {
  921. html += '<div class="tarteaucitronCookiesListMain">';
  922. html += ' <div class="tarteaucitronCookiesListLeft"><b>-</b></div>';
  923. html += ' <div class="tarteaucitronCookiesListRight"></div>';
  924. html += '</div>';
  925. }
  926. html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
  927. if (document.getElementById('tarteaucitronCookiesList') !== null) {
  928. document.getElementById('tarteaucitronCookiesList').innerHTML = html;
  929. }
  930. if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
  931. document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
  932. }
  933. if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) {
  934. document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
  935. }
  936. for (i = 0; i < tarteaucitron.job.length; i += 1) {
  937. tarteaucitron.cookie.checkCount(tarteaucitron.job[i]);
  938. }
  939. }
  940. },
  941. "getLanguage": function () {
  942. "use strict";
  943. if (!navigator) { return 'en'; }
  944. var availableLanguages = 'cs,en,fr,es,it,de,pt,pl,ru',
  945. defaultLanguage = 'en',
  946. lang = navigator.language || navigator.browserLanguage ||
  947. navigator.systemLanguage || navigator.userLang || null,
  948. userLanguage = lang.substr(0, 2);
  949. if (tarteaucitronForceLanguage !== '') {
  950. if (availableLanguages.indexOf(tarteaucitronForceLanguage) !== -1) {
  951. return tarteaucitronForceLanguage;
  952. }
  953. }
  954. if (availableLanguages.indexOf(userLanguage) === -1) {
  955. return defaultLanguage;
  956. }
  957. return userLanguage;
  958. },
  959. "getLocale": function () {
  960. "use strict";
  961. if (!navigator) { return 'en_US'; }
  962. var lang = navigator.language || navigator.browserLanguage ||
  963. navigator.systemLanguage || navigator.userLang || null,
  964. userLanguage = lang.substr(0, 2);
  965. if (userLanguage === 'fr') {
  966. return 'fr_FR';
  967. } else if (userLanguage === 'en') {
  968. return 'en_US';
  969. } else if (userLanguage === 'de') {
  970. return 'de_DE';
  971. } else if (userLanguage === 'es') {
  972. return 'es_ES';
  973. } else if (userLanguage === 'it') {
  974. return 'it_IT';
  975. } else if (userLanguage === 'pt') {
  976. return 'pt_PT';
  977. } else {
  978. return 'en_US';
  979. }
  980. },
  981. "addScript": function (url, id, callback, execute, attrName, attrVal) {
  982. "use strict";
  983. var script,
  984. done = false;
  985. if (execute === false) {
  986. if (typeof callback === 'function') {
  987. callback();
  988. }
  989. } else {
  990. script = document.createElement('script');
  991. script.type = 'text/javascript';
  992. script.id = (id !== undefined) ? id : '';
  993. script.async = true;
  994. script.src = url;
  995. if (attrName !== undefined && attrVal !== undefined) {
  996. script.setAttribute(attrName, attrVal);
  997. }
  998. if (typeof callback === 'function') {
  999. script.onreadystatechange = script.onload = function () {
  1000. var state = script.readyState;
  1001. if (!done && (!state || /loaded|complete/.test(state))) {
  1002. done = true;
  1003. callback();
  1004. }
  1005. };
  1006. }
  1007. document.getElementsByTagName('head')[0].appendChild(script);
  1008. }
  1009. },
  1010. "makeAsync": {
  1011. "antiGhost": 0,
  1012. "buffer": '',
  1013. "init": function (url, id) {
  1014. "use strict";
  1015. var savedWrite = document.write,
  1016. savedWriteln = document.writeln;
  1017. document.write = function (content) {
  1018. tarteaucitron.makeAsync.buffer += content;
  1019. };
  1020. document.writeln = function (content) {
  1021. tarteaucitron.makeAsync.buffer += content.concat("\n");
  1022. };
  1023. setTimeout(function () {
  1024. document.write = savedWrite;
  1025. document.writeln = savedWriteln;
  1026. }, 20000);
  1027. tarteaucitron.makeAsync.getAndParse(url, id);
  1028. },
  1029. "getAndParse": function (url, id) {
  1030. "use strict";
  1031. if (tarteaucitron.makeAsync.antiGhost > 9) {
  1032. tarteaucitron.makeAsync.antiGhost = 0;
  1033. return;
  1034. }
  1035. tarteaucitron.makeAsync.antiGhost += 1;
  1036. tarteaucitron.addScript(url, '', function () {
  1037. if (document.getElementById(id) !== null) {
  1038. document.getElementById(id).innerHTML += "<span style='display:none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
  1039. tarteaucitron.makeAsync.buffer = '';
  1040. tarteaucitron.makeAsync.execJS(id);
  1041. }
  1042. });
  1043. },
  1044. "execJS": function (id) {
  1045. /* not strict because third party scripts may have errors */
  1046. var i,
  1047. scripts,
  1048. childId,
  1049. type;
  1050. if (document.getElementById(id) === null) {
  1051. return;
  1052. }
  1053. scripts = document.getElementById(id).getElementsByTagName('script');
  1054. for (i = 0; i < scripts.length; i += 1) {
  1055. type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : '';
  1056. if (type === '') {
  1057. type = (scripts[i].getAttribute('language') !== null) ? scripts[i].getAttribute('language') : '';
  1058. }
  1059. if (scripts[i].getAttribute('src') !== null && scripts[i].getAttribute('src') !== '') {
  1060. childId = id + Math.floor(Math.random() * 99999999999);
  1061. document.getElementById(id).innerHTML += '<div id="' + childId + '"></div>';
  1062. tarteaucitron.makeAsync.getAndParse(scripts[i].getAttribute('src'), childId);
  1063. } else if (type.indexOf('javascript') !== -1 || type === '') {
  1064. eval(scripts[i].innerHTML);
  1065. }
  1066. }
  1067. }
  1068. },
  1069. "fallback": function (matchClass, content, noInner) {
  1070. "use strict";
  1071. var elems = document.getElementsByTagName('*'),
  1072. i,
  1073. index = 0;
  1074. for (i in elems) {
  1075. if (elems[i] !== undefined) {
  1076. for (index = 0; index < matchClass.length; index += 1) {
  1077. if ((' ' + elems[i].className + ' ')
  1078. .indexOf(' ' + matchClass[index] + ' ') > -1) {
  1079. if (typeof content === 'function') {
  1080. if (noInner === true) {
  1081. content(elems[i]);
  1082. } else {
  1083. elems[i].innerHTML = content(elems[i]);
  1084. }
  1085. } else {
  1086. elems[i].innerHTML = content;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. },
  1093. "engage": function (id) {
  1094. "use strict";
  1095. var html = '',
  1096. r = Math.floor(Math.random() * 100000);
  1097. html += '<div class="tac_activate">';
  1098. html += ' <div class="tac_float">';
  1099. html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback;
  1100. html += ' <div class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
  1101. html += ' &#10003; ' + tarteaucitron.lang.allow;
  1102. html += ' </div>';
  1103. html += ' </div>';
  1104. html += '</div>';
  1105. return html;
  1106. },
  1107. "extend": function (a, b) {
  1108. "use strict";
  1109. var prop;
  1110. for (prop in b) {
  1111. if (b.hasOwnProperty(prop)) {
  1112. a[prop] = b[prop];
  1113. }
  1114. }
  1115. },
  1116. "proTemp": '',
  1117. "proTimer": function () {
  1118. "use strict";
  1119. setTimeout(tarteaucitron.proPing, 1000);
  1120. },
  1121. "pro": function (list) {
  1122. "use strict";
  1123. tarteaucitron.proTemp += list;
  1124. clearTimeout(tarteaucitron.proTimer);
  1125. tarteaucitron.proTimer = setTimeout(tarteaucitron.proPing, 2500);
  1126. },
  1127. "proPing": function () {
  1128. "use strict";
  1129. if (tarteaucitron.uuid !== '' && tarteaucitron.uuid !== undefined && tarteaucitron.proTemp !== '') {
  1130. var div = document.getElementById('tarteaucitronPremium'),
  1131. timestamp = new Date().getTime(),
  1132. url = '//opt-out.ferank.eu/premium.php?';
  1133. if (div === null) {
  1134. return;
  1135. }
  1136. url += 'domain=' + tarteaucitron.domain + '&';
  1137. url += 'uuid=' + tarteaucitron.uuid + '&';
  1138. url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
  1139. url += '_' + timestamp;
  1140. div.innerHTML = '<img src="' + url + '" style="display:none" />';
  1141. tarteaucitron.proTemp = '';
  1142. }
  1143. tarteaucitron.cookie.number();
  1144. }
  1145. };