tarteaucitron.js 49 KB

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