tarteaucitron.js 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  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": 20181023,
  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 type="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 type="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="1" 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 type="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="2">' + tarteaucitron.lang.all + '</span>';
  267. html += ' </div>';
  268. html += ' <div class="tarteaucitronAsk" id="tarteaucitronScrollbarAdjust">';
  269. html += ' <button type="button" id="tarteaucitronAllAllowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respondAll(true);">';
  270. html += ' &#10003; ' + tarteaucitron.lang.allowAll;
  271. html += ' </button> ';
  272. html += ' <button type="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 type="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 noreferrer 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 type="button" id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.openPanel();">';
  306. html += ' ' + tarteaucitron.lang.personalize;
  307. html += ' </button>';
  308. if (tarteaucitron.parameters.privacyUrl !== "") {
  309. html += ' <button type="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 type="button" id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.respondAll(true);">';
  324. html += ' &#10003; ' + tarteaucitron.lang.acceptAll;
  325. html += ' </button>';
  326. html += ' <button type="button" id="tarteaucitronCloseAlert" onclick="tarteaucitron.userInterface.openPanel();">';
  327. html += ' ' + tarteaucitron.lang.personalize;
  328. html += ' </button>';
  329. if (tarteaucitron.parameters.privacyUrl !== "") {
  330. html += ' <button type="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 type="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 type="button" id="tarteaucitronCookiesNumber" onclick="tarteaucitron.userInterface.toggleCookiesList();">0</button>';
  349. html += ' <div id="tarteaucitronCookiesListContainer">';
  350. html += ' <button type="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="2" 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 type="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. }
  437. }, 1500);
  438. }
  439. });
  440. });
  441. if(tarteaucitron.events.load) {
  442. tarteaucitron.events.load();
  443. }
  444. },
  445. "addService": function (serviceId) {
  446. "use strict";
  447. var html = '',
  448. s = tarteaucitron.services,
  449. service = s[serviceId],
  450. cookie = tarteaucitron.cookie.read(),
  451. hostname = document.location.hostname,
  452. hostRef = document.referrer.split('/')[2],
  453. isNavigating = (hostRef === hostname && window.location.href !== tarteaucitron.parameters.privacyUrl) ? true : false,
  454. isAutostart = (!service.needConsent) ? true : false,
  455. isWaiting = (cookie.indexOf(service.key + '=wait') >= 0) ? true : false,
  456. isDenied = (cookie.indexOf(service.key + '=false') >= 0) ? true : false,
  457. isAllowed = (cookie.indexOf(service.key + '=true') >= 0) ? true : false,
  458. isResponded = (cookie.indexOf(service.key + '=false') >= 0 || cookie.indexOf(service.key + '=true') >= 0) ? true : false,
  459. isDNTRequested = (navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1" || window.doNotTrack === "1") ? true : false;
  460. if (tarteaucitron.added[service.key] !== true) {
  461. tarteaucitron.added[service.key] = true;
  462. html += '<li id="' + service.key + 'Line" class="tarteaucitronLine">';
  463. html += ' <div class="tarteaucitronName">';
  464. html += ' <span class="tarteaucitronH3" role="heading" aria-level="3">' + service.name + '</span>';
  465. html += ' <span id="tacCL' + service.key + '" class="tarteaucitronListCookies"></span><br/>';
  466. if (tarteaucitron.parameters.moreInfoLink == true) {
  467. var link = 'https://opt-out.ferank.eu/service/' + service.key + '/';
  468. if (service.readmoreLink !== undefined && service.readmoreLink !== '') {
  469. link = service.readmoreLink;
  470. }
  471. if (tarteaucitron.parameters.readmoreLink !== undefined && tarteaucitron.parameters.readmoreLink !== '') {
  472. link = tarteaucitron.parameters.readmoreLink;
  473. }
  474. html += ' <a href="' + link + '" target="_blank" rel="noreferrer noopener" title="'+ tarteaucitron.lang.cookieDetail + ' ' + service.name + ' ' + tarteaucitron.lang.ourSite + ' ' + tarteaucitron.lang.newWindow +'">';
  475. html += ' ' + tarteaucitron.lang.more;
  476. html += ' </a>';
  477. html += ' - ';
  478. html += ' <a href="' + service.uri + '" target="_blank" rel="noreferrer noopener" title="' + service.name + ' ' + tarteaucitron.lang.newWindow + '">';
  479. html += ' ' + tarteaucitron.lang.source;
  480. html += ' </a>';
  481. }
  482. html += ' </div>';
  483. html += ' <div class="tarteaucitronAsk">';
  484. html += ' <button type="button" id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  485. html += ' &#10003; ' + tarteaucitron.lang.allow;
  486. html += ' </button> ';
  487. html += ' <button type="button" id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  488. html += ' &#10007; ' + tarteaucitron.lang.deny;
  489. html += ' </button>';
  490. html += ' </div>';
  491. html += '</li>';
  492. tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
  493. if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
  494. document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
  495. }
  496. tarteaucitron.userInterface.order(service.type);
  497. }
  498. tarteaucitron.pro('!' + service.key + '=' + isAllowed);
  499. // allow by default for non EU
  500. if (isResponded === false && tarteaucitron.user.bypass === true) {
  501. isAllowed = true;
  502. tarteaucitron.cookie.create(service.key, true);
  503. }
  504. if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
  505. if (!isAllowed) {
  506. tarteaucitron.cookie.create(service.key, true);
  507. }
  508. if (tarteaucitron.launch[service.key] !== true) {
  509. tarteaucitron.launch[service.key] = true;
  510. service.js();
  511. }
  512. tarteaucitron.state[service.key] = true;
  513. tarteaucitron.userInterface.color(service.key, true);
  514. } else if (isDenied) {
  515. if (typeof service.fallback === 'function') {
  516. service.fallback();
  517. }
  518. tarteaucitron.state[service.key] = false;
  519. tarteaucitron.userInterface.color(service.key, false);
  520. } else if (!isResponded && isDNTRequested && tarteaucitron.handleBrowserDNTRequest) {
  521. tarteaucitron.cookie.create(service.key, 'false');
  522. if (typeof service.fallback === 'function') {
  523. service.fallback();
  524. }
  525. tarteaucitron.state[service.key] = false;
  526. tarteaucitron.userInterface.color(service.key, false);
  527. } else if (!isResponded) {
  528. tarteaucitron.cookie.create(service.key, 'wait');
  529. if (typeof service.fallback === 'function') {
  530. service.fallback();
  531. }
  532. tarteaucitron.userInterface.color(service.key, 'wait');
  533. tarteaucitron.userInterface.openAlert();
  534. }
  535. tarteaucitron.cookie.checkCount(service.key);
  536. },
  537. "cleanArray": function cleanArray(arr) {
  538. "use strict";
  539. var i,
  540. len = arr.length,
  541. out = [],
  542. obj = {},
  543. s = tarteaucitron.services;
  544. for (i = 0; i < len; i += 1) {
  545. if (!obj[arr[i]]) {
  546. obj[arr[i]] = {};
  547. if (tarteaucitron.services[arr[i]] !== undefined) {
  548. out.push(arr[i]);
  549. }
  550. }
  551. }
  552. out = out.sort(function (a, b) {
  553. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  554. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  555. return 0;
  556. });
  557. return out;
  558. },
  559. "userInterface": {
  560. "css": function (id, property, value) {
  561. "use strict";
  562. if (document.getElementById(id) !== null) {
  563. document.getElementById(id).style[property] = value;
  564. }
  565. },
  566. "respondAll": function (status) {
  567. "use strict";
  568. var s = tarteaucitron.services,
  569. service,
  570. key,
  571. index = 0;
  572. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  573. service = s[tarteaucitron.job[index]];
  574. key = service.key;
  575. if (tarteaucitron.state[key] !== status) {
  576. if (status === false && tarteaucitron.launch[key] === true) {
  577. tarteaucitron.reloadThePage = true;
  578. }
  579. if (tarteaucitron.launch[key] !== true && status === true) {
  580. tarteaucitron.pro('!' + key + '=engage');
  581. tarteaucitron.launch[key] = true;
  582. tarteaucitron.services[key].js();
  583. }
  584. tarteaucitron.state[key] = status;
  585. tarteaucitron.cookie.create(key, status);
  586. tarteaucitron.userInterface.color(key, status);
  587. }
  588. }
  589. },
  590. "respond": function (el, status) {
  591. "use strict";
  592. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  593. // return if same state
  594. if (tarteaucitron.state[key] === status) {
  595. return;
  596. }
  597. if (status === false && tarteaucitron.launch[key] === true) {
  598. tarteaucitron.reloadThePage = true;
  599. }
  600. // if not already launched... launch the service
  601. if (status === true) {
  602. if (tarteaucitron.launch[key] !== true) {
  603. tarteaucitron.pro('!' + key + '=engage');
  604. tarteaucitron.launch[key] = true;
  605. tarteaucitron.services[key].js();
  606. }
  607. }
  608. tarteaucitron.state[key] = status;
  609. tarteaucitron.cookie.create(key, status);
  610. tarteaucitron.userInterface.color(key, status);
  611. },
  612. "color": function (key, status) {
  613. "use strict";
  614. var gray = '#808080',
  615. greenDark = '#1B870B',
  616. greenLight = '#E6FFE2',
  617. redDark = '#9C1A1A',
  618. redLight = '#FFE2E2',
  619. yellowDark = '#FBDA26',
  620. c = 'tarteaucitron',
  621. nbDenied = 0,
  622. nbPending = 0,
  623. nbAllowed = 0,
  624. sum = tarteaucitron.job.length,
  625. index;
  626. if (status === true) {
  627. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  628. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  629. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  630. document.getElementById(key + 'Line').classList.add('tarteaucitronIsAllowed');
  631. document.getElementById(key + 'Line').classList.remove('tarteaucitronIsDenied');
  632. } else if (status === false) {
  633. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  634. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  635. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  636. document.getElementById(key + 'Line').classList.remove('tarteaucitronIsAllowed');
  637. document.getElementById(key + 'Line').classList.add('tarteaucitronIsDenied');
  638. }
  639. // check if all services are allowed
  640. for (index = 0; index < sum; index += 1) {
  641. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  642. nbDenied += 1;
  643. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  644. nbPending += 1;
  645. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  646. nbAllowed += 1;
  647. }
  648. }
  649. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  650. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  651. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  652. if (nbDenied === 0 && nbPending === 0) {
  653. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  654. tarteaucitron.userInterface.css(c + 'AllDenied', 'opacity', '0.4');
  655. tarteaucitron.userInterface.css(c + 'AllAllowed', 'opacity', '1');
  656. } else if (nbAllowed === 0 && nbPending === 0) {
  657. tarteaucitron.userInterface.css(c + 'AllAllowed', 'opacity', '0.4');
  658. tarteaucitron.userInterface.css(c + 'AllDenied', 'opacity', '1');
  659. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  660. } else {
  661. tarteaucitron.userInterface.css(c + 'AllAllowed', 'opacity', '0.4');
  662. tarteaucitron.userInterface.css(c + 'AllDenied', 'opacity', '0.4');
  663. }
  664. // close the alert if all service have been reviewed
  665. if (nbPending === 0) {
  666. tarteaucitron.userInterface.closeAlert();
  667. }
  668. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  669. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  670. }
  671. if (status === true) {
  672. if (document.getElementById('tacCL' + key) !== null) {
  673. document.getElementById('tacCL' + key).innerHTML = '...';
  674. }
  675. setTimeout(function () {
  676. tarteaucitron.cookie.checkCount(key);
  677. }, 2500);
  678. } else {
  679. tarteaucitron.cookie.checkCount(key);
  680. }
  681. },
  682. "openPanel": function () {
  683. "use strict";
  684. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  685. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  686. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  687. document.getElementById('tarteaucitronClosePanel').focus();
  688. //document.getElementById('contentWrapper').setAttribute("aria-hidden", "true");
  689. document.getElementsByTagName('body')[0].classList.add('modal-open');
  690. tarteaucitron.userInterface.focusTrap();
  691. tarteaucitron.userInterface.jsSizing('main');
  692. },
  693. "closePanel": function () {
  694. "use strict";
  695. if (document.location.hash === tarteaucitron.hashtag) {
  696. document.location.hash = '';
  697. }
  698. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  699. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  700. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  701. elem.style.display = 'none';
  702. }, true);
  703. if (tarteaucitron.reloadThePage === true) {
  704. window.location.reload();
  705. } else {
  706. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  707. }
  708. if (document.getElementById('tarteaucitronCloseAlert') !== null) {
  709. document.getElementById('tarteaucitronCloseAlert').focus();
  710. }
  711. //document.getElementById('contentWrapper').setAttribute("aria-hidden", "false");
  712. document.getElementsByTagName('body')[0].classList.remove('modal-open');
  713. },
  714. "focusTrap": function() {
  715. "use strict";
  716. var focusableEls,
  717. firstFocusableEl,
  718. lastFocusableEl,
  719. filtered;
  720. focusableEls = document.getElementById('tarteaucitron').querySelectorAll('a[href], button');
  721. filtered = [];
  722. // get only visible items
  723. for (var i = 0, max = focusableEls.length; i < max; i++) {
  724. if (focusableEls[i].offsetHeight > 0) {
  725. filtered.push(focusableEls[i]);
  726. }
  727. }
  728. firstFocusableEl = filtered[0];
  729. lastFocusableEl = filtered[filtered.length - 1];
  730. //loop focus inside tarteaucitron
  731. document.getElementById('tarteaucitron').addEventListener("keydown", function (evt) {
  732. if ( evt.key === 'Tab' || evt.keyCode === 9 ) {
  733. if ( evt.shiftKey ) /* shift + tab */ {
  734. if (document.activeElement === firstFocusableEl) {
  735. lastFocusableEl.focus();
  736. evt.preventDefault();
  737. }
  738. } else /* tab */ {
  739. if (document.activeElement === lastFocusableEl) {
  740. firstFocusableEl.focus();
  741. evt.preventDefault();
  742. }
  743. }
  744. }
  745. })
  746. },
  747. "openAlert": function () {
  748. "use strict";
  749. var c = 'tarteaucitron';
  750. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'block');
  751. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  752. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  753. },
  754. "closeAlert": function () {
  755. "use strict";
  756. var c = 'tarteaucitron';
  757. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'none');
  758. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  759. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  760. tarteaucitron.userInterface.jsSizing('box');
  761. },
  762. "toggleCookiesList": function () {
  763. "use strict";
  764. var div = document.getElementById('tarteaucitronCookiesListContainer');
  765. if (div === null) {
  766. return;
  767. }
  768. if (div.style.display !== 'block') {
  769. tarteaucitron.cookie.number();
  770. div.style.display = 'block';
  771. tarteaucitron.userInterface.jsSizing('cookie');
  772. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  773. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  774. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  775. elem.style.display = 'none';
  776. }, true);
  777. } else {
  778. div.style.display = 'none';
  779. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  780. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  781. }
  782. },
  783. "toggle": function (id, closeClass) {
  784. "use strict";
  785. var div = document.getElementById(id);
  786. if (div === null) {
  787. return;
  788. }
  789. if (closeClass !== undefined) {
  790. tarteaucitron.fallback([closeClass], function (elem) {
  791. if (elem.id !== id) {
  792. elem.style.display = 'none';
  793. }
  794. }, true);
  795. }
  796. if (div.style.display !== 'block') {
  797. div.style.display = 'block';
  798. } else {
  799. div.style.display = 'none';
  800. }
  801. },
  802. "order": function (id) {
  803. "use strict";
  804. var main = document.getElementById('tarteaucitronServices_' + id),
  805. allDivs,
  806. store = [],
  807. i;
  808. if (main === null) {
  809. return;
  810. }
  811. allDivs = main.childNodes;
  812. if (typeof Array.prototype.map === 'function' && typeof Enumerable === 'undefined') {
  813. Array.prototype.map.call(main.children, Object).sort(function (a, b) {
  814. //var mainChildren = Array.from(main.children);
  815. //mainChildren.sort(function (a, b) {
  816. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
  817. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; }
  818. return 0;
  819. }).forEach(function (element) {
  820. main.appendChild(element);
  821. });
  822. }
  823. },
  824. "jsSizing": function (type) {
  825. "use strict";
  826. var scrollbarMarginRight = 10,
  827. scrollbarWidthParent,
  828. scrollbarWidthChild,
  829. servicesHeight,
  830. e = window,
  831. a = 'inner',
  832. windowInnerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
  833. mainTop,
  834. mainHeight,
  835. closeButtonHeight,
  836. headerHeight,
  837. cookiesListHeight,
  838. cookiesCloseHeight,
  839. cookiesTitleHeight,
  840. paddingBox,
  841. alertSmallHeight,
  842. cookiesNumberHeight;
  843. if (type === 'box') {
  844. if (document.getElementById('tarteaucitronAlertSmall') !== null && document.getElementById('tarteaucitronCookiesNumber') !== null) {
  845. // reset
  846. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', '0px 10px');
  847. // calculate
  848. alertSmallHeight = document.getElementById('tarteaucitronAlertSmall').offsetHeight;
  849. cookiesNumberHeight = document.getElementById('tarteaucitronCookiesNumber').offsetHeight;
  850. paddingBox = (alertSmallHeight - cookiesNumberHeight) / 2;
  851. // apply
  852. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', paddingBox + 'px 10px');
  853. }
  854. } else if (type === 'main') {
  855. // get the real window width for media query
  856. if (window.innerWidth === undefined) {
  857. a = 'client';
  858. e = document.documentElement || document.body;
  859. }
  860. // height of the services list container
  861. if (document.getElementById('tarteaucitron') !== null && document.getElementById('tarteaucitronClosePanel') !== null && document.getElementById('tarteaucitronMainLineOffset') !== null) {
  862. // reset
  863. tarteaucitron.userInterface.css('tarteaucitronServices', 'height', 'auto');
  864. // calculate
  865. mainHeight = document.getElementById('tarteaucitron').offsetHeight;
  866. closeButtonHeight = document.getElementById('tarteaucitronClosePanel').offsetHeight;
  867. // apply
  868. servicesHeight = (mainHeight - closeButtonHeight + 2);
  869. tarteaucitron.userInterface.css('tarteaucitronServices', 'height', servicesHeight + 'px');
  870. tarteaucitron.userInterface.css('tarteaucitronServices', 'overflow-x', 'auto');
  871. }
  872. // align the main allow/deny button depending on scrollbar width
  873. if (document.getElementById('tarteaucitronServices') !== null && document.getElementById('tarteaucitronScrollbarChild') !== null) {
  874. // media query
  875. if (e[a + 'Width'] <= 479) {
  876. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px');
  877. } else if (e[a + 'Width'] <= 767) {
  878. scrollbarMarginRight = 12;
  879. }
  880. scrollbarWidthParent = document.getElementById('tarteaucitronServices').offsetWidth;
  881. scrollbarWidthChild = document.getElementById('tarteaucitronScrollbarChild').offsetWidth;
  882. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((scrollbarWidthParent - scrollbarWidthChild) + scrollbarMarginRight) + 'px');
  883. }
  884. // center the main panel
  885. if (document.getElementById('tarteaucitron') !== null) {
  886. // media query
  887. if (e[a + 'Width'] <= 767) {
  888. mainTop = 0;
  889. } else {
  890. mainTop = ((windowInnerHeight - document.getElementById('tarteaucitron').offsetHeight) / 2) - 21;
  891. }
  892. // correct
  893. if (mainTop < 0) {
  894. mainTop = 0;
  895. }
  896. if (document.getElementById('tarteaucitronMainLineOffset') !== null) {
  897. if (document.getElementById('tarteaucitron').offsetHeight < (windowInnerHeight / 2)) {
  898. mainTop -= document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  899. }
  900. }
  901. // apply
  902. tarteaucitron.userInterface.css('tarteaucitron', 'top', mainTop + 'px');
  903. }
  904. } else if (type === 'cookie') {
  905. // put cookies list at bottom
  906. if (document.getElementById('tarteaucitronAlertSmall') !== null) {
  907. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (document.getElementById('tarteaucitronAlertSmall').offsetHeight) + 'px');
  908. }
  909. // height of cookies list
  910. if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
  911. // reset
  912. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto');
  913. // calculate
  914. cookiesListHeight = document.getElementById('tarteaucitronCookiesListContainer').offsetHeight;
  915. cookiesCloseHeight = document.getElementById('tarteaucitronClosePanelCookie').offsetHeight;
  916. cookiesTitleHeight = document.getElementById('tarteaucitronCookiesTitle').offsetHeight;
  917. // apply
  918. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (cookiesListHeight - cookiesCloseHeight - cookiesTitleHeight - 2) + 'px');
  919. }
  920. }
  921. }
  922. },
  923. "cookie": {
  924. "owner": {},
  925. "create": function (key, status) {
  926. "use strict";
  927. if (tarteaucitronForceExpire !== '') {
  928. // The number of day cann't be higher than 1 year
  929. timeExipre = (tarteaucitronForceExpire > 365) ? 31536000000 : tarteaucitronForceExpire * 86400000; // Multiplication to tranform the number of days to milliseconds
  930. }
  931. var d = new Date(),
  932. time = d.getTime(),
  933. expireTime = time + timeExipre, // 365 days
  934. regex = new RegExp("!" + key + "=(wait|true|false)", "g"),
  935. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  936. value = tarteaucitron.parameters.cookieName + '=' + cookie + '!' + key + '=' + status,
  937. domain = (tarteaucitron.parameters.cookieDomain !== undefined && tarteaucitron.parameters.cookieDomain !== '') ? 'domain=' + tarteaucitron.parameters.cookieDomain + ';' : '';
  938. d.setTime(expireTime);
  939. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;' + domain;
  940. },
  941. "read": function () {
  942. "use strict";
  943. var nameEQ = tarteaucitron.parameters.cookieName + "=",
  944. ca = document.cookie.split(';'),
  945. i,
  946. c;
  947. for (i = 0; i < ca.length; i += 1) {
  948. c = ca[i];
  949. while (c.charAt(0) === ' ') {
  950. c = c.substring(1, c.length);
  951. }
  952. if (c.indexOf(nameEQ) === 0) {
  953. return c.substring(nameEQ.length, c.length);
  954. }
  955. }
  956. return '';
  957. },
  958. "purge": function (arr) {
  959. "use strict";
  960. var i;
  961. for (i = 0; i < arr.length; i += 1) {
  962. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  963. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  964. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  965. }
  966. },
  967. "checkCount": function (key) {
  968. "use strict";
  969. var arr = tarteaucitron.services[key].cookies,
  970. nb = arr.length,
  971. nbCurrent = 0,
  972. html = '',
  973. i,
  974. status = document.cookie.indexOf(key + '=true');
  975. if (status >= 0 && nb === 0) {
  976. html += tarteaucitron.lang.useNoCookie;
  977. } else if (status >= 0) {
  978. for (i = 0; i < nb; i += 1) {
  979. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  980. nbCurrent += 1;
  981. if (tarteaucitron.cookie.owner[arr[i]] === undefined) {
  982. tarteaucitron.cookie.owner[arr[i]] = [];
  983. }
  984. if (tarteaucitron.cookie.crossIndexOf(tarteaucitron.cookie.owner[arr[i]], tarteaucitron.services[key].name) === false) {
  985. tarteaucitron.cookie.owner[arr[i]].push(tarteaucitron.services[key].name);
  986. }
  987. }
  988. }
  989. if (nbCurrent > 0) {
  990. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  991. if (nbCurrent > 1) {
  992. html += 's';
  993. }
  994. html += '.';
  995. } else {
  996. html += tarteaucitron.lang.useNoCookie;
  997. }
  998. } else if (nb === 0) {
  999. html = tarteaucitron.lang.noCookie;
  1000. } else {
  1001. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  1002. if (nb > 1) {
  1003. html += 's';
  1004. }
  1005. html += '.';
  1006. }
  1007. if (document.getElementById('tacCL' + key) !== null) {
  1008. document.getElementById('tacCL' + key).innerHTML = html;
  1009. }
  1010. },
  1011. "crossIndexOf": function (arr, match) {
  1012. "use strict";
  1013. var i;
  1014. for (i = 0; i < arr.length; i += 1) {
  1015. if (arr[i] === match) {
  1016. return true;
  1017. }
  1018. }
  1019. return false;
  1020. },
  1021. "number": function () {
  1022. "use strict";
  1023. var cookies = document.cookie.split(';'),
  1024. nb = (document.cookie !== '') ? cookies.length : 0,
  1025. html = '',
  1026. i,
  1027. name,
  1028. namea,
  1029. nameb,
  1030. c,
  1031. d,
  1032. s = (nb > 1) ? 's' : '',
  1033. savedname,
  1034. regex = /^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i,
  1035. regexedDomain = (tarteaucitron.cdn.match(regex) !== null) ? tarteaucitron.cdn.match(regex)[1] : tarteaucitron.cdn,
  1036. host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : regexedDomain;
  1037. cookies = cookies.sort(function (a, b) {
  1038. namea = a.split('=', 1).toString().replace(/ /g, '');
  1039. nameb = b.split('=', 1).toString().replace(/ /g, '');
  1040. c = (tarteaucitron.cookie.owner[namea] !== undefined) ? tarteaucitron.cookie.owner[namea] : '0';
  1041. d = (tarteaucitron.cookie.owner[nameb] !== undefined) ? tarteaucitron.cookie.owner[nameb] : '0';
  1042. if (c + a > d + b) { return 1; }
  1043. if (c + a < d + b) { return -1; }
  1044. return 0;
  1045. });
  1046. if (document.cookie !== '') {
  1047. for (i = 0; i < nb; i += 1) {
  1048. name = cookies[i].split('=', 1).toString().replace(/ /g, '');
  1049. if (tarteaucitron.cookie.owner[name] !== undefined && tarteaucitron.cookie.owner[name].join(' // ') !== savedname) {
  1050. savedname = tarteaucitron.cookie.owner[name].join(' // ');
  1051. html += '<div class="tarteaucitronHidden">';
  1052. html += ' <span class="tarteaucitronTitle tarteaucitronH3" role="heading" aria-level="3">';
  1053. html += ' ' + tarteaucitron.cookie.owner[name].join(' // ');
  1054. html += ' </span>';
  1055. html += '</div><ul class="cookie-list">';
  1056. } else if (tarteaucitron.cookie.owner[name] === undefined && host !== savedname) {
  1057. savedname = host;
  1058. html += '<div class="tarteaucitronHidden">';
  1059. html += ' <span class="tarteaucitronTitle tarteaucitronH3" role="heading" aria-level="3">';
  1060. html += ' ' + host;
  1061. html += ' </span>';
  1062. html += '</div><ul class="cookie-list">';
  1063. }
  1064. html += '<li class="tarteaucitronCookiesListMain">';
  1065. html += ' <div class="tarteaucitronCookiesListLeft"><button type="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>';
  1066. html += ' </div>';
  1067. html += ' <div class="tarteaucitronCookiesListRight">' + cookies[i].split('=').slice(1).join('=') + '</div>';
  1068. html += '</li>';
  1069. }
  1070. html += '</ul>';
  1071. } else {
  1072. html += '<div class="tarteaucitronCookiesListMain">';
  1073. html += ' <div class="tarteaucitronCookiesListLeft"><strong>-</strong></div>';
  1074. html += ' <div class="tarteaucitronCookiesListRight"></div>';
  1075. html += '</div>';
  1076. }
  1077. html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
  1078. if (document.getElementById('tarteaucitronCookiesList') !== null) {
  1079. document.getElementById('tarteaucitronCookiesList').innerHTML = html;
  1080. }
  1081. if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
  1082. document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
  1083. }
  1084. if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) {
  1085. document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
  1086. }
  1087. for (i = 0; i < tarteaucitron.job.length; i += 1) {
  1088. tarteaucitron.cookie.checkCount(tarteaucitron.job[i]);
  1089. }
  1090. }
  1091. },
  1092. "getLanguage": function () {
  1093. "use strict";
  1094. if (!navigator) { return 'en'; }
  1095. var availableLanguages = 'cs,en,fr,es,it,de,nl,pt,pl,ru,el',
  1096. defaultLanguage = 'en',
  1097. lang = navigator.language || navigator.browserLanguage ||
  1098. navigator.systemLanguage || navigator.userLang || null,
  1099. userLanguage = lang ? lang.substr(0, 2) : null;
  1100. if (tarteaucitronForceLanguage !== '') {
  1101. if (availableLanguages.indexOf(tarteaucitronForceLanguage) !== -1) {
  1102. return tarteaucitronForceLanguage;
  1103. }
  1104. }
  1105. if (availableLanguages.indexOf(userLanguage) === -1) {
  1106. return defaultLanguage;
  1107. }
  1108. return userLanguage;
  1109. },
  1110. "getLocale": function () {
  1111. "use strict";
  1112. if (!navigator) { return 'en_US'; }
  1113. var lang = navigator.language || navigator.browserLanguage ||
  1114. navigator.systemLanguage || navigator.userLang || null,
  1115. userLanguage = lang ? lang.substr(0, 2) : null;
  1116. if (userLanguage === 'fr') {
  1117. return 'fr_FR';
  1118. } else if (userLanguage === 'en') {
  1119. return 'en_US';
  1120. } else if (userLanguage === 'de') {
  1121. return 'de_DE';
  1122. } else if (userLanguage === 'es') {
  1123. return 'es_ES';
  1124. } else if (userLanguage === 'it') {
  1125. return 'it_IT';
  1126. } else if (userLanguage === 'pt') {
  1127. return 'pt_PT';
  1128. } else if (userLanguage === 'nl') {
  1129. return 'nl_NL';
  1130. } else if (userLanguage === 'el') {
  1131. return 'el_EL';
  1132. } else {
  1133. return 'en_US';
  1134. }
  1135. },
  1136. "addScript": function (url, id, callback, execute, attrName, attrVal) {
  1137. "use strict";
  1138. var script,
  1139. done = false;
  1140. if (execute === false) {
  1141. if (typeof callback === 'function') {
  1142. callback();
  1143. }
  1144. } else {
  1145. script = document.createElement('script');
  1146. script.type = 'text/javascript';
  1147. script.id = (id !== undefined) ? id : '';
  1148. script.async = true;
  1149. script.src = url;
  1150. if (attrName !== undefined && attrVal !== undefined) {
  1151. script.setAttribute(attrName, attrVal);
  1152. }
  1153. if (typeof callback === 'function') {
  1154. script.onreadystatechange = script.onload = function () {
  1155. var state = script.readyState;
  1156. if (!done && (!state || /loaded|complete/.test(state))) {
  1157. done = true;
  1158. callback();
  1159. }
  1160. };
  1161. }
  1162. document.getElementsByTagName('head')[0].appendChild(script);
  1163. }
  1164. },
  1165. "makeAsync": {
  1166. "antiGhost": 0,
  1167. "buffer": '',
  1168. "init": function (url, id) {
  1169. "use strict";
  1170. var savedWrite = document.write,
  1171. savedWriteln = document.writeln;
  1172. document.write = function (content) {
  1173. tarteaucitron.makeAsync.buffer += content;
  1174. };
  1175. document.writeln = function (content) {
  1176. tarteaucitron.makeAsync.buffer += content.concat("\n");
  1177. };
  1178. setTimeout(function () {
  1179. document.write = savedWrite;
  1180. document.writeln = savedWriteln;
  1181. }, 20000);
  1182. tarteaucitron.makeAsync.getAndParse(url, id);
  1183. },
  1184. "getAndParse": function (url, id) {
  1185. "use strict";
  1186. if (tarteaucitron.makeAsync.antiGhost > 9) {
  1187. tarteaucitron.makeAsync.antiGhost = 0;
  1188. return;
  1189. }
  1190. tarteaucitron.makeAsync.antiGhost += 1;
  1191. tarteaucitron.addScript(url, '', function () {
  1192. if (document.getElementById(id) !== null) {
  1193. document.getElementById(id).innerHTML += "<span style='display:none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
  1194. tarteaucitron.makeAsync.buffer = '';
  1195. tarteaucitron.makeAsync.execJS(id);
  1196. }
  1197. });
  1198. },
  1199. "execJS": function (id) {
  1200. /* not strict because third party scripts may have errors */
  1201. var i,
  1202. scripts,
  1203. childId,
  1204. type;
  1205. if (document.getElementById(id) === null) {
  1206. return;
  1207. }
  1208. scripts = document.getElementById(id).getElementsByTagName('script');
  1209. for (i = 0; i < scripts.length; i += 1) {
  1210. type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : '';
  1211. if (type === '') {
  1212. type = (scripts[i].getAttribute('language') !== null) ? scripts[i].getAttribute('language') : '';
  1213. }
  1214. if (scripts[i].getAttribute('src') !== null && scripts[i].getAttribute('src') !== '') {
  1215. childId = id + Math.floor(Math.random() * 99999999999);
  1216. document.getElementById(id).innerHTML += '<div id="' + childId + '"></div>';
  1217. tarteaucitron.makeAsync.getAndParse(scripts[i].getAttribute('src'), childId);
  1218. } else if (type.indexOf('javascript') !== -1 || type === '') {
  1219. eval(scripts[i].innerHTML);
  1220. }
  1221. }
  1222. }
  1223. },
  1224. "fallback": function (matchClass, content, noInner) {
  1225. "use strict";
  1226. var elems = document.getElementsByTagName('*'),
  1227. i,
  1228. index = 0;
  1229. for (i in elems) {
  1230. if (elems[i] !== undefined) {
  1231. for (index = 0; index < matchClass.length; index += 1) {
  1232. if ((' ' + elems[i].className + ' ')
  1233. .indexOf(' ' + matchClass[index] + ' ') > -1) {
  1234. if (typeof content === 'function') {
  1235. if (noInner === true) {
  1236. content(elems[i]);
  1237. } else {
  1238. elems[i].innerHTML = content(elems[i]);
  1239. }
  1240. } else {
  1241. elems[i].innerHTML = content;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. },
  1248. "engage": function (id) {
  1249. "use strict";
  1250. var html = '',
  1251. r = Math.floor(Math.random() * 100000),
  1252. engage = tarteaucitron.services[id].name + ' ' + tarteaucitron.lang.fallback;
  1253. if (tarteaucitron.lang['engage-' + id] !== undefined) {
  1254. engage = tarteaucitron.lang['engage-' + id];
  1255. }
  1256. html += '<div class="tac_activate">';
  1257. html += ' <div class="tac_float">';
  1258. html += ' ' + engage;
  1259. html += ' <button type="button" class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
  1260. html += ' &#10003; ' + tarteaucitron.lang.allow;
  1261. html += ' </button>';
  1262. html += ' </div>';
  1263. html += '</div>';
  1264. return html;
  1265. },
  1266. "extend": function (a, b) {
  1267. "use strict";
  1268. var prop;
  1269. for (prop in b) {
  1270. if (b.hasOwnProperty(prop)) {
  1271. a[prop] = b[prop];
  1272. }
  1273. }
  1274. },
  1275. "proTemp": '',
  1276. "proTimer": function () {
  1277. "use strict";
  1278. setTimeout(tarteaucitron.proPing, 500);
  1279. },
  1280. "pro": function (list) {
  1281. "use strict";
  1282. tarteaucitron.proTemp += list;
  1283. clearTimeout(tarteaucitron.proTimer);
  1284. tarteaucitron.proTimer = setTimeout(tarteaucitron.proPing, 500);
  1285. },
  1286. "proPing": function () {
  1287. "use strict";
  1288. if (tarteaucitron.uuid !== '' && tarteaucitron.uuid !== undefined && tarteaucitron.proTemp !== '') {
  1289. var div = document.getElementById('tarteaucitronPremium'),
  1290. timestamp = new Date().getTime(),
  1291. url = 'https://opt-out.ferank.eu/premium.php?';
  1292. if (div === null) {
  1293. return;
  1294. }
  1295. url += 'domain=' + tarteaucitron.domain + '&';
  1296. url += 'uuid=' + tarteaucitron.uuid + '&';
  1297. url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
  1298. url += '_' + timestamp;
  1299. div.innerHTML = '<img src="' + url + '" style="display:none" />';
  1300. tarteaucitron.proTemp = '';
  1301. }
  1302. tarteaucitron.cookie.number();
  1303. },
  1304. "AddOrUpdate" : function(source, custom){
  1305. /**
  1306. Utility function to Add or update the fields of obj1 with the ones in obj2
  1307. */
  1308. for(key in custom){
  1309. if(custom[key] instanceof Object){
  1310. source[key] = tarteaucitron.AddOrUpdate(source[key], custom[key]);
  1311. }else{
  1312. source[key] = custom[key];
  1313. }
  1314. }
  1315. return source;
  1316. },
  1317. "getElemWidth": function(elem) {
  1318. return elem.getAttribute('width') || elem.clientWidth;
  1319. },
  1320. "getElemHeight": function(elem) {
  1321. return elem.getAttribute('height') || elem.clientHeight;
  1322. }
  1323. };