tarteaucitron.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*jslint browser: 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. var tarteaucitron = {
  8. "cdn": cdn,
  9. "user": {},
  10. "lang": {},
  11. "services": {},
  12. "state": [],
  13. "launch": [],
  14. "init": function (params) {
  15. "use strict";
  16. if (alreadyLaunch === 0) {
  17. alreadyLaunch = 1;
  18. if (window.addEventListener) {
  19. window.addEventListener("load", tarteaucitron.load(params), false);
  20. } else {
  21. window.attachEvent('onload', tarteaucitron.load(params));
  22. }
  23. }
  24. },
  25. "load": function (params) {
  26. "use strict";
  27. var cdn = tarteaucitron.cdn,
  28. language = tarteaucitron.getLanguage(),
  29. pathToLang = cdn + 'lang/tarteaucitron.' + language + '.js',
  30. pathToServices = cdn + 'tarteaucitron.services.js',
  31. linkElement = document.createElement('link'),
  32. defaults = {
  33. "hashtag": '#tarteaucitron',
  34. "highPrivacy": false,
  35. "orientation": "top",
  36. "removeCredit": false,
  37. "showAlertSmall": true
  38. };
  39. // Step 0: get params
  40. if (params !== undefined) {
  41. tarteaucitron.extend(defaults, params);
  42. }
  43. // the hashtag need to be global
  44. tarteaucitron.hashtag = defaults.hashtag;
  45. // Step 1: load css
  46. linkElement.rel = 'stylesheet';
  47. linkElement.type = 'text/css';
  48. linkElement.href = cdn + 'css/tarteaucitron.css';
  49. document.getElementsByTagName('head')[0].appendChild(linkElement);
  50. // Step 2: load language and services
  51. tarteaucitron.addScript(pathToLang, '', function () {
  52. tarteaucitron.addScript(pathToServices, '', function () {
  53. var body = document.body,
  54. div = document.createElement('div'),
  55. hostname = document.location.hostname,
  56. hostRef = document.referrer.split('/')[2],
  57. isNavigating = (hostRef === hostname) ? true : false,
  58. isAutostart,
  59. isDenied,
  60. isAllowed,
  61. isResponded,
  62. cookie = tarteaucitron.cookie.read(),
  63. s = tarteaucitron.services,
  64. service,
  65. html = '',
  66. lastTitle,
  67. alert = false,
  68. index,
  69. orientation = 'Top';
  70. // dedup, clean and sort job[]
  71. function cleanArray(arr) {
  72. var i,
  73. len = arr.length,
  74. out = [],
  75. obj = {};
  76. for (i = 0; i < len; i += 1) {
  77. if (!obj[arr[i]]) {
  78. obj[arr[i]] = {};
  79. if (tarteaucitron.services[arr[i]] !== undefined) {
  80. out.push(arr[i]);
  81. }
  82. }
  83. }
  84. return out;
  85. }
  86. if (tarteaucitron.job === undefined) {
  87. return;
  88. }
  89. tarteaucitron.job = cleanArray(tarteaucitron.job);
  90. tarteaucitron.job = tarteaucitron.job.sort(function (a, b) {
  91. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  92. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  93. return 0;
  94. });
  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. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  124. service = s[tarteaucitron.job[index]];
  125. if (lastTitle !== service.type) {
  126. html += '<div class="tarteaucitronTitle">';
  127. html += ' ' + tarteaucitron.lang[service.type].title;
  128. html += ' <div class="tarteaucitronDetails">';
  129. html += ' ' + tarteaucitron.lang[service.type].details;
  130. html += ' </div>';
  131. html += '</div>';
  132. lastTitle = service.type;
  133. }
  134. html += '<div id="' + service.key + 'Line" class="tarteaucitronLine">';
  135. html += ' <div class="tarteaucitronName">';
  136. html += ' <b>' + service.name + '</b><br/>';
  137. html += ' <span id="tacCL' + service.key + '" class="tarteaucitronListCookies"></span><br/>';
  138. html += ' <a href="https://opt-out.ferank.eu/' + language + '/service/' + service.key + '/" target="_blank">';
  139. html += ' ' + tarteaucitron.lang.more;
  140. html += ' </a>';
  141. html += ' - ';
  142. html += ' <a href="' + service.uri + '" target="_blank">';
  143. html += ' ' + tarteaucitron.lang.source;
  144. html += ' </a>';
  145. html += ' </div>';
  146. html += ' <div class="tarteaucitronAsk">';
  147. html += ' <div id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  148. html += ' ' + tarteaucitron.lang.allow;
  149. html += ' </div> ';
  150. html += ' <div id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  151. html += ' ' + tarteaucitron.lang.deny;
  152. html += ' </div>';
  153. html += ' </div>';
  154. html += '</div>';
  155. html += '<div class="clear"></div>';
  156. }
  157. html += ' </div>';
  158. if (defaults.removeCredit === false) {
  159. html += ' <div id="tarteaucitronFooter">';
  160. html += ' <a href="https://opt-out.ferank.eu/" rel="nofollow" target="_blank">' + tarteaucitron.lang.credit + '</a>';
  161. html += ' </div>';
  162. }
  163. html += '</div>';
  164. // get the banner orientation
  165. if (defaults.orientation === 'bottom') {
  166. orientation = 'Bottom';
  167. }
  168. if (defaults.highPrivacy) {
  169. html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
  170. html += ' <span id="tarteaucitronDisclaimerAlert">';
  171. html += ' ' + tarteaucitron.lang.alertBigPrivacy;
  172. html += ' </span>';
  173. html += ' <span id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.openPanel();">';
  174. html += ' ' + tarteaucitron.lang.personalize;
  175. html += ' </span>';
  176. html += '</div>';
  177. } else {
  178. html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
  179. html += ' <span id="tarteaucitronDisclaimerAlert">';
  180. html += ' ' + tarteaucitron.lang.alertBig;
  181. html += ' </span>';
  182. html += ' <span id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.respondAll(true);">';
  183. html += ' ' + tarteaucitron.lang.acceptAll;
  184. html += ' </span>';
  185. html += ' <span id="tarteaucitronCloseAlert" onclick="tarteaucitron.userInterface.openPanel();">';
  186. html += ' ' + tarteaucitron.lang.personalize;
  187. html += ' </span>';
  188. html += '</div>';
  189. }
  190. if (defaults.showAlertSmall === true) {
  191. html += '<div id="tarteaucitronAlertSmall" onclick="tarteaucitron.userInterface.openPanel();">';
  192. html += ' ' + tarteaucitron.lang.alertSmall;
  193. html += ' <div id="tarteaucitronDot">';
  194. html += ' <span id="tarteaucitronDotGreen"></span>';
  195. html += ' <span id="tarteaucitronDotYellow"></span>';
  196. html += ' <span id="tarteaucitronDotRed"></span>';
  197. html += ' </div>';
  198. html += '</div>';
  199. }
  200. div.id = 'tarteaucitronRoot';
  201. body.appendChild(div, body);
  202. div.innerHTML = html;
  203. // Step 4: load services
  204. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  205. service = s[tarteaucitron.job[index]];
  206. isAutostart = (!service.needConsent) ? true : false;
  207. isDenied = (cookie.indexOf(service.key + '=false') >= 0) ? true : false;
  208. isAllowed = (cookie.indexOf(service.key + '=true') >= 0) ? true : false;
  209. isResponded = (cookie.indexOf(service.key) >= 0) ? true : false;
  210. // allow by default for non EU
  211. if (isResponded === false && tarteaucitron.user.bypass === true) {
  212. isAllowed = true;
  213. tarteaucitron.cookie.create(service.key, true);
  214. }
  215. if ((!isResponded && (isAutostart || isNavigating) && !defaults.highPrivacy) || isAllowed) {
  216. if (!isAllowed) {
  217. tarteaucitron.cookie.create(service.key, true);
  218. }
  219. if (tarteaucitron.launch[service.key] !== true) {
  220. tarteaucitron.launch[service.key] = true;
  221. service.js();
  222. }
  223. tarteaucitron.state[service.key] = true;
  224. tarteaucitron.userInterface.color(service.key, true);
  225. } else if (isDenied) {
  226. if (typeof service.fallback === 'function') {
  227. service.fallback();
  228. }
  229. tarteaucitron.state[service.key] = false;
  230. tarteaucitron.userInterface.color(service.key, false);
  231. } else if (!isResponded) {
  232. if (typeof service.fallback === 'function') {
  233. service.fallback();
  234. }
  235. }
  236. if (tarteaucitron.state[service.key] === undefined && !alert) {
  237. alert = true;
  238. }
  239. tarteaucitron.cookie.checkCount(service.key);
  240. }
  241. // Step 5: display the alert
  242. if (alert) {
  243. tarteaucitron.userInterface.openAlert();
  244. } else {
  245. tarteaucitron.userInterface.closeAlert();
  246. }
  247. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  248. tarteaucitron.userInterface.openPanel();
  249. }
  250. });
  251. });
  252. },
  253. "userInterface": {
  254. "css": function (id, property, value) {
  255. "use strict";
  256. if (document.getElementById(id) !== null) {
  257. document.getElementById(id).style[property] = value;
  258. }
  259. },
  260. "respondAll": function (status) {
  261. "use strict";
  262. var s = tarteaucitron.services,
  263. service,
  264. key,
  265. index = 0;
  266. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  267. service = s[tarteaucitron.job[index]];
  268. key = service.key;
  269. if (tarteaucitron.launch[key] !== true && status === true) {
  270. tarteaucitron.launch[key] = true;
  271. tarteaucitron.services[key].js();
  272. }
  273. tarteaucitron.state[key] = status;
  274. tarteaucitron.cookie.create(key, status);
  275. tarteaucitron.userInterface.color(key, status);
  276. }
  277. },
  278. "respond": function (el, status) {
  279. "use strict";
  280. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  281. // return if same state
  282. if (tarteaucitron.state[key] === status) {
  283. return;
  284. }
  285. // if not already launched... launch the service
  286. if (status === true) {
  287. if (tarteaucitron.launch[key] !== true) {
  288. tarteaucitron.launch[key] = true;
  289. tarteaucitron.services[key].js();
  290. }
  291. }
  292. tarteaucitron.state[key] = status;
  293. tarteaucitron.cookie.create(key, status);
  294. tarteaucitron.userInterface.color(key, status);
  295. },
  296. "color": function (key, status) {
  297. "use strict";
  298. var gray = '#808080',
  299. greenDark = '#1B870B',
  300. greenLight = '#E6FFE2',
  301. redDark = '#9C1A1A',
  302. redLight = '#FFE2E2',
  303. yellowDark = '#FBDA26',
  304. c = 'tarteaucitron',
  305. nbDenied = 0,
  306. nbPending = 0,
  307. nbAllowed = 0,
  308. sum = tarteaucitron.job.length,
  309. index;
  310. if (status === true) {
  311. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  312. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  313. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  314. } else if (status === false) {
  315. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  316. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  317. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  318. }
  319. // check if all services are allowed
  320. for (index = 0; index < sum; index += 1) {
  321. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  322. nbDenied += 1;
  323. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  324. nbPending += 1;
  325. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  326. nbAllowed += 1;
  327. }
  328. }
  329. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  330. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  331. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  332. if (nbDenied === 0 && nbPending === 0) {
  333. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  334. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  335. } else if (nbAllowed === 0 && nbPending === 0) {
  336. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  337. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  338. } else {
  339. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  340. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  341. }
  342. // close the alert if all service have been reviewed
  343. if (nbPending === 0) {
  344. tarteaucitron.userInterface.closeAlert();
  345. }
  346. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  347. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  348. }
  349. if (status === true) {
  350. if (document.getElementById('tacCL' + key) !== null) {
  351. document.getElementById('tacCL' + key).innerHTML = '...';
  352. }
  353. setTimeout(function () {
  354. tarteaucitron.cookie.checkCount(key);
  355. }, 2500);
  356. } else {
  357. tarteaucitron.cookie.checkCount(key);
  358. }
  359. },
  360. "openPanel": function () {
  361. "use strict";
  362. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  363. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  364. // setting hash tag
  365. if (tarteaucitron.hashtag !== '') {
  366. document.location.hash = tarteaucitron.hashtag;
  367. }
  368. },
  369. "closePanel": function () {
  370. "use strict";
  371. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  372. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  373. },
  374. "openAlert": function () {
  375. "use strict";
  376. var c = 'tarteaucitron';
  377. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  378. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  379. },
  380. "closeAlert": function () {
  381. "use strict";
  382. var c = 'tarteaucitron';
  383. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  384. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  385. }
  386. },
  387. "cookie": {
  388. "create": function (key, status) {
  389. "use strict";
  390. var d = new Date(),
  391. time = d.getTime(),
  392. expireTime = time + 31536000000, // 365 days
  393. regex = new RegExp("!" + key + "=(true|false)", "g"),
  394. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  395. value = 'tarteaucitron=' + cookie + '!' + key + '=' + status;
  396. if (tarteaucitron.cookie.read().indexOf(key + '=' + status) === -1) {
  397. tarteaucitron.pro('!' + key + '=' + status);
  398. }
  399. d.setTime(expireTime);
  400. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;';
  401. },
  402. "read": function () {
  403. "use strict";
  404. var nameEQ = "tarteaucitron=",
  405. ca = document.cookie.split(';'),
  406. i,
  407. c;
  408. for (i = 0; i < ca.length; i += 1) {
  409. c = ca[i];
  410. while (c.charAt(0) === ' ') {
  411. c = c.substring(1, c.length);
  412. }
  413. if (c.indexOf(nameEQ) === 0) {
  414. return c.substring(nameEQ.length, c.length);
  415. }
  416. }
  417. return '';
  418. },
  419. "purge": function (arr) {
  420. "use strict";
  421. var i;
  422. for (i = 0; i < arr.length; i += 1) {
  423. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  424. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  425. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  426. }
  427. },
  428. "checkCount": function (key) {
  429. "use strict";
  430. var arr = tarteaucitron.services[key].cookies,
  431. nb = arr.length,
  432. nbCurrent = 0,
  433. html = '',
  434. i,
  435. status = document.cookie.indexOf(key + '=true');
  436. if (status >= 0 && nb === 0) {
  437. html += tarteaucitron.lang.useNoCookie;
  438. } else if (status >= 0) {
  439. for (i = 0; i < nb; i += 1) {
  440. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  441. nbCurrent += 1;
  442. }
  443. }
  444. if (nbCurrent > 0) {
  445. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  446. if (nbCurrent > 1) {
  447. html += 's';
  448. }
  449. html += '.';
  450. } else {
  451. html += tarteaucitron.lang.useNoCookie;
  452. }
  453. } else if (nb === 0) {
  454. html = tarteaucitron.lang.noCookie;
  455. } else {
  456. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  457. if (nb > 1) {
  458. html += 's';
  459. }
  460. html += '.';
  461. }
  462. if (document.getElementById('tacCL' + key) !== null) {
  463. document.getElementById('tacCL' + key).innerHTML = html;
  464. }
  465. }
  466. },
  467. "getLanguage": function () {
  468. "use strict";
  469. if (!navigator) { return 'en'; }
  470. var availableLanguages = 'en,fr',
  471. defaultLanguage = 'en',
  472. lang = navigator.language || navigator.browserLanguage ||
  473. navigator.systemLanguage || navigator.userLang || null,
  474. userLanguage = lang.substr(0, 2);
  475. if (availableLanguages.indexOf(userLanguage) === -1) {
  476. return defaultLanguage;
  477. }
  478. return userLanguage;
  479. },
  480. "getLocale": function () {
  481. "use strict";
  482. if (!navigator) { return 'en_US'; }
  483. var lang = navigator.language || navigator.browserLanguage ||
  484. navigator.systemLanguage || navigator.userLang || null,
  485. userLanguage = lang.substr(0, 2);
  486. if (userLanguage === 'fr') {
  487. return 'fr_FR';
  488. } else if (userLanguage === 'en') {
  489. return 'en_US';
  490. } else if (userLanguage === 'de') {
  491. return 'de_DE';
  492. } else if (userLanguage === 'es') {
  493. return 'es_ES';
  494. } else if (userLanguage === 'it') {
  495. return 'it_IT';
  496. } else if (userLanguage === 'pt') {
  497. return 'pt_PT';
  498. } else {
  499. return 'en_US';
  500. }
  501. },
  502. "addScript": function (url, id, callback) {
  503. "use strict";
  504. var script = document.createElement('script'),
  505. done = false;
  506. script.type = 'text/javascript';
  507. script.id = (id !== undefined) ? id : '';
  508. script.async = true;
  509. script.src = url;
  510. if (typeof callback === 'function') {
  511. script.onreadystatechange = script.onload = function () {
  512. var state = script.readyState;
  513. if (!done && (!state || /loaded|complete/.test(state))) {
  514. done = true;
  515. callback();
  516. }
  517. };
  518. }
  519. document.getElementsByTagName('head')[0].appendChild(script);
  520. },
  521. "fallback": function (matchClass, content) {
  522. "use strict";
  523. var elems = document.getElementsByTagName('*'),
  524. i,
  525. index = 0;
  526. for (i in elems) {
  527. if (elems[i] !== undefined) {
  528. for (index = 0; index < matchClass.length; index += 1) {
  529. if ((' ' + elems[i].className + ' ')
  530. .indexOf(' ' + matchClass[index] + ' ') > -1) {
  531. if (typeof content === 'function') {
  532. elems[i].innerHTML = content(elems[i]);
  533. } else {
  534. elems[i].innerHTML = content;
  535. }
  536. }
  537. }
  538. }
  539. }
  540. },
  541. "engage": function (id) {
  542. "use strict";
  543. var html = '',
  544. r = Math.floor(Math.random() * 100000);
  545. html += '<div class="tac_activate">';
  546. html += ' <div class="tac_float">';
  547. html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback + '<br/>';
  548. html += ' <div class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
  549. html += ' ' + tarteaucitron.lang.allow;
  550. html += ' </div>';
  551. html += ' </div>';
  552. html += '</div>';
  553. return html;
  554. },
  555. "extend": function (a, b) {
  556. "use strict";
  557. var prop;
  558. for (prop in b) {
  559. if (b.hasOwnProperty(prop)) {
  560. a[prop] = b[prop];
  561. }
  562. }
  563. },
  564. "proTemp": '',
  565. "proTimer": function () {
  566. "use strict";
  567. setTimeout(tarteaucitron.proPing, 1000);
  568. },
  569. "pro": function (list) {
  570. "use strict";
  571. tarteaucitron.proTemp += list;
  572. clearTimeout(tarteaucitron.proTimer);
  573. tarteaucitron.proTimer = setTimeout(tarteaucitron.proPing, 2500);
  574. },
  575. "proPing": function () {
  576. "use strict";
  577. if (tarteaucitron.uuid !== '' && tarteaucitron.uuid !== undefined && tarteaucitron.proTemp !== '') {
  578. var div = document.getElementById('tarteaucitronPremium'),
  579. timestamp = new Date().getTime(),
  580. url = '//opt-out.ferank.eu/premium.php?';
  581. url += 'domain=' + tarteaucitron.domain + '&';
  582. url += 'uuid=' + tarteaucitron.uuid + '&';
  583. url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
  584. url += '_' + timestamp;
  585. div.innerHTML = '<img src="' + url + '" style="display:none" />';
  586. tarteaucitron.proTemp = '';
  587. }
  588. }
  589. };