tarteaucitron.js 65 KB

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