tarteaucitron.js 33 KB

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