tarteaucitron.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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,
  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": true,
  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"><div id="tarteaucitronCookiesList"></div></div>';
  214. } else {
  215. html += ' </div>';
  216. }
  217. html += '</div>';
  218. }
  219. tarteaucitron.addScript(tarteaucitron.cdn + 'advertising.js?v=' + tarteaucitron.version, '', function () {
  220. if (tarteaucitronNoAdBlocker === true || defaults.adblocker === false) {
  221. div.id = 'tarteaucitronRoot';
  222. body.appendChild(div, body);
  223. div.innerHTML = html;
  224. if (tarteaucitron.job !== undefined) {
  225. tarteaucitron.job = tarteaucitron.cleanArray(tarteaucitron.job);
  226. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  227. tarteaucitron.addService(tarteaucitron.job[index]);
  228. }
  229. }
  230. tarteaucitron.isAjax = true;
  231. tarteaucitron.job.push = function (id) {
  232. // ie <9 hack
  233. if (typeof tarteaucitron.job.indexOf === 'undefined') {
  234. tarteaucitron.job.indexOf = function (obj, start) {
  235. var i,
  236. j = this.length;
  237. for (i = (start || 0); i < j; i += 1) {
  238. if (this[i] === obj) { return i; }
  239. }
  240. return -1;
  241. };
  242. }
  243. if (tarteaucitron.job.indexOf(id) === -1) {
  244. Array.prototype.push.call(this, id);
  245. }
  246. tarteaucitron.launch[id] = false;
  247. tarteaucitron.addService(id);
  248. };
  249. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  250. tarteaucitron.userInterface.openPanel();
  251. }
  252. tarteaucitron.cookie.number();
  253. setInterval(tarteaucitron.cookie.number, 60000);
  254. }
  255. });
  256. if (defaults.adblocker === true) {
  257. setTimeout(function () {
  258. if (tarteaucitronNoAdBlocker === false) {
  259. html = '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '" style="display:block">';
  260. html += ' <span id="tarteaucitronDisclaimerAlert">';
  261. html += ' ' + tarteaucitron.lang.adblock + '<br/>';
  262. html += ' <b>' + tarteaucitron.lang.adblock_call + '</b>';
  263. html += ' </span>';
  264. html += ' <span id="tarteaucitronPersonalize" onclick="location.reload();">';
  265. html += ' ' + tarteaucitron.lang.reload;
  266. html += ' </span>';
  267. html += '</div>';
  268. div.id = 'tarteaucitronRoot';
  269. body.appendChild(div, body);
  270. div.innerHTML = html;
  271. }
  272. }, 1500);
  273. }
  274. });
  275. });
  276. },
  277. "addService": function (serviceId) {
  278. "use strict";
  279. var html = '',
  280. s = tarteaucitron.services,
  281. service = s[serviceId],
  282. cookie = tarteaucitron.cookie.read(),
  283. hostname = document.location.hostname,
  284. hostRef = document.referrer.split('/')[2],
  285. isNavigating = (hostRef === hostname) ? true : false,
  286. isAutostart = (!service.needConsent) ? true : false,
  287. isWaiting = (cookie.indexOf(service.key + '=wait') >= 0) ? true : false,
  288. isDenied = (cookie.indexOf(service.key + '=false') >= 0) ? true : false,
  289. isAllowed = (cookie.indexOf(service.key + '=true') >= 0) ? true : false,
  290. isResponded = (cookie.indexOf(service.key + '=false') >= 0 || cookie.indexOf(service.key + '=true') >= 0) ? true : false;
  291. if (tarteaucitron.added[service.key] !== true) {
  292. tarteaucitron.added[service.key] = true;
  293. html += '<div id="' + service.key + 'Line" class="tarteaucitronLine">';
  294. html += ' <div class="tarteaucitronName">';
  295. html += ' <b>' + service.name + '</b><br/>';
  296. html += ' <span id="tacCL' + service.key + '" class="tarteaucitronListCookies"></span><br/>';
  297. html += ' <a href="https://opt-out.ferank.eu/service/' + service.key + '/" target="_blank">';
  298. html += ' ' + tarteaucitron.lang.more;
  299. html += ' </a>';
  300. html += ' - ';
  301. html += ' <a href="' + service.uri + '" target="_blank">';
  302. html += ' ' + tarteaucitron.lang.source;
  303. html += ' </a>';
  304. html += ' </div>';
  305. html += ' <div class="tarteaucitronAsk">';
  306. html += ' <div id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  307. html += ' ' + tarteaucitron.lang.allow;
  308. html += ' </div> ';
  309. html += ' <div id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  310. html += ' ' + tarteaucitron.lang.deny;
  311. html += ' </div>';
  312. html += ' </div>';
  313. html += '</div>';
  314. tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
  315. if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
  316. document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
  317. }
  318. tarteaucitron.userInterface.order(service.type);
  319. }
  320. // allow by default for non EU
  321. if (isResponded === false && tarteaucitron.user.bypass === true) {
  322. isAllowed = true;
  323. tarteaucitron.cookie.create(service.key, true);
  324. }
  325. if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
  326. if (!isAllowed) {
  327. tarteaucitron.cookie.create(service.key, true);
  328. }
  329. if (tarteaucitron.launch[service.key] !== true) {
  330. tarteaucitron.launch[service.key] = true;
  331. service.js();
  332. }
  333. tarteaucitron.state[service.key] = true;
  334. tarteaucitron.userInterface.color(service.key, true);
  335. } else if (isDenied) {
  336. if (typeof service.fallback === 'function') {
  337. service.fallback();
  338. }
  339. tarteaucitron.state[service.key] = false;
  340. tarteaucitron.userInterface.color(service.key, false);
  341. } else if (!isResponded) {
  342. tarteaucitron.cookie.create(service.key, 'wait');
  343. if (typeof service.fallback === 'function') {
  344. service.fallback();
  345. }
  346. tarteaucitron.userInterface.color(service.key, 'wait');
  347. tarteaucitron.userInterface.openAlert();
  348. }
  349. tarteaucitron.cookie.checkCount(service.key);
  350. },
  351. "cleanArray": function cleanArray(arr) {
  352. "use strict";
  353. var i,
  354. len = arr.length,
  355. out = [],
  356. obj = {},
  357. s = tarteaucitron.services;
  358. for (i = 0; i < len; i += 1) {
  359. if (!obj[arr[i]]) {
  360. obj[arr[i]] = {};
  361. if (tarteaucitron.services[arr[i]] !== undefined) {
  362. out.push(arr[i]);
  363. }
  364. }
  365. }
  366. out = out.sort(function (a, b) {
  367. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  368. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  369. return 0;
  370. });
  371. return out;
  372. },
  373. "userInterface": {
  374. "css": function (id, property, value) {
  375. "use strict";
  376. if (document.getElementById(id) !== null) {
  377. document.getElementById(id).style[property] = value;
  378. }
  379. },
  380. "respondAll": function (status) {
  381. "use strict";
  382. var s = tarteaucitron.services,
  383. service,
  384. key,
  385. index = 0;
  386. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  387. service = s[tarteaucitron.job[index]];
  388. key = service.key;
  389. if (tarteaucitron.state[key] !== status) {
  390. if (tarteaucitron.launch[key] !== true && status === true) {
  391. tarteaucitron.launch[key] = true;
  392. tarteaucitron.services[key].js();
  393. }
  394. tarteaucitron.state[key] = status;
  395. tarteaucitron.cookie.create(key, status);
  396. tarteaucitron.userInterface.color(key, status);
  397. }
  398. }
  399. },
  400. "respond": function (el, status) {
  401. "use strict";
  402. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  403. // return if same state
  404. if (tarteaucitron.state[key] === status) {
  405. return;
  406. }
  407. // if not already launched... launch the service
  408. if (status === true) {
  409. if (tarteaucitron.launch[key] !== true) {
  410. tarteaucitron.launch[key] = true;
  411. tarteaucitron.services[key].js();
  412. }
  413. }
  414. tarteaucitron.state[key] = status;
  415. tarteaucitron.cookie.create(key, status);
  416. tarteaucitron.userInterface.color(key, status);
  417. },
  418. "color": function (key, status) {
  419. "use strict";
  420. var gray = '#808080',
  421. greenDark = '#1B870B',
  422. greenLight = '#E6FFE2',
  423. redDark = '#9C1A1A',
  424. redLight = '#FFE2E2',
  425. yellowDark = '#FBDA26',
  426. c = 'tarteaucitron',
  427. nbDenied = 0,
  428. nbPending = 0,
  429. nbAllowed = 0,
  430. sum = tarteaucitron.job.length,
  431. index;
  432. if (status === true) {
  433. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  434. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  435. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  436. } else if (status === false) {
  437. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  438. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  439. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  440. }
  441. // check if all services are allowed
  442. for (index = 0; index < sum; index += 1) {
  443. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  444. nbDenied += 1;
  445. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  446. nbPending += 1;
  447. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  448. nbAllowed += 1;
  449. }
  450. }
  451. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  452. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  453. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  454. if (nbDenied === 0 && nbPending === 0) {
  455. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  456. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  457. } else if (nbAllowed === 0 && nbPending === 0) {
  458. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  459. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  460. } else {
  461. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  462. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  463. }
  464. // close the alert if all service have been reviewed
  465. if (nbPending === 0) {
  466. tarteaucitron.userInterface.closeAlert();
  467. }
  468. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  469. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  470. }
  471. if (status === true) {
  472. if (document.getElementById('tacCL' + key) !== null) {
  473. document.getElementById('tacCL' + key).innerHTML = '...';
  474. }
  475. setTimeout(function () {
  476. tarteaucitron.cookie.checkCount(key);
  477. }, 2500);
  478. } else {
  479. tarteaucitron.cookie.checkCount(key);
  480. }
  481. },
  482. "openPanel": function () {
  483. "use strict";
  484. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  485. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  486. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  487. },
  488. "closePanel": function () {
  489. "use strict";
  490. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  491. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  492. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  493. if (document.location.hash === tarteaucitron.hashtag) {
  494. document.location.hash = '';
  495. }
  496. },
  497. "openAlert": function () {
  498. "use strict";
  499. var c = 'tarteaucitron';
  500. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  501. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  502. },
  503. "closeAlert": function () {
  504. "use strict";
  505. var c = 'tarteaucitron';
  506. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  507. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  508. },
  509. "toggleCookiesList": function () {
  510. "use strict";
  511. var div = document.getElementById('tarteaucitronCookiesListContainer');
  512. if (div === null) {
  513. return;
  514. }
  515. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (parseInt(document.getElementById('tarteaucitronAlertSmall').offsetHeight, 10) + 10) + 'px');
  516. if (div.style.display !== 'block') {
  517. tarteaucitron.cookie.number();
  518. div.style.display = 'block';
  519. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  520. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  521. } else {
  522. div.style.display = 'none';
  523. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  524. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  525. }
  526. },
  527. "order": function (id) {
  528. "use strict";
  529. var main = document.getElementById('tarteaucitronServices_' + id),
  530. allDivs = main.childNodes,
  531. store = [],
  532. i;
  533. if (main === null) {
  534. return;
  535. }
  536. if (typeof Array.prototype.map === 'function') {
  537. Array.prototype.map.call(main.children, Object).sort(function (a, b) {
  538. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
  539. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; }
  540. return 0;
  541. }).forEach(function (element) {
  542. main.appendChild(element);
  543. });
  544. }
  545. }
  546. },
  547. "cookie": {
  548. "owner": {},
  549. "create": function (key, status) {
  550. "use strict";
  551. var d = new Date(),
  552. time = d.getTime(),
  553. expireTime = time + 31536000000, // 365 days
  554. regex = new RegExp("!" + key + "=(wait|true|false)", "g"),
  555. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  556. value = 'tarteaucitron=' + cookie + '!' + key + '=' + status;
  557. if (tarteaucitron.cookie.read().indexOf(key + '=' + status) === -1) {
  558. tarteaucitron.pro('!' + key + '=' + status);
  559. }
  560. d.setTime(expireTime);
  561. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;';
  562. },
  563. "read": function () {
  564. "use strict";
  565. var nameEQ = "tarteaucitron=",
  566. ca = document.cookie.split(';'),
  567. i,
  568. c;
  569. for (i = 0; i < ca.length; i += 1) {
  570. c = ca[i];
  571. while (c.charAt(0) === ' ') {
  572. c = c.substring(1, c.length);
  573. }
  574. if (c.indexOf(nameEQ) === 0) {
  575. return c.substring(nameEQ.length, c.length);
  576. }
  577. }
  578. return '';
  579. },
  580. "purge": function (arr) {
  581. "use strict";
  582. var i;
  583. for (i = 0; i < arr.length; i += 1) {
  584. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  585. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  586. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  587. }
  588. },
  589. "checkCount": function (key) {
  590. "use strict";
  591. var arr = tarteaucitron.services[key].cookies,
  592. nb = arr.length,
  593. nbCurrent = 0,
  594. html = '',
  595. i,
  596. status = document.cookie.indexOf(key + '=true');
  597. if (status >= 0 && nb === 0) {
  598. html += tarteaucitron.lang.useNoCookie;
  599. } else if (status >= 0) {
  600. for (i = 0; i < nb; i += 1) {
  601. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  602. nbCurrent += 1;
  603. if (tarteaucitron.cookie.owner[arr[i]] === undefined) {
  604. tarteaucitron.cookie.owner[arr[i]] = [];
  605. }
  606. if (tarteaucitron.cookie.crossIndexOf(tarteaucitron.cookie.owner[arr[i]], tarteaucitron.services[key].name) === false) {
  607. tarteaucitron.cookie.owner[arr[i]].push(tarteaucitron.services[key].name);
  608. }
  609. }
  610. }
  611. if (nbCurrent > 0) {
  612. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  613. if (nbCurrent > 1) {
  614. html += 's';
  615. }
  616. html += '.';
  617. } else {
  618. html += tarteaucitron.lang.useNoCookie;
  619. }
  620. } else if (nb === 0) {
  621. html = tarteaucitron.lang.noCookie;
  622. } else {
  623. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  624. if (nb > 1) {
  625. html += 's';
  626. }
  627. html += '.';
  628. }
  629. if (document.getElementById('tacCL' + key) !== null) {
  630. document.getElementById('tacCL' + key).innerHTML = html;
  631. }
  632. tarteaucitron.cookie.number();
  633. },
  634. "crossIndexOf": function (arr, match) {
  635. "use strict";
  636. var i;
  637. for (i = 0; i < arr.length; i += 1) {
  638. if (arr[i] === match) {
  639. return true;
  640. }
  641. }
  642. return false;
  643. },
  644. "number": function () {
  645. "use strict";
  646. var cookies = document.cookie.split(';'),
  647. nb = (document.cookie !== '') ? cookies.length : 0,
  648. html = '',
  649. i,
  650. s = (nb > 1) ? 's' : '',
  651. name;
  652. cookies = cookies.sort(function (a, b) {
  653. if (a > b) { return 1; }
  654. if (a < b) { return -1; }
  655. return 0;
  656. });
  657. html += '<div class="tarteaucitronCookiesListMain" id="tarteaucitronCookiesTitle">';
  658. html += ' <b>' + nb + ' cookie' + s + '</b>';
  659. html += '</div>';
  660. if (document.cookie !== '') {
  661. for (i = 0; i < nb; i += 1) {
  662. name = cookies[i].split('=', 1).toString().replace(/ /g, '');
  663. html += '<div class="tarteaucitronCookiesListMain">';
  664. html += ' <div class="tarteaucitronCookiesListLeft"><a href="#" onclick="tarteaucitron.cookie.purge([\'' + cookies[i].split('=', 1) + '\']);tarteaucitron.cookie.number();return false">[x]</a> <b>' + name + '</b>';
  665. if (tarteaucitron.cookie.owner[name] !== undefined) {
  666. html += ' <br/>' + tarteaucitron.cookie.owner[name].join('<br/>');
  667. }
  668. html += ' </div>';
  669. html += ' <div class="tarteaucitronCookiesListRight">' + cookies[i].split('=').slice(1).join('=') + '</div>';
  670. html += '</div>';
  671. }
  672. } else {
  673. html += '<div class="tarteaucitronCookiesListMain">';
  674. html += ' <div class="tarteaucitronCookiesListLeft"><b>-</b></div>';
  675. html += ' <div class="tarteaucitronCookiesListRight"></div>';
  676. html += '</div>';
  677. }
  678. if (document.getElementById('tarteaucitronCookiesList') !== null) {
  679. document.getElementById('tarteaucitronCookiesList').innerHTML = html;
  680. }
  681. if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
  682. document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
  683. }
  684. }
  685. },
  686. "getLanguage": function () {
  687. "use strict";
  688. if (!navigator) { return 'en'; }
  689. var availableLanguages = 'en,fr,es,it,de,pt,pl',
  690. defaultLanguage = 'en',
  691. lang = navigator.language || navigator.browserLanguage ||
  692. navigator.systemLanguage || navigator.userLang || null,
  693. userLanguage = lang.substr(0, 2);
  694. if (tarteaucitronForceLanguage !== '') {
  695. if (availableLanguages.indexOf(tarteaucitronForceLanguage) !== -1) {
  696. return tarteaucitronForceLanguage;
  697. }
  698. }
  699. if (availableLanguages.indexOf(userLanguage) === -1) {
  700. return defaultLanguage;
  701. }
  702. return userLanguage;
  703. },
  704. "getLocale": function () {
  705. "use strict";
  706. if (!navigator) { return 'en_US'; }
  707. var lang = navigator.language || navigator.browserLanguage ||
  708. navigator.systemLanguage || navigator.userLang || null,
  709. userLanguage = lang.substr(0, 2);
  710. if (userLanguage === 'fr') {
  711. return 'fr_FR';
  712. } else if (userLanguage === 'en') {
  713. return 'en_US';
  714. } else if (userLanguage === 'de') {
  715. return 'de_DE';
  716. } else if (userLanguage === 'es') {
  717. return 'es_ES';
  718. } else if (userLanguage === 'it') {
  719. return 'it_IT';
  720. } else if (userLanguage === 'pt') {
  721. return 'pt_PT';
  722. } else {
  723. return 'en_US';
  724. }
  725. },
  726. "addScript": function (url, id, callback) {
  727. "use strict";
  728. var script = document.createElement('script'),
  729. done = false;
  730. script.type = 'text/javascript';
  731. script.id = (id !== undefined) ? id : '';
  732. script.async = true;
  733. script.src = url;
  734. if (typeof callback === 'function') {
  735. script.onreadystatechange = script.onload = function () {
  736. var state = script.readyState;
  737. if (!done && (!state || /loaded|complete/.test(state))) {
  738. done = true;
  739. callback();
  740. }
  741. };
  742. }
  743. document.getElementsByTagName('head')[0].appendChild(script);
  744. },
  745. "makeAsync": {
  746. "antiGhost": 0,
  747. "buffer": '',
  748. "init": function (url, id) {
  749. "use strict";
  750. var savedWrite = document.write,
  751. savedWriteln = document.writeln;
  752. document.write = function (content) {
  753. tarteaucitron.makeAsync.buffer += content;
  754. };
  755. document.writeln = function (content) {
  756. tarteaucitron.makeAsync.buffer += content.concat("\n");
  757. };
  758. setTimeout(function () {
  759. document.write = savedWrite;
  760. document.writeln = savedWriteln;
  761. }, 20000);
  762. tarteaucitron.makeAsync.getAndParse(url, id);
  763. },
  764. "getAndParse": function (url, id) {
  765. "use strict";
  766. if (tarteaucitron.makeAsync.antiGhost > 9) {
  767. tarteaucitron.makeAsync.antiGhost = 0;
  768. return;
  769. }
  770. tarteaucitron.makeAsync.antiGhost += 1;
  771. tarteaucitron.addScript(url, '', function () {
  772. if (document.getElementById(id) !== null) {
  773. document.getElementById(id).innerHTML += "<span style='display:none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
  774. tarteaucitron.makeAsync.buffer = '';
  775. tarteaucitron.makeAsync.execJS(id);
  776. }
  777. });
  778. },
  779. "execJS": function (id) {
  780. /* not strict because third party scripts may have errors */
  781. var i,
  782. scripts,
  783. childId,
  784. type;
  785. if (document.getElementById(id) === null) {
  786. return;
  787. }
  788. scripts = document.getElementById(id).getElementsByTagName('script');
  789. for (i = 0; i < scripts.length; i += 1) {
  790. type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : '';
  791. if (type === '') {
  792. type = (scripts[i].getAttribute('language') !== null) ? scripts[i].getAttribute('language') : '';
  793. }
  794. if (scripts[i].getAttribute('src') !== null && scripts[i].getAttribute('src') !== '') {
  795. childId = id + Math.floor(Math.random() * 99999999999);
  796. document.getElementById(id).innerHTML += '<div id="' + childId + '"></div>';
  797. tarteaucitron.makeAsync.getAndParse(scripts[i].getAttribute('src'), childId);
  798. } else if (type.indexOf('javascript') !== -1 || type === '') {
  799. eval(scripts[i].innerHTML);
  800. }
  801. }
  802. }
  803. },
  804. "fallback": function (matchClass, content) {
  805. "use strict";
  806. var elems = document.getElementsByTagName('*'),
  807. i,
  808. index = 0;
  809. for (i in elems) {
  810. if (elems[i] !== undefined) {
  811. for (index = 0; index < matchClass.length; index += 1) {
  812. if ((' ' + elems[i].className + ' ')
  813. .indexOf(' ' + matchClass[index] + ' ') > -1) {
  814. if (typeof content === 'function') {
  815. elems[i].innerHTML = content(elems[i]);
  816. } else {
  817. elems[i].innerHTML = content;
  818. }
  819. }
  820. }
  821. }
  822. }
  823. },
  824. "engage": function (id) {
  825. "use strict";
  826. var html = '',
  827. r = Math.floor(Math.random() * 100000);
  828. html += '<div class="tac_activate">';
  829. html += ' <div class="tac_float">';
  830. html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback;
  831. html += ' <div class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
  832. html += ' ' + tarteaucitron.lang.allow;
  833. html += ' </div>';
  834. html += ' </div>';
  835. html += '</div>';
  836. return html;
  837. },
  838. "extend": function (a, b) {
  839. "use strict";
  840. var prop;
  841. for (prop in b) {
  842. if (b.hasOwnProperty(prop)) {
  843. a[prop] = b[prop];
  844. }
  845. }
  846. },
  847. "proTemp": '',
  848. "proTimer": function () {
  849. "use strict";
  850. setTimeout(tarteaucitron.proPing, 1000);
  851. },
  852. "pro": function (list) {
  853. "use strict";
  854. tarteaucitron.proTemp += list;
  855. clearTimeout(tarteaucitron.proTimer);
  856. tarteaucitron.proTimer = setTimeout(tarteaucitron.proPing, 2500);
  857. },
  858. "proPing": function () {
  859. "use strict";
  860. if (tarteaucitron.uuid !== '' && tarteaucitron.uuid !== undefined && tarteaucitron.proTemp !== '') {
  861. var div = document.getElementById('tarteaucitronPremium'),
  862. timestamp = new Date().getTime(),
  863. url = '//opt-out.ferank.eu/premium.php?';
  864. if (div === null) {
  865. return;
  866. }
  867. url += 'domain=' + tarteaucitron.domain + '&';
  868. url += 'uuid=' + tarteaucitron.uuid + '&';
  869. url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
  870. url += '_' + timestamp;
  871. div.innerHTML = '<img src="' + url + '" style="display:none" />';
  872. tarteaucitron.proTemp = '';
  873. }
  874. }
  875. };