tarteaucitron.js 37 KB

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