tarteaucitron.js 43 KB

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