tarteaucitron.js 34 KB

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