tarteaucitron.js 28 KB

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