tarteaucitron.js 67 KB

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