tarteaucitron.js 40 KB

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