tarteaucitron.js 36 KB

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