tarteaucitron.js 35 KB

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