tarteaucitron.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /*jslint browser: true, evil: true */
  2. // define correct path for files inclusion
  3. var scripts = document.getElementsByTagName('script'),
  4. path = scripts[scripts.length - 1].src.split('?')[0],
  5. cdn = path.split('/').slice(0, -1).join('/') + '/',
  6. alreadyLaunch = (alreadyLaunch === undefined) ? 0 : alreadyLaunch,
  7. tarteaucitronForceLanguage = (tarteaucitronForceLanguage === undefined) ? '' : tarteaucitronForceLanguage,
  8. tarteaucitronProLoadServices,
  9. tarteaucitronNoAdBlocker = false;
  10. var tarteaucitron = {
  11. "version": 323,
  12. "cdn": cdn,
  13. "user": {},
  14. "lang": {},
  15. "services": {},
  16. "added": [],
  17. "idprocessed": [],
  18. "state": [],
  19. "launch": [],
  20. "parameters": {},
  21. "isAjax": false,
  22. "reloadThePage": false,
  23. "init": function (params) {
  24. "use strict";
  25. var origOpen;
  26. tarteaucitron.parameters = params;
  27. if (alreadyLaunch === 0) {
  28. alreadyLaunch = 1;
  29. if (window.addEventListener) {
  30. window.addEventListener("load", function () {
  31. tarteaucitron.load();
  32. tarteaucitron.fallback(['tarteaucitronOpenPanel'], function (elem) {
  33. elem.addEventListener("click", function (event) {
  34. tarteaucitron.userInterface.openPanel();
  35. event.preventDefault();
  36. }, false);
  37. }, true);
  38. }, false);
  39. window.addEventListener("scroll", function () {
  40. var scrollPos = window.pageYOffset || document.documentElement.scrollTop,
  41. heightPosition;
  42. if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) {
  43. if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') {
  44. heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px';
  45. if (scrollPos > (screen.height * 2)) {
  46. tarteaucitron.userInterface.respondAll(true);
  47. } else if (scrollPos > (screen.height / 2)) {
  48. document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<b>' + tarteaucitron.lang.alertBigScroll + '</b> ' + tarteaucitron.lang.alertBig;
  49. }
  50. if (tarteaucitron.orientation === 'top') {
  51. document.getElementById('tarteaucitronPercentage').style.top = heightPosition;
  52. } else {
  53. document.getElementById('tarteaucitronPercentage').style.bottom = heightPosition;
  54. }
  55. document.getElementById('tarteaucitronPercentage').style.width = ((100 / (screen.height * 2)) * scrollPos) + '%';
  56. }
  57. }
  58. }, false);
  59. window.addEventListener("keydown", function (evt) {
  60. if (evt.keyCode === 27) {
  61. tarteaucitron.userInterface.closePanel();
  62. }
  63. }, false);
  64. window.addEventListener("hashchange", function () {
  65. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  66. tarteaucitron.userInterface.openPanel();
  67. }
  68. }, false);
  69. window.addEventListener("resize", function () {
  70. if (document.getElementById('tarteaucitron') !== null) {
  71. if (document.getElementById('tarteaucitron').style.display === 'block') {
  72. tarteaucitron.userInterface.jsSizing('main');
  73. }
  74. }
  75. if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
  76. if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
  77. tarteaucitron.userInterface.jsSizing('cookie');
  78. }
  79. }
  80. }, false);
  81. } else {
  82. window.attachEvent("onload", function () {
  83. tarteaucitron.load();
  84. tarteaucitron.fallback(['tarteaucitronOpenPanel'], function (elem) {
  85. elem.attachEvent("onclick", function (event) {
  86. tarteaucitron.userInterface.openPanel();
  87. event.preventDefault();
  88. });
  89. }, true);
  90. });
  91. window.attachEvent("onscroll", function () {
  92. var scrollPos = window.pageYOffset || document.documentElement.scrollTop,
  93. heightPosition;
  94. if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) {
  95. if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') {
  96. heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px';
  97. if (scrollPos > (screen.height * 2)) {
  98. tarteaucitron.userInterface.respondAll(true);
  99. } else if (scrollPos > (screen.height / 2)) {
  100. document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<b>' + tarteaucitron.lang.alertBigScroll + '</b> ' + tarteaucitron.lang.alertBig;
  101. }
  102. if (tarteaucitron.orientation === 'top') {
  103. document.getElementById('tarteaucitronPercentage').style.top = heightPosition;
  104. } else {
  105. document.getElementById('tarteaucitronPercentage').style.bottom = heightPosition;
  106. }
  107. document.getElementById('tarteaucitronPercentage').style.width = ((100 / (screen.height * 2)) * scrollPos) + '%';
  108. }
  109. }
  110. });
  111. window.attachEvent("onkeydown", function (evt) {
  112. if (evt.keyCode === 27) {
  113. tarteaucitron.userInterface.closePanel();
  114. }
  115. });
  116. window.attachEvent("onhashchange", function () {
  117. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  118. tarteaucitron.userInterface.openPanel();
  119. }
  120. });
  121. window.attachEvent("onresize", function () {
  122. if (document.getElementById('tarteaucitron') !== null) {
  123. if (document.getElementById('tarteaucitron').style.display === 'block') {
  124. tarteaucitron.userInterface.jsSizing('main');
  125. }
  126. }
  127. if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
  128. if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
  129. tarteaucitron.userInterface.jsSizing('cookie');
  130. }
  131. }
  132. });
  133. }
  134. if (typeof XMLHttpRequest !== 'undefined') {
  135. origOpen = XMLHttpRequest.prototype.open;
  136. XMLHttpRequest.prototype.open = function () {
  137. if (window.addEventListener) {
  138. this.addEventListener("load", function () {
  139. if (typeof tarteaucitronProLoadServices === 'function') {
  140. tarteaucitronProLoadServices();
  141. }
  142. }, false);
  143. } else if (typeof this.attachEvent !== 'undefined') {
  144. this.attachEvent("onload", function () {
  145. if (typeof tarteaucitronProLoadServices === 'function') {
  146. tarteaucitronProLoadServices();
  147. }
  148. });
  149. } else {
  150. if (typeof tarteaucitronProLoadServices === 'function') {
  151. setTimeout(tarteaucitronProLoadServices, 1000);
  152. }
  153. }
  154. try {
  155. origOpen.apply(this, arguments);
  156. } catch (err) {}
  157. };
  158. }
  159. }
  160. },
  161. "load": function () {
  162. "use strict";
  163. var cdn = tarteaucitron.cdn,
  164. language = tarteaucitron.getLanguage(),
  165. pathToLang = cdn + 'lang/tarteaucitron.' + language + '.js?v=' + tarteaucitron.version,
  166. pathToServices = cdn + 'tarteaucitron.services.js?v=' + tarteaucitron.version,
  167. linkElement = document.createElement('link'),
  168. defaults = {
  169. "adblocker": false,
  170. "hashtag": '#tarteaucitron',
  171. "highPrivacy": false,
  172. "orientation": "top",
  173. "removeCredit": false,
  174. "showAlertSmall": true,
  175. "cookieslist": true
  176. },
  177. params = tarteaucitron.parameters;
  178. // Step 0: get params
  179. if (params !== undefined) {
  180. tarteaucitron.extend(defaults, params);
  181. }
  182. // global
  183. tarteaucitron.orientation = defaults.orientation;
  184. tarteaucitron.hashtag = defaults.hashtag;
  185. tarteaucitron.highPrivacy = defaults.highPrivacy;
  186. // Step 1: load css
  187. linkElement.rel = 'stylesheet';
  188. linkElement.type = 'text/css';
  189. linkElement.href = cdn + 'css/tarteaucitron.css?v=' + tarteaucitron.version;
  190. document.getElementsByTagName('head')[0].appendChild(linkElement);
  191. // Step 2: load language and services
  192. tarteaucitron.addScript(pathToLang, '', function () {
  193. tarteaucitron.addScript(pathToServices, '', function () {
  194. var body = document.body,
  195. div = document.createElement('div'),
  196. html = '',
  197. index,
  198. orientation = 'Top',
  199. cat = ['ads', 'analytic', 'api', 'comment', 'social', 'support', 'video', 'other'],
  200. i;
  201. cat = cat.sort(function (a, b) {
  202. if (tarteaucitron.lang[a].title > tarteaucitron.lang[b].title) { return 1; }
  203. if (tarteaucitron.lang[a].title < tarteaucitron.lang[b].title) { return -1; }
  204. return 0;
  205. });
  206. // Step 3: prepare the html
  207. html += '<div id="tarteaucitronPremium"></div>';
  208. html += '<div id="tarteaucitronBack" onclick="tarteaucitron.userInterface.closePanel();"></div>';
  209. html += '<div id="tarteaucitron">';
  210. html += ' <div id="tarteaucitronClosePanel" onclick="tarteaucitron.userInterface.closePanel();">';
  211. html += ' ' + tarteaucitron.lang.close;
  212. html += ' </div>';
  213. html += ' <div id="tarteaucitronServices">';
  214. html += ' <div class="tarteaucitronLine tarteaucitronMainLine" id="tarteaucitronMainLineOffset">';
  215. html += ' <div class="tarteaucitronName">';
  216. html += ' <b><a href="#" onclick="tarteaucitron.userInterface.toggle(\'tarteaucitronInfo\', \'tarteaucitronInfoBox\');return false">&#10011;</a> ' + tarteaucitron.lang.all + '</b>';
  217. html += ' </div>';
  218. html += ' <div class="tarteaucitronAsk" id="tarteaucitronScrollbarAdjust">';
  219. html += ' <div id="tarteaucitronAllAllowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respondAll(true);">';
  220. html += ' &#10003; ' + tarteaucitron.lang.allow;
  221. html += ' </div> ';
  222. html += ' <div id="tarteaucitronAllDenied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respondAll(false);">';
  223. html += ' &#10007; ' + tarteaucitron.lang.deny;
  224. html += ' </div>';
  225. html += ' </div>';
  226. html += ' </div>';
  227. html += ' <div id="tarteaucitronInfo" class="tarteaucitronInfoBox">';
  228. html += ' ' + tarteaucitron.lang.disclaimer;
  229. if (defaults.removeCredit === false) {
  230. html += ' <br/><br/>';
  231. html += ' <a href="https://opt-out.ferank.eu/" rel="nofollow" target="_blank" rel="noopener">' + tarteaucitron.lang.credit + '</a>';
  232. }
  233. html += ' </div>';
  234. html += ' <div class="tarteaucitronBorder" id="tarteaucitronScrollbarParent">';
  235. html += ' <div class="clear"></div>';
  236. for (i = 0; i < cat.length; i += 1) {
  237. html += ' <div id="tarteaucitronServicesTitle_' + cat[i] + '" class="tarteaucitronHidden">';
  238. html += ' <div class="tarteaucitronTitle">';
  239. html += ' <a href="#" onclick="tarteaucitron.userInterface.toggle(\'tarteaucitronDetails' + cat[i] + '\', \'tarteaucitronInfoBox\');return false">&#10011;</a> ' + tarteaucitron.lang[cat[i]].title;
  240. html += ' </div>';
  241. html += ' <div id="tarteaucitronDetails' + cat[i] + '" class="tarteaucitronDetails tarteaucitronInfoBox">';
  242. html += ' ' + tarteaucitron.lang[cat[i]].details;
  243. html += ' </div>';
  244. html += ' </div>';
  245. html += ' <div id="tarteaucitronServices_' + cat[i] + '"></div>';
  246. }
  247. html += ' <div class="tarteaucitronHidden" id="tarteaucitronScrollbarChild" style="height:20px;display:block"></div>';
  248. html += ' </div>';
  249. html += ' </div>';
  250. html += '</div>';
  251. if (defaults.orientation === 'bottom') {
  252. orientation = 'Bottom';
  253. }
  254. if (defaults.highPrivacy) {
  255. html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
  256. html += ' <span id="tarteaucitronDisclaimerAlert">';
  257. html += ' ' + tarteaucitron.lang.alertBigPrivacy;
  258. html += ' </span>';
  259. html += ' <span id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.openPanel();">';
  260. html += ' ' + tarteaucitron.lang.personalize;
  261. html += ' </span>';
  262. html += '</div>';
  263. } else {
  264. html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
  265. html += ' <span id="tarteaucitronDisclaimerAlert">';
  266. html += ' ' + tarteaucitron.lang.alertBigClick + ' ' + tarteaucitron.lang.alertBig;
  267. html += ' </span>';
  268. html += ' <span id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.respondAll(true);">';
  269. html += ' &#10003; ' + tarteaucitron.lang.acceptAll;
  270. html += ' </span>';
  271. html += ' <span id="tarteaucitronCloseAlert" onclick="tarteaucitron.userInterface.openPanel();">';
  272. html += ' ' + tarteaucitron.lang.personalize;
  273. html += ' </span>';
  274. html += '</div>';
  275. html += '<div id="tarteaucitronPercentage"></div>';
  276. }
  277. if (defaults.showAlertSmall === true) {
  278. html += '<div id="tarteaucitronAlertSmall">';
  279. html += ' <div id="tarteaucitronManager" onclick="tarteaucitron.userInterface.openPanel();">';
  280. html += ' ' + tarteaucitron.lang.alertSmall;
  281. html += ' <div id="tarteaucitronDot">';
  282. html += ' <span id="tarteaucitronDotGreen"></span>';
  283. html += ' <span id="tarteaucitronDotYellow"></span>';
  284. html += ' <span id="tarteaucitronDotRed"></span>';
  285. html += ' </div>';
  286. if (defaults.cookieslist === true) {
  287. html += ' </div><!-- @whitespace';
  288. html += ' --><div id="tarteaucitronCookiesNumber" onclick="tarteaucitron.userInterface.toggleCookiesList();">0</div>';
  289. html += ' <div id="tarteaucitronCookiesListContainer">';
  290. html += ' <div id="tarteaucitronClosePanelCookie" onclick="tarteaucitron.userInterface.closePanel();">';
  291. html += ' ' + tarteaucitron.lang.close;
  292. html += ' </div>';
  293. html += ' <div class="tarteaucitronCookiesListMain" id="tarteaucitronCookiesTitle">';
  294. html += ' <b id="tarteaucitronCookiesNumberBis">0 cookie</b>';
  295. html += ' </div>';
  296. html += ' <div id="tarteaucitronCookiesList"></div>';
  297. html += ' </div>';
  298. } else {
  299. html += ' </div>';
  300. }
  301. html += '</div>';
  302. }
  303. tarteaucitron.addScript(tarteaucitron.cdn + 'advertising.js?v=' + tarteaucitron.version, '', function () {
  304. if (tarteaucitronNoAdBlocker === true || defaults.adblocker === false) {
  305. div.id = 'tarteaucitronRoot';
  306. body.appendChild(div, body);
  307. div.innerHTML = html;
  308. if (tarteaucitron.job !== undefined) {
  309. tarteaucitron.job = tarteaucitron.cleanArray(tarteaucitron.job);
  310. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  311. tarteaucitron.addService(tarteaucitron.job[index]);
  312. }
  313. } else {
  314. tarteaucitron.job = []
  315. }
  316. tarteaucitron.isAjax = true;
  317. tarteaucitron.job.push = function (id) {
  318. // ie <9 hack
  319. if (typeof tarteaucitron.job.indexOf === 'undefined') {
  320. tarteaucitron.job.indexOf = function (obj, start) {
  321. var i,
  322. j = this.length;
  323. for (i = (start || 0); i < j; i += 1) {
  324. if (this[i] === obj) { return i; }
  325. }
  326. return -1;
  327. };
  328. }
  329. if (tarteaucitron.job.indexOf(id) === -1) {
  330. Array.prototype.push.call(this, id);
  331. }
  332. tarteaucitron.launch[id] = false;
  333. tarteaucitron.addService(id);
  334. };
  335. if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
  336. tarteaucitron.userInterface.openPanel();
  337. }
  338. tarteaucitron.cookie.number();
  339. setInterval(tarteaucitron.cookie.number, 60000);
  340. }
  341. }, defaults.adblocker);
  342. if (defaults.adblocker === true) {
  343. setTimeout(function () {
  344. if (tarteaucitronNoAdBlocker === false) {
  345. html = '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '" style="display:block">';
  346. html += ' <span id="tarteaucitronDisclaimerAlert">';
  347. html += ' ' + tarteaucitron.lang.adblock + '<br/>';
  348. html += ' <b>' + tarteaucitron.lang.adblock_call + '</b>';
  349. html += ' </span>';
  350. html += ' <span id="tarteaucitronPersonalize" onclick="location.reload();">';
  351. html += ' ' + tarteaucitron.lang.reload;
  352. html += ' </span>';
  353. html += '</div>';
  354. html += '<div id="tarteaucitronPremium"></div>';
  355. div.id = 'tarteaucitronRoot';
  356. body.appendChild(div, body);
  357. div.innerHTML = html;
  358. tarteaucitron.pro('!adblocker=true');
  359. } else {
  360. tarteaucitron.pro('!adblocker=false');
  361. }
  362. }, 1500);
  363. }
  364. });
  365. });
  366. },
  367. "addService": function (serviceId) {
  368. "use strict";
  369. var html = '',
  370. s = tarteaucitron.services,
  371. service = s[serviceId],
  372. cookie = tarteaucitron.cookie.read(),
  373. hostname = document.location.hostname,
  374. hostRef = document.referrer.split('/')[2],
  375. isNavigating = (hostRef === hostname) ? true : false,
  376. isAutostart = (!service.needConsent) ? true : false,
  377. isWaiting = (cookie.indexOf(service.key + '=wait') >= 0) ? true : false,
  378. isDenied = (cookie.indexOf(service.key + '=false') >= 0) ? true : false,
  379. isAllowed = (cookie.indexOf(service.key + '=true') >= 0) ? true : false,
  380. isResponded = (cookie.indexOf(service.key + '=false') >= 0 || cookie.indexOf(service.key + '=true') >= 0) ? true : false;
  381. if (tarteaucitron.added[service.key] !== true) {
  382. tarteaucitron.added[service.key] = true;
  383. html += '<div id="' + service.key + 'Line" class="tarteaucitronLine">';
  384. html += ' <div class="tarteaucitronName">';
  385. html += ' <b>' + service.name + '</b><br/>';
  386. html += ' <span id="tacCL' + service.key + '" class="tarteaucitronListCookies"></span><br/>';
  387. html += ' <a href="https://opt-out.ferank.eu/service/' + service.key + '/" target="_blank" rel="noopener">';
  388. html += ' ' + tarteaucitron.lang.more;
  389. html += ' </a>';
  390. html += ' - ';
  391. html += ' <a href="' + service.uri + '" target="_blank" rel="noopener">';
  392. html += ' ' + tarteaucitron.lang.source;
  393. html += ' </a>';
  394. html += ' </div>';
  395. html += ' <div class="tarteaucitronAsk">';
  396. html += ' <div id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
  397. html += ' &#10003; ' + tarteaucitron.lang.allow;
  398. html += ' </div> ';
  399. html += ' <div id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
  400. html += ' &#10007; ' + tarteaucitron.lang.deny;
  401. html += ' </div>';
  402. html += ' </div>';
  403. html += '</div>';
  404. tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
  405. if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
  406. document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
  407. }
  408. tarteaucitron.userInterface.order(service.type);
  409. }
  410. // allow by default for non EU
  411. if (isResponded === false && tarteaucitron.user.bypass === true) {
  412. isAllowed = true;
  413. tarteaucitron.cookie.create(service.key, true);
  414. }
  415. if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
  416. if (!isAllowed) {
  417. tarteaucitron.cookie.create(service.key, true);
  418. }
  419. if (tarteaucitron.launch[service.key] !== true) {
  420. tarteaucitron.launch[service.key] = true;
  421. service.js();
  422. }
  423. tarteaucitron.state[service.key] = true;
  424. tarteaucitron.userInterface.color(service.key, true);
  425. } else if (isDenied) {
  426. if (typeof service.fallback === 'function') {
  427. service.fallback();
  428. }
  429. tarteaucitron.state[service.key] = false;
  430. tarteaucitron.userInterface.color(service.key, false);
  431. } else if (!isResponded) {
  432. tarteaucitron.cookie.create(service.key, 'wait');
  433. if (typeof service.fallback === 'function') {
  434. service.fallback();
  435. }
  436. tarteaucitron.userInterface.color(service.key, 'wait');
  437. tarteaucitron.userInterface.openAlert();
  438. }
  439. tarteaucitron.cookie.checkCount(service.key);
  440. },
  441. "cleanArray": function cleanArray(arr) {
  442. "use strict";
  443. var i,
  444. len = arr.length,
  445. out = [],
  446. obj = {},
  447. s = tarteaucitron.services;
  448. for (i = 0; i < len; i += 1) {
  449. if (!obj[arr[i]]) {
  450. obj[arr[i]] = {};
  451. if (tarteaucitron.services[arr[i]] !== undefined) {
  452. out.push(arr[i]);
  453. }
  454. }
  455. }
  456. out = out.sort(function (a, b) {
  457. if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
  458. if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
  459. return 0;
  460. });
  461. return out;
  462. },
  463. "userInterface": {
  464. "css": function (id, property, value) {
  465. "use strict";
  466. if (document.getElementById(id) !== null) {
  467. document.getElementById(id).style[property] = value;
  468. }
  469. },
  470. "respondAll": function (status) {
  471. "use strict";
  472. var s = tarteaucitron.services,
  473. service,
  474. key,
  475. index = 0;
  476. for (index = 0; index < tarteaucitron.job.length; index += 1) {
  477. service = s[tarteaucitron.job[index]];
  478. key = service.key;
  479. if (tarteaucitron.state[key] !== status) {
  480. if (status === false && tarteaucitron.launch[key] === true) {
  481. tarteaucitron.reloadThePage = true;
  482. }
  483. if (tarteaucitron.launch[key] !== true && status === true) {
  484. tarteaucitron.launch[key] = true;
  485. tarteaucitron.services[key].js();
  486. }
  487. tarteaucitron.state[key] = status;
  488. tarteaucitron.cookie.create(key, status);
  489. tarteaucitron.userInterface.color(key, status);
  490. }
  491. }
  492. },
  493. "respond": function (el, status) {
  494. "use strict";
  495. var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
  496. // return if same state
  497. if (tarteaucitron.state[key] === status) {
  498. return;
  499. }
  500. if (status === false && tarteaucitron.launch[key] === true) {
  501. tarteaucitron.reloadThePage = true;
  502. }
  503. // if not already launched... launch the service
  504. if (status === true) {
  505. if (tarteaucitron.launch[key] !== true) {
  506. tarteaucitron.launch[key] = true;
  507. tarteaucitron.services[key].js();
  508. }
  509. }
  510. tarteaucitron.state[key] = status;
  511. tarteaucitron.cookie.create(key, status);
  512. tarteaucitron.userInterface.color(key, status);
  513. },
  514. "color": function (key, status) {
  515. "use strict";
  516. var gray = '#808080',
  517. greenDark = '#1B870B',
  518. greenLight = '#E6FFE2',
  519. redDark = '#9C1A1A',
  520. redLight = '#FFE2E2',
  521. yellowDark = '#FBDA26',
  522. c = 'tarteaucitron',
  523. nbDenied = 0,
  524. nbPending = 0,
  525. nbAllowed = 0,
  526. sum = tarteaucitron.job.length,
  527. index;
  528. if (status === true) {
  529. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + greenDark);
  530. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', greenDark);
  531. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', gray);
  532. } else if (status === false) {
  533. tarteaucitron.userInterface.css(key + 'Line', 'borderLeft', '5px solid ' + redDark);
  534. tarteaucitron.userInterface.css(key + 'Allowed', 'backgroundColor', gray);
  535. tarteaucitron.userInterface.css(key + 'Denied', 'backgroundColor', redDark);
  536. }
  537. // check if all services are allowed
  538. for (index = 0; index < sum; index += 1) {
  539. if (tarteaucitron.state[tarteaucitron.job[index]] === false) {
  540. nbDenied += 1;
  541. } else if (tarteaucitron.state[tarteaucitron.job[index]] === undefined) {
  542. nbPending += 1;
  543. } else if (tarteaucitron.state[tarteaucitron.job[index]] === true) {
  544. nbAllowed += 1;
  545. }
  546. }
  547. tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
  548. tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
  549. tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
  550. if (nbDenied === 0 && nbPending === 0) {
  551. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
  552. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  553. } else if (nbAllowed === 0 && nbPending === 0) {
  554. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  555. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', redDark);
  556. } else {
  557. tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
  558. tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
  559. }
  560. // close the alert if all service have been reviewed
  561. if (nbPending === 0) {
  562. tarteaucitron.userInterface.closeAlert();
  563. }
  564. if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
  565. tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
  566. }
  567. if (status === true) {
  568. if (document.getElementById('tacCL' + key) !== null) {
  569. document.getElementById('tacCL' + key).innerHTML = '...';
  570. }
  571. setTimeout(function () {
  572. tarteaucitron.cookie.checkCount(key);
  573. }, 2500);
  574. } else {
  575. tarteaucitron.cookie.checkCount(key);
  576. }
  577. },
  578. "openPanel": function () {
  579. "use strict";
  580. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'block');
  581. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  582. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  583. tarteaucitron.userInterface.jsSizing('main');
  584. },
  585. "closePanel": function () {
  586. "use strict";
  587. if (document.location.hash === tarteaucitron.hashtag) {
  588. document.location.hash = '';
  589. }
  590. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  591. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
  592. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  593. elem.style.display = 'none';
  594. }, true);
  595. if (tarteaucitron.reloadThePage === true) {
  596. window.location.reload();
  597. } else {
  598. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  599. }
  600. },
  601. "openAlert": function () {
  602. "use strict";
  603. var c = 'tarteaucitron';
  604. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'block');
  605. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'none');
  606. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'block');
  607. },
  608. "closeAlert": function () {
  609. "use strict";
  610. var c = 'tarteaucitron';
  611. tarteaucitron.userInterface.css(c + 'Percentage', 'display', 'none');
  612. tarteaucitron.userInterface.css(c + 'AlertSmall', 'display', 'block');
  613. tarteaucitron.userInterface.css(c + 'AlertBig', 'display', 'none');
  614. tarteaucitron.userInterface.jsSizing('box');
  615. },
  616. "toggleCookiesList": function () {
  617. "use strict";
  618. var div = document.getElementById('tarteaucitronCookiesListContainer');
  619. if (div === null) {
  620. return;
  621. }
  622. if (div.style.display !== 'block') {
  623. tarteaucitron.cookie.number();
  624. div.style.display = 'block';
  625. tarteaucitron.userInterface.jsSizing('cookie');
  626. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  627. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'block');
  628. tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
  629. elem.style.display = 'none';
  630. }, true);
  631. } else {
  632. div.style.display = 'none';
  633. tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
  634. tarteaucitron.userInterface.css('tarteaucitronBack', 'display', 'none');
  635. }
  636. },
  637. "toggle": function (id, closeClass) {
  638. "use strict";
  639. var div = document.getElementById(id);
  640. if (div === null) {
  641. return;
  642. }
  643. if (closeClass !== undefined) {
  644. tarteaucitron.fallback([closeClass], function (elem) {
  645. if (elem.id !== id) {
  646. elem.style.display = 'none';
  647. }
  648. }, true);
  649. }
  650. if (div.style.display !== 'block') {
  651. div.style.display = 'block';
  652. } else {
  653. div.style.display = 'none';
  654. }
  655. },
  656. "order": function (id) {
  657. "use strict";
  658. var main = document.getElementById('tarteaucitronServices_' + id),
  659. allDivs,
  660. store = [],
  661. i;
  662. if (main === null) {
  663. return;
  664. }
  665. allDivs = main.childNodes;
  666. if (typeof Array.prototype.map === 'function') {
  667. Array.prototype.map.call(main.children, Object).sort(function (a, b) {
  668. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
  669. if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; }
  670. return 0;
  671. }).forEach(function (element) {
  672. main.appendChild(element);
  673. });
  674. }
  675. },
  676. "jsSizing": function (type) {
  677. "use strict";
  678. var scrollbarMarginRight = 10,
  679. scrollbarWidthParent,
  680. scrollbarWidthChild,
  681. servicesHeight,
  682. e = window,
  683. a = 'inner',
  684. windowInnerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
  685. mainTop,
  686. mainHeight,
  687. closeButtonHeight,
  688. headerHeight,
  689. cookiesListHeight,
  690. cookiesCloseHeight,
  691. cookiesTitleHeight,
  692. paddingBox,
  693. alertSmallHeight,
  694. cookiesNumberHeight;
  695. if (type === 'box') {
  696. if (document.getElementById('tarteaucitronAlertSmall') !== null && document.getElementById('tarteaucitronCookiesNumber') !== null) {
  697. // reset
  698. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', '0px 10px');
  699. // calculate
  700. alertSmallHeight = document.getElementById('tarteaucitronAlertSmall').offsetHeight;
  701. cookiesNumberHeight = document.getElementById('tarteaucitronCookiesNumber').offsetHeight;
  702. paddingBox = (alertSmallHeight - cookiesNumberHeight) / 2;
  703. // apply
  704. tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', paddingBox + 'px 10px');
  705. }
  706. } else if (type === 'main') {
  707. // get the real window width for media query
  708. if (window.innerWidth === undefined) {
  709. a = 'client';
  710. e = document.documentElement || document.body;
  711. }
  712. // height of the services list container
  713. if (document.getElementById('tarteaucitron') !== null && document.getElementById('tarteaucitronClosePanel') !== null && document.getElementById('tarteaucitronMainLineOffset') !== null) {
  714. // reset
  715. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', 'auto');
  716. // calculate
  717. mainHeight = document.getElementById('tarteaucitron').offsetHeight;
  718. closeButtonHeight = document.getElementById('tarteaucitronClosePanel').offsetHeight;
  719. headerHeight = document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  720. // apply
  721. servicesHeight = (mainHeight - closeButtonHeight - headerHeight + 1);
  722. tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', servicesHeight + 'px');
  723. }
  724. // align the main allow/deny button depending on scrollbar width
  725. if (document.getElementById('tarteaucitronScrollbarParent') !== null && document.getElementById('tarteaucitronScrollbarChild') !== null) {
  726. // media query
  727. if (e[a + 'Width'] <= 479) {
  728. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px');
  729. } else if (e[a + 'Width'] <= 767) {
  730. scrollbarMarginRight = 12;
  731. }
  732. scrollbarWidthParent = document.getElementById('tarteaucitronScrollbarParent').offsetWidth;
  733. scrollbarWidthChild = document.getElementById('tarteaucitronScrollbarChild').offsetWidth;
  734. tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((scrollbarWidthParent - scrollbarWidthChild) + scrollbarMarginRight) + 'px');
  735. }
  736. // center the main panel
  737. if (document.getElementById('tarteaucitron') !== null) {
  738. // media query
  739. if (e[a + 'Width'] <= 767) {
  740. mainTop = 0;
  741. } else {
  742. mainTop = ((windowInnerHeight - document.getElementById('tarteaucitron').offsetHeight) / 2) - 21;
  743. }
  744. // correct
  745. if (mainTop < 0) {
  746. mainTop = 0;
  747. }
  748. if (document.getElementById('tarteaucitronMainLineOffset') !== null) {
  749. if (document.getElementById('tarteaucitron').offsetHeight < (windowInnerHeight / 2)) {
  750. mainTop -= document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
  751. }
  752. }
  753. // apply
  754. tarteaucitron.userInterface.css('tarteaucitron', 'top', mainTop + 'px');
  755. }
  756. } else if (type === 'cookie') {
  757. // put cookies list at bottom
  758. if (document.getElementById('tarteaucitronAlertSmall') !== null) {
  759. tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (document.getElementById('tarteaucitronAlertSmall').offsetHeight) + 'px');
  760. }
  761. // height of cookies list
  762. if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
  763. // reset
  764. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto');
  765. // calculate
  766. cookiesListHeight = document.getElementById('tarteaucitronCookiesListContainer').offsetHeight;
  767. cookiesCloseHeight = document.getElementById('tarteaucitronClosePanelCookie').offsetHeight;
  768. cookiesTitleHeight = document.getElementById('tarteaucitronCookiesTitle').offsetHeight;
  769. // apply
  770. tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (cookiesListHeight - cookiesCloseHeight - cookiesTitleHeight - 2) + 'px');
  771. }
  772. }
  773. }
  774. },
  775. "cookie": {
  776. "owner": {},
  777. "create": function (key, status) {
  778. "use strict";
  779. var d = new Date(),
  780. time = d.getTime(),
  781. expireTime = time + 31536000000, // 365 days
  782. regex = new RegExp("!" + key + "=(wait|true|false)", "g"),
  783. cookie = tarteaucitron.cookie.read().replace(regex, ""),
  784. value = 'tarteaucitron=' + cookie + '!' + key + '=' + status,
  785. domain = (tarteaucitron.parameters.cookieDomain !== undefined && tarteaucitron.parameters.cookieDomain !== '') ? 'domain=' + tarteaucitron.parameters.cookieDomain + ';' : '';
  786. if (tarteaucitron.cookie.read().indexOf(key + '=' + status) === -1) {
  787. tarteaucitron.pro('!' + key + '=' + status);
  788. }
  789. d.setTime(expireTime);
  790. document.cookie = value + '; expires=' + d.toGMTString() + '; path=/;' + domain;
  791. },
  792. "read": function () {
  793. "use strict";
  794. var nameEQ = "tarteaucitron=",
  795. ca = document.cookie.split(';'),
  796. i,
  797. c;
  798. for (i = 0; i < ca.length; i += 1) {
  799. c = ca[i];
  800. while (c.charAt(0) === ' ') {
  801. c = c.substring(1, c.length);
  802. }
  803. if (c.indexOf(nameEQ) === 0) {
  804. return c.substring(nameEQ.length, c.length);
  805. }
  806. }
  807. return '';
  808. },
  809. "purge": function (arr) {
  810. "use strict";
  811. var i;
  812. for (i = 0; i < arr.length; i += 1) {
  813. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
  814. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
  815. document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';';
  816. }
  817. },
  818. "checkCount": function (key) {
  819. "use strict";
  820. var arr = tarteaucitron.services[key].cookies,
  821. nb = arr.length,
  822. nbCurrent = 0,
  823. html = '',
  824. i,
  825. status = document.cookie.indexOf(key + '=true');
  826. if (status >= 0 && nb === 0) {
  827. html += tarteaucitron.lang.useNoCookie;
  828. } else if (status >= 0) {
  829. for (i = 0; i < nb; i += 1) {
  830. if (document.cookie.indexOf(arr[i] + '=') !== -1) {
  831. nbCurrent += 1;
  832. if (tarteaucitron.cookie.owner[arr[i]] === undefined) {
  833. tarteaucitron.cookie.owner[arr[i]] = [];
  834. }
  835. if (tarteaucitron.cookie.crossIndexOf(tarteaucitron.cookie.owner[arr[i]], tarteaucitron.services[key].name) === false) {
  836. tarteaucitron.cookie.owner[arr[i]].push(tarteaucitron.services[key].name);
  837. }
  838. }
  839. }
  840. if (nbCurrent > 0) {
  841. html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
  842. if (nbCurrent > 1) {
  843. html += 's';
  844. }
  845. html += '.';
  846. } else {
  847. html += tarteaucitron.lang.useNoCookie;
  848. }
  849. } else if (nb === 0) {
  850. html = tarteaucitron.lang.noCookie;
  851. } else {
  852. html += tarteaucitron.lang.useCookie + ' ' + nb + ' cookie';
  853. if (nb > 1) {
  854. html += 's';
  855. }
  856. html += '.';
  857. }
  858. if (document.getElementById('tacCL' + key) !== null) {
  859. document.getElementById('tacCL' + key).innerHTML = html;
  860. }
  861. },
  862. "crossIndexOf": function (arr, match) {
  863. "use strict";
  864. var i;
  865. for (i = 0; i < arr.length; i += 1) {
  866. if (arr[i] === match) {
  867. return true;
  868. }
  869. }
  870. return false;
  871. },
  872. "number": function () {
  873. "use strict";
  874. var cookies = document.cookie.split(';'),
  875. nb = (document.cookie !== '') ? cookies.length : 0,
  876. html = '',
  877. i,
  878. name,
  879. namea,
  880. nameb,
  881. c,
  882. d,
  883. s = (nb > 1) ? 's' : '',
  884. savedname,
  885. regex = /^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i,
  886. regexedDomain = (tarteaucitron.cdn.match(regex) !== null) ? tarteaucitron.cdn.match(regex)[1] : tarteaucitron.cdn,
  887. host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : regexedDomain;
  888. cookies = cookies.sort(function (a, b) {
  889. namea = a.split('=', 1).toString().replace(/ /g, '');
  890. nameb = b.split('=', 1).toString().replace(/ /g, '');
  891. c = (tarteaucitron.cookie.owner[namea] !== undefined) ? tarteaucitron.cookie.owner[namea] : '0';
  892. d = (tarteaucitron.cookie.owner[nameb] !== undefined) ? tarteaucitron.cookie.owner[nameb] : '0';
  893. if (c + a > d + b) { return 1; }
  894. if (c + a < d + b) { return -1; }
  895. return 0;
  896. });
  897. if (document.cookie !== '') {
  898. for (i = 0; i < nb; i += 1) {
  899. name = cookies[i].split('=', 1).toString().replace(/ /g, '');
  900. if (tarteaucitron.cookie.owner[name] !== undefined && tarteaucitron.cookie.owner[name].join(' // ') !== savedname) {
  901. savedname = tarteaucitron.cookie.owner[name].join(' // ');
  902. html += '<div class="tarteaucitronHidden">';
  903. html += ' <div class="tarteaucitronTitle">';
  904. html += ' ' + tarteaucitron.cookie.owner[name].join(' // ');
  905. html += ' </div>';
  906. html += '</div>';
  907. } else if (tarteaucitron.cookie.owner[name] === undefined && host !== savedname) {
  908. savedname = host;
  909. html += '<div class="tarteaucitronHidden">';
  910. html += ' <div class="tarteaucitronTitle">';
  911. html += ' ' + host;
  912. html += ' </div>';
  913. html += '</div>';
  914. }
  915. html += '<div class="tarteaucitronCookiesListMain">';
  916. html += ' <div class="tarteaucitronCookiesListLeft"><a href="#" onclick="tarteaucitron.cookie.purge([\'' + cookies[i].split('=', 1) + '\']);tarteaucitron.cookie.number();tarteaucitron.userInterface.jsSizing(\'cookie\');return false"><b>&times;</b></a> <b>' + name + '</b>';
  917. html += ' </div>';
  918. html += ' <div class="tarteaucitronCookiesListRight">' + cookies[i].split('=').slice(1).join('=') + '</div>';
  919. html += '</div>';
  920. }
  921. } else {
  922. html += '<div class="tarteaucitronCookiesListMain">';
  923. html += ' <div class="tarteaucitronCookiesListLeft"><b>-</b></div>';
  924. html += ' <div class="tarteaucitronCookiesListRight"></div>';
  925. html += '</div>';
  926. }
  927. html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
  928. if (document.getElementById('tarteaucitronCookiesList') !== null) {
  929. document.getElementById('tarteaucitronCookiesList').innerHTML = html;
  930. }
  931. if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
  932. document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
  933. }
  934. if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) {
  935. document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
  936. }
  937. for (i = 0; i < tarteaucitron.job.length; i += 1) {
  938. tarteaucitron.cookie.checkCount(tarteaucitron.job[i]);
  939. }
  940. }
  941. },
  942. "getLanguage": function () {
  943. "use strict";
  944. if (!navigator) { return 'en'; }
  945. var availableLanguages = 'cs,en,fr,es,it,de,nl,pt,pl,ru',
  946. defaultLanguage = 'en',
  947. lang = navigator.language || navigator.browserLanguage ||
  948. navigator.systemLanguage || navigator.userLang || null,
  949. userLanguage = lang.substr(0, 2);
  950. if (tarteaucitronForceLanguage !== '') {
  951. if (availableLanguages.indexOf(tarteaucitronForceLanguage) !== -1) {
  952. return tarteaucitronForceLanguage;
  953. }
  954. }
  955. if (availableLanguages.indexOf(userLanguage) === -1) {
  956. return defaultLanguage;
  957. }
  958. return userLanguage;
  959. },
  960. "getLocale": function () {
  961. "use strict";
  962. if (!navigator) { return 'en_US'; }
  963. var lang = navigator.language || navigator.browserLanguage ||
  964. navigator.systemLanguage || navigator.userLang || null,
  965. userLanguage = lang.substr(0, 2);
  966. if (userLanguage === 'fr') {
  967. return 'fr_FR';
  968. } else if (userLanguage === 'en') {
  969. return 'en_US';
  970. } else if (userLanguage === 'de') {
  971. return 'de_DE';
  972. } else if (userLanguage === 'es') {
  973. return 'es_ES';
  974. } else if (userLanguage === 'it') {
  975. return 'it_IT';
  976. } else if (userLanguage === 'pt') {
  977. return 'pt_PT';
  978. } else if (userLanguage === 'nl') {
  979. return 'nl_NL';
  980. } else {
  981. return 'en_US';
  982. }
  983. },
  984. "addScript": function (url, id, callback, execute, attrName, attrVal) {
  985. "use strict";
  986. var script,
  987. done = false;
  988. if (execute === false) {
  989. if (typeof callback === 'function') {
  990. callback();
  991. }
  992. } else {
  993. script = document.createElement('script');
  994. script.type = 'text/javascript';
  995. script.id = (id !== undefined) ? id : '';
  996. script.async = true;
  997. script.src = url;
  998. if (attrName !== undefined && attrVal !== undefined) {
  999. script.setAttribute(attrName, attrVal);
  1000. }
  1001. if (typeof callback === 'function') {
  1002. script.onreadystatechange = script.onload = function () {
  1003. var state = script.readyState;
  1004. if (!done && (!state || /loaded|complete/.test(state))) {
  1005. done = true;
  1006. callback();
  1007. }
  1008. };
  1009. }
  1010. document.getElementsByTagName('head')[0].appendChild(script);
  1011. }
  1012. },
  1013. "makeAsync": {
  1014. "antiGhost": 0,
  1015. "buffer": '',
  1016. "init": function (url, id) {
  1017. "use strict";
  1018. var savedWrite = document.write,
  1019. savedWriteln = document.writeln;
  1020. document.write = function (content) {
  1021. tarteaucitron.makeAsync.buffer += content;
  1022. };
  1023. document.writeln = function (content) {
  1024. tarteaucitron.makeAsync.buffer += content.concat("\n");
  1025. };
  1026. setTimeout(function () {
  1027. document.write = savedWrite;
  1028. document.writeln = savedWriteln;
  1029. }, 20000);
  1030. tarteaucitron.makeAsync.getAndParse(url, id);
  1031. },
  1032. "getAndParse": function (url, id) {
  1033. "use strict";
  1034. if (tarteaucitron.makeAsync.antiGhost > 9) {
  1035. tarteaucitron.makeAsync.antiGhost = 0;
  1036. return;
  1037. }
  1038. tarteaucitron.makeAsync.antiGhost += 1;
  1039. tarteaucitron.addScript(url, '', function () {
  1040. if (document.getElementById(id) !== null) {
  1041. document.getElementById(id).innerHTML += "<span style='display:none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
  1042. tarteaucitron.makeAsync.buffer = '';
  1043. tarteaucitron.makeAsync.execJS(id);
  1044. }
  1045. });
  1046. },
  1047. "execJS": function (id) {
  1048. /* not strict because third party scripts may have errors */
  1049. var i,
  1050. scripts,
  1051. childId,
  1052. type;
  1053. if (document.getElementById(id) === null) {
  1054. return;
  1055. }
  1056. scripts = document.getElementById(id).getElementsByTagName('script');
  1057. for (i = 0; i < scripts.length; i += 1) {
  1058. type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : '';
  1059. if (type === '') {
  1060. type = (scripts[i].getAttribute('language') !== null) ? scripts[i].getAttribute('language') : '';
  1061. }
  1062. if (scripts[i].getAttribute('src') !== null && scripts[i].getAttribute('src') !== '') {
  1063. childId = id + Math.floor(Math.random() * 99999999999);
  1064. document.getElementById(id).innerHTML += '<div id="' + childId + '"></div>';
  1065. tarteaucitron.makeAsync.getAndParse(scripts[i].getAttribute('src'), childId);
  1066. } else if (type.indexOf('javascript') !== -1 || type === '') {
  1067. eval(scripts[i].innerHTML);
  1068. }
  1069. }
  1070. }
  1071. },
  1072. "fallback": function (matchClass, content, noInner) {
  1073. "use strict";
  1074. var elems = document.getElementsByTagName('*'),
  1075. i,
  1076. index = 0;
  1077. for (i in elems) {
  1078. if (elems[i] !== undefined) {
  1079. for (index = 0; index < matchClass.length; index += 1) {
  1080. if ((' ' + elems[i].className + ' ')
  1081. .indexOf(' ' + matchClass[index] + ' ') > -1) {
  1082. if (typeof content === 'function') {
  1083. if (noInner === true) {
  1084. content(elems[i]);
  1085. } else {
  1086. elems[i].innerHTML = content(elems[i]);
  1087. }
  1088. } else {
  1089. elems[i].innerHTML = content;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. }
  1095. },
  1096. "engage": function (id) {
  1097. "use strict";
  1098. var html = '',
  1099. r = Math.floor(Math.random() * 100000);
  1100. html += '<div class="tac_activate">';
  1101. html += ' <div class="tac_float">';
  1102. html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback;
  1103. html += ' <div class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
  1104. html += ' &#10003; ' + tarteaucitron.lang.allow;
  1105. html += ' </div>';
  1106. html += ' </div>';
  1107. html += '</div>';
  1108. return html;
  1109. },
  1110. "extend": function (a, b) {
  1111. "use strict";
  1112. var prop;
  1113. for (prop in b) {
  1114. if (b.hasOwnProperty(prop)) {
  1115. a[prop] = b[prop];
  1116. }
  1117. }
  1118. },
  1119. "proTemp": '',
  1120. "proTimer": function () {
  1121. "use strict";
  1122. setTimeout(tarteaucitron.proPing, 1000);
  1123. },
  1124. "pro": function (list) {
  1125. "use strict";
  1126. tarteaucitron.proTemp += list;
  1127. clearTimeout(tarteaucitron.proTimer);
  1128. tarteaucitron.proTimer = setTimeout(tarteaucitron.proPing, 2500);
  1129. },
  1130. "proPing": function () {
  1131. "use strict";
  1132. if (tarteaucitron.uuid !== '' && tarteaucitron.uuid !== undefined && tarteaucitron.proTemp !== '') {
  1133. var div = document.getElementById('tarteaucitronPremium'),
  1134. timestamp = new Date().getTime(),
  1135. url = '//opt-out.ferank.eu/premium.php?';
  1136. if (div === null) {
  1137. return;
  1138. }
  1139. url += 'domain=' + tarteaucitron.domain + '&';
  1140. url += 'uuid=' + tarteaucitron.uuid + '&';
  1141. url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
  1142. url += '_' + timestamp;
  1143. div.innerHTML = '<img src="' + url + '" style="display:none" />';
  1144. tarteaucitron.proTemp = '';
  1145. }
  1146. tarteaucitron.cookie.number();
  1147. }
  1148. };