tarteaucitron.js 65 KB

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