tarteaucitron.js 33 KB

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