tarteaucitron.js 49 KB

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