tarteaucitron.js 27 KB

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