tarteaucitron.js 40 KB

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