tarteaucitron.js 63 KB

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