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. html += ' <a href="https://opt-out.ferank.eu/service/' + service.key + '/" target="_blank" rel="noopener">';
  386. html += ' ' + tarteaucitron.lang.more;
  387. html += ' </a>';
  388. html += ' - ';
  389. html += ' <a href="' + service.uri + '" target="_blank" rel="noopener">';
  390. html += ' ' + tarteaucitron.lang.source;
  391. html += ' </a>';
  392. html += ' </div>';
  393. html += ' <div class="tarteaucitronAsk">';
  394. html += ' <div id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  395. html += ' &#10003; ' + tarteaucitron.lang.allow;
  396. html += ' </div> ';
  397. html += ' <div id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  398. html += ' &#10007; ' + tarteaucitron.lang.deny;
  399. html += ' </div>';
  400. html += ' </div>';
  401. html += '</div>';
  402. tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
  403. if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
  404. document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
  405. }
  406. tarteaucitron.userInterface.order(service.type);
  407. }
  408. // allow by default for non EU
  409. if (isResponded === false && tarteaucitron.user.bypass === true) {
  410. isAllowed = true;
  411. tarteaucitron.cookie.create(service.key, true);
  412. }
  413. if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
  414. if (!isAllowed) {
  415. tarteaucitron.cookie.create(service.key, true);
  416. }
  417. if (tarteaucitron.launch[service.key] !== true) {
  418. tarteaucitron.launch[service.key] = true;
  419. service.js();
  420. }
  421. tarteaucitron.state[service.key] = true;
  422. tarteaucitron.userInterface.color(service.key, true);
  423. } else if (isDenied) {
  424. if (typeof service.fallback === 'function') {
  425. service.fallback();
  426. }
  427. tarteaucitron.state[service.key] = false;
  428. tarteaucitron.userInterface.color(service.key, false);
  429. } else if (!isResponded) {
  430. tarteaucitron.cookie.create(service.key, 'wait');
  431. if (typeof service.fallback === 'function') {
  432. service.fallback();
  433. }
  434. tarteaucitron.userInterface.color(service.key, 'wait');
  435. tarteaucitron.userInterface.openAlert();
  436. }
  437. tarteaucitron.cookie.checkCount(service.key);
  438. },
  439. "cleanArray": function cleanArray(arr) {
  440. "use strict";
  441. var i,
  442. len = arr.length,
  443. out = [],
  444. obj = {},
  445. s = tarteaucitron.services;
  446. for (i = 0; i < len; i += 1) {
  447. if (!obj[arr[i]]) {
  448. obj[arr[i]] = {};
  449. if (tarteaucitron.services[arr[i]] !== undefined) {
  450. out.push(arr[i]);
  451. }
  452. }
  453. }
  454. out = out.sort(function (a, b) {
  455. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  456. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  457. return 0;
  458. });
  459. return out;
  460. },
  461. "userInterface": {
  462. "css": function (id, property, value) {
  463. "use strict";
  464. if (document.getElementById(id) !== null) {
  465. document.getElementById(id).style[property] = value;
  466. }
  467. },
  468. "respondAll": function (status) {
  469. "use strict";
  470. var s = tarteaucitron.services,
  471. service,
  472. key,
  473. index = 0;
  474. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  475. service = s[tarteaucitron.job[index]];
  476. key = service.key;
  477. if (tarteaucitron.state[key] !== status) {
  478. if (status === false && tarteaucitron.launch[key] === true) {
  479. tarteaucitron.reloadThePage = true;
  480. }
  481. if (tarteaucitron.launch[key] !== true && status === true) {
  482. tarteaucitron.launch[key] = true;
  483. tarteaucitron.services[key].js();
  484. }
  485. tarteaucitron.state[key] = status;
  486. tarteaucitron.cookie.create(key, status);
  487. tarteaucitron.userInterface.color(key, status);
  488. }
  489. }
  490. },
  491. "respond": function (el, status) {
  492. "use strict";
  493. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  494. // return if same state
  495. if (tarteaucitron.state[key] === status) {
  496. return;
  497. }
  498. if (status === false && tarteaucitron.launch[key] === true) {
  499. tarteaucitron.reloadThePage = true;
  500. }
  501. // if not already launched... launch the service
  502. if (status === true) {
  503. if (tarteaucitron.launch[key] !== true) {
  504. tarteaucitron.launch[key] = true;
  505. tarteaucitron.services[key].js();
  506. }
  507. }
  508. tarteaucitron.state[key] = status;
  509. tarteaucitron.cookie.create(key, status);
  510. tarteaucitron.userInterface.color(key, status);
  511. },
  512. "color": function (key, status) {
  513. "use strict";
  514. var gray = '#808080',
  515. greenDark = '#1B870B',
  516. greenLight = '#E6FFE2',
  517. redDark = '#9C1A1A',
  518. redLight = '#FFE2E2',
  519. yellowDark = '#FBDA26',
  520. c = 'tarteaucitron',
  521. nbDenied = 0,
  522. nbPending = 0,
  523. nbAllowed = 0,
  524. sum = tarteaucitron.job.length,
  525. index;
  526. if (status === true) {
  527. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  528. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  529. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  530. } else if (status === false) {
  531. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  532. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  533. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  534. }
  535. // check if all services are allowed
  536. for (index = 0; index < sum; index += 1) {
  537. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  538. nbDenied += 1;
  539. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  540. nbPending += 1;
  541. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  542. nbAllowed += 1;
  543. }
  544. }
  545. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  546. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  547. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  548. if (nbDenied === 0 && nbPending === 0) {
  549. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  550. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  551. } else if (nbAllowed === 0 && nbPending === 0) {
  552. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  553. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  554. } else {
  555. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  556. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  557. }
  558. // close the alert if all service have been reviewed
  559. if (nbPending === 0) {
  560. tarteaucitron.userInterface.closeAlert();
  561. }
  562. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  563. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  564. }
  565. if (status === true) {
  566. if (document.getElementById('tacCL' + key) !== null) {
  567. document.getElementById('tacCL' + key).innerHTML = '...';
  568. }
  569. setTimeout(function () {
  570. tarteaucitron.cookie.checkCount(key);
  571. }, 2500);
  572. } else {
  573. tarteaucitron.cookie.checkCount(key);
  574. }
  575. },
  576. "openPanel": function () {
  577. "use strict";
  578. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  579. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  580. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  581. tarteaucitron.userInterface.jsSizing('main');
  582. },
  583. "closePanel": function () {
  584. "use strict";
  585. if (document.location.hash === tarteaucitron.hashtag) {
  586. document.location.hash = '';
  587. }
  588. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  589. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  590. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  591. elem.style.display = 'none';
  592. }, true);
  593. if (tarteaucitron.reloadThePage === true) {
  594. window.location.reload();
  595. } else {
  596. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  597. }
  598. },
  599. "openAlert": function () {
  600. "use strict";
  601. var c = 'tarteaucitron';
  602. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'block');
  603. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  604. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  605. },
  606. "closeAlert": function () {
  607. "use strict";
  608. var c = 'tarteaucitron';
  609. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'none');
  610. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  611. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  612. tarteaucitron.userInterface.jsSizing('box');
  613. },
  614. "toggleCookiesList": function () {
  615. "use strict";
  616. var div = document.getElementById('tarteaucitronCookiesListContainer');
  617. if (div === null) {
  618. return;
  619. }
  620. if (div.style.display !== 'block') {
  621. tarteaucitron.cookie.number();
  622. div.style.display = 'block';
  623. tarteaucitron.userInterface.jsSizing('cookie');
  624. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  625. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  626. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  627. elem.style.display = 'none';
  628. }, true);
  629. } else {
  630. div.style.display = 'none';
  631. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  632. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  633. }
  634. },
  635. "toggle": function (id, closeClass) {
  636. "use strict";
  637. var div = document.getElementById(id);
  638. if (div === null) {
  639. return;
  640. }
  641. if (closeClass !== undefined) {
  642. tarteaucitron.fallback([closeClass], function (elem) {
  643. if (elem.id !== id) {
  644. elem.style.display = 'none';
  645. }
  646. }, true);
  647. }
  648. if (div.style.display !== 'block') {
  649. div.style.display = 'block';
  650. } else {
  651. div.style.display = 'none';
  652. }
  653. },
  654. "order": function (id) {
  655. "use strict";
  656. var main = document.getElementById('tarteaucitronServices_' + id),
  657. allDivs,
  658. store = [],
  659. i;
  660. if (main === null) {
  661. return;
  662. }
  663. allDivs = main.childNodes;
  664. if (typeof Array.prototype.map === 'function') {
  665. Array.prototype.map.call(main.children, Object).sort(function (a, b) {
  666. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
  667. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; }
  668. return 0;
  669. }).forEach(function (element) {
  670. main.appendChild(element);
  671. });
  672. }
  673. },
  674. "jsSizing": function (type) {
  675. "use strict";
  676. var scrollbarMarginRight = 10,
  677. scrollbarWidthParent,
  678. scrollbarWidthChild,
  679. servicesHeight,
  680. e = window,
  681. a = 'inner',
  682. windowInnerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
  683. mainTop,
  684. mainHeight,
  685. closeButtonHeight,
  686. headerHeight,
  687. cookiesListHeight,
  688. cookiesCloseHeight,
  689. cookiesTitleHeight,
  690. paddingBox,
  691. alertSmallHeight,
  692. cookiesNumberHeight;
  693. if (type === 'box') {
  694. if (document.getElementById('tarteaucitronAlertSmall') !== null && document.getElementById('tarteaucitronCookiesNumber') !== null) {
  695. // reset
  696. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', '0px 10px');
  697. // calculate
  698. alertSmallHeight = document.getElementById('tarteaucitronAlertSmall').offsetHeight;
  699. cookiesNumberHeight = document.getElementById('tarteaucitronCookiesNumber').offsetHeight;
  700. paddingBox = (alertSmallHeight - cookiesNumberHeight) / 2;
  701. // apply
  702. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', paddingBox + 'px 10px');
  703. }
  704. } else if (type === 'main') {
  705. // get the real window width for media query
  706. if (window.innerWidth === undefined) {
  707. a = 'client';
  708. e = document.documentElement || document.body;
  709. }
  710. // height of the services list container
  711. if (document.getElementById('tarteaucitron') !== null && document.getElementById('tarteaucitronClosePanel') !== null && document.getElementById('tarteaucitronMainLineOffset') !== null) {
  712. // reset
  713. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', 'auto');
  714. // calculate
  715. mainHeight = document.getElementById('tarteaucitron').offsetHeight;
  716. closeButtonHeight = document.getElementById('tarteaucitronClosePanel').offsetHeight;
  717. headerHeight = document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  718. // apply
  719. servicesHeight = (mainHeight - closeButtonHeight - headerHeight + 1);
  720. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', servicesHeight + 'px');
  721. }
  722. // align the main allow/deny button depending on scrollbar width
  723. if (document.getElementById('tarteaucitronScrollbarParent') !== null && document.getElementById('tarteaucitronScrollbarChild') !== null) {
  724. // media query
  725. if (e[a + 'Width'] <= 479) {
  726. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px');
  727. } else if (e[a + 'Width'] <= 767) {
  728. scrollbarMarginRight = 12;
  729. }
  730. scrollbarWidthParent = document.getElementById('tarteaucitronScrollbarParent').offsetWidth;
  731. scrollbarWidthChild = document.getElementById('tarteaucitronScrollbarChild').offsetWidth;
  732. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((scrollbarWidthParent - scrollbarWidthChild) + scrollbarMarginRight) + 'px');
  733. }
  734. // center the main panel
  735. if (document.getElementById('tarteaucitron') !== null) {
  736. // media query
  737. if (e[a + 'Width'] <= 767) {
  738. mainTop = 0;
  739. } else {
  740. mainTop = ((windowInnerHeight - document.getElementById('tarteaucitron').offsetHeight) / 2) - 21;
  741. }
  742. // correct
  743. if (mainTop < 0) {
  744. mainTop = 0;
  745. }
  746. if (document.getElementById('tarteaucitronMainLineOffset') !== null) {
  747. if (document.getElementById('tarteaucitron').offsetHeight < (windowInnerHeight / 2)) {
  748. mainTop -= document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  749. }
  750. }
  751. // apply
  752. tarteaucitron.userInterface.css('tarteaucitron', 'top', mainTop + 'px');
  753. }
  754. } else if (type === 'cookie') {
  755. // put cookies list at bottom
  756. if (document.getElementById('tarteaucitronAlertSmall') !== null) {
  757. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (document.getElementById('tarteaucitronAlertSmall').offsetHeight) + 'px');
  758. }
  759. // height of cookies list
  760. if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
  761. // reset
  762. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto');
  763. // calculate
  764. cookiesListHeight = document.getElementById('tarteaucitronCookiesListContainer').offsetHeight;
  765. cookiesCloseHeight = document.getElementById('tarteaucitronClosePanelCookie').offsetHeight;
  766. cookiesTitleHeight = document.getElementById('tarteaucitronCookiesTitle').offsetHeight;
  767. // apply
  768. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (cookiesListHeight - cookiesCloseHeight - cookiesTitleHeight - 2) + 'px');
  769. }
  770. }
  771. }
  772. },
  773. "cookie": {
  774. "owner": {},
  775. "create": function (key, status) {
  776. "use strict";
  777. var d = new Date(),
  778. time = d.getTime(),
  779. expireTime = time + 31536000000, // 365 days
  780. regex = new RegExp("!" + key + "=(wait|true|false)", "g"),
  781. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  782. value = 'tarteaucitron=' + cookie + '!' + key + '=' + status;
  783. if (tarteaucitron.cookie.read().indexOf(key + '=' + status) === -1) {
  784. tarteaucitron.pro('!' + key + '=' + status);
  785. }
  786. d.setTime(expireTime);
  787. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;';
  788. },
  789. "read": function () {
  790. "use strict";
  791. var nameEQ = "tarteaucitron=",
  792. ca = document.cookie.split(';'),
  793. i,
  794. c;
  795. for (i = 0; i < ca.length; i += 1) {
  796. c = ca[i];
  797. while (c.charAt(0) === ' ') {
  798. c = c.substring(1, c.length);
  799. }
  800. if (c.indexOf(nameEQ) === 0) {
  801. return c.substring(nameEQ.length, c.length);
  802. }
  803. }
  804. return '';
  805. },
  806. "purge": function (arr) {
  807. "use strict";
  808. var i;
  809. for (i = 0; i < arr.length; i += 1) {
  810. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  811. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  812. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  813. }
  814. },
  815. "checkCount": function (key) {
  816. "use strict";
  817. var arr = tarteaucitron.services[key].cookies,
  818. nb = arr.length,
  819. nbCurrent = 0,
  820. html = '',
  821. i,
  822. status = document.cookie.indexOf(key + '=true');
  823. if (status >= 0 && nb === 0) {
  824. html += tarteaucitron.lang.useNoCookie;
  825. } else if (status >= 0) {
  826. for (i = 0; i < nb; i += 1) {
  827. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  828. nbCurrent += 1;
  829. if (tarteaucitron.cookie.owner[arr[i]] === undefined) {
  830. tarteaucitron.cookie.owner[arr[i]] = [];
  831. }
  832. if (tarteaucitron.cookie.crossIndexOf(tarteaucitron.cookie.owner[arr[i]], tarteaucitron.services[key].name) === false) {
  833. tarteaucitron.cookie.owner[arr[i]].push(tarteaucitron.services[key].name);
  834. }
  835. }
  836. }
  837. if (nbCurrent > 0) {
  838. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  839. if (nbCurrent > 1) {
  840. html += 's';
  841. }
  842. html += '.';
  843. } else {
  844. html += tarteaucitron.lang.useNoCookie;
  845. }
  846. } else if (nb === 0) {
  847. html = tarteaucitron.lang.noCookie;
  848. } else {
  849. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  850. if (nb > 1) {
  851. html += 's';
  852. }
  853. html += '.';
  854. }
  855. if (document.getElementById('tacCL' + key) !== null) {
  856. document.getElementById('tacCL' + key).innerHTML = html;
  857. }
  858. },
  859. "crossIndexOf": function (arr, match) {
  860. "use strict";
  861. var i;
  862. for (i = 0; i < arr.length; i += 1) {
  863. if (arr[i] === match) {
  864. return true;
  865. }
  866. }
  867. return false;
  868. },
  869. "number": function () {
  870. "use strict";
  871. var cookies = document.cookie.split(';'),
  872. nb = (document.cookie !== '') ? cookies.length : 0,
  873. html = '',
  874. i,
  875. name,
  876. namea,
  877. nameb,
  878. c,
  879. d,
  880. s = (nb > 1) ? 's' : '',
  881. savedname,
  882. regex = /^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i,
  883. regexedDomain = (tarteaucitron.cdn.match(regex) !== null) ? tarteaucitron.cdn.match(regex)[1] : tarteaucitron.cdn,
  884. host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : regexedDomain;
  885. cookies = cookies.sort(function (a, b) {
  886. namea = a.split('=', 1).toString().replace(/ /g, '');
  887. nameb = b.split('=', 1).toString().replace(/ /g, '');
  888. c = (tarteaucitron.cookie.owner[namea] !== undefined) ? tarteaucitron.cookie.owner[namea] : '0';
  889. d = (tarteaucitron.cookie.owner[nameb] !== undefined) ? tarteaucitron.cookie.owner[nameb] : '0';
  890. if (c + a > d + b) { return 1; }
  891. if (c + a < d + b) { return -1; }
  892. return 0;
  893. });
  894. if (document.cookie !== '') {
  895. for (i = 0; i < nb; i += 1) {
  896. name = cookies[i].split('=', 1).toString().replace(/ /g, '');
  897. if (tarteaucitron.cookie.owner[name] !== undefined && tarteaucitron.cookie.owner[name].join(' // ') !== savedname) {
  898. savedname = tarteaucitron.cookie.owner[name].join(' // ');
  899. html += '<div class="tarteaucitronHidden">';
  900. html += ' <div class="tarteaucitronTitle">';
  901. html += ' ' + tarteaucitron.cookie.owner[name].join(' // ');
  902. html += ' </div>';
  903. html += '</div>';
  904. } else if (tarteaucitron.cookie.owner[name] === undefined && host !== savedname) {
  905. savedname = host;
  906. html += '<div class="tarteaucitronHidden">';
  907. html += ' <div class="tarteaucitronTitle">';
  908. html += ' ' + host;
  909. html += ' </div>';
  910. html += '</div>';
  911. }
  912. html += '<div class="tarteaucitronCookiesListMain">';
  913. 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>';
  914. html += ' </div>';
  915. html += ' <div class="tarteaucitronCookiesListRight">' + cookies[i].split('=').slice(1).join('=') + '</div>';
  916. html += '</div>';
  917. }
  918. } else {
  919. html += '<div class="tarteaucitronCookiesListMain">';
  920. html += ' <div class="tarteaucitronCookiesListLeft"><b>-</b></div>';
  921. html += ' <div class="tarteaucitronCookiesListRight"></div>';
  922. html += '</div>';
  923. }
  924. html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
  925. if (document.getElementById('tarteaucitronCookiesList') !== null) {
  926. document.getElementById('tarteaucitronCookiesList').innerHTML = html;
  927. }
  928. if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
  929. document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
  930. }
  931. if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) {
  932. document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
  933. }
  934. for (i = 0; i < tarteaucitron.job.length; i += 1) {
  935. tarteaucitron.cookie.checkCount(tarteaucitron.job[i]);
  936. }
  937. }
  938. },
  939. "getLanguage": function () {
  940. "use strict";
  941. if (!navigator) { return 'en'; }
  942. var availableLanguages = 'cs,en,fr,es,it,de,nl,pt,pl,ru',
  943. defaultLanguage = 'en',
  944. lang = navigator.language || navigator.browserLanguage ||
  945. navigator.systemLanguage || navigator.userLang || null,
  946. userLanguage = lang.substr(0, 2);
  947. if (tarteaucitronForceLanguage !== '') {
  948. if (availableLanguages.indexOf(tarteaucitronForceLanguage) !== -1) {
  949. return tarteaucitronForceLanguage;
  950. }
  951. }
  952. if (availableLanguages.indexOf(userLanguage) === -1) {
  953. return defaultLanguage;
  954. }
  955. return userLanguage;
  956. },
  957. "getLocale": function () {
  958. "use strict";
  959. if (!navigator) { return 'en_US'; }
  960. var lang = navigator.language || navigator.browserLanguage ||
  961. navigator.systemLanguage || navigator.userLang || null,
  962. userLanguage = lang.substr(0, 2);
  963. if (userLanguage === 'fr') {
  964. return 'fr_FR';
  965. } else if (userLanguage === 'en') {
  966. return 'en_US';
  967. } else if (userLanguage === 'de') {
  968. return 'de_DE';
  969. } else if (userLanguage === 'es') {
  970. return 'es_ES';
  971. } else if (userLanguage === 'it') {
  972. return 'it_IT';
  973. } else if (userLanguage === 'pt') {
  974. return 'pt_PT';
  975. } else if (userLanguage === 'nl') {
  976. return 'nl_NL';
  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. };