tarteaucitron.js 65 KB

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