Subversion Repositories Sites.tela-botanica.org

Rev

Rev 1125 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1125 aurelien 1
function ajouterStyle() {
2
  var urlCss = "http://resources.tela-botanica.org/tb/reseau/bandeau_cnil.css";
3
  // http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript
4
  link = document.createElement("link");
5
  link.href = urlCss;
6
  link.type = "text/css";
7
  link.rel = "stylesheet";
8
  link.media = "screen,print";
9
  document.getElementsByTagName( "head" )[0].appendChild(link);
10
}
11
 
12
function ajouterBandeau() {
13
  var divCookie =
14
    '<div class="bandeau" id="bandeau_cookie_cnil">'+
15
    	'<div class="bandeau_cookie_cnil_titre"> Utilisation des cookies </div>'+
16
    	'<hr />'+
17
		'<div class="avertissement_cookie">  '+
18
		'Le site de Tela Botanica utilise des cookies. En poursuivant votre navigation sur le site, vous acceptez l\'utilisation de ces cookies qui permettent notamment de se souvenir de vos pr&eacute;f&eacute;rences. <br />'+
19
		'<a class="en_savoir_plus" target="_blank" href="http://www.tela-botanica.org/page:licence"> En savoir plus</a>'+
20
		'<a class="button" id="accepterCookie" onclick="javascript:accepterCookie()" href="#" > OK </a>'+
21
		'</div>'+
22
    '</div>';
1127 aurelien 23
  var nDiv = document.createElement('div');
24
  nDiv.innerHTML = divCookie;
25
  document.getElementsByTagName("body")[0].appendChild(nDiv);
1125 aurelien 26
}
27
 
28
function accepterCookie() {
29
  var element = document.getElementById("bandeau_cookie_cnil");
30
  element.parentNode.removeChild(element);
31
  createCookie("cnil", 1, 365);
32
  return false;
33
}
34
 
35
function initialiserBandeauCnil() {
36
    ajouterStyle();
37
    ajouterBandeau();
38
}
39
 
40
/**
41
 * Fonctions tirées de stackoverflow
42
 */
43
// http://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie
44
function createCookie(name, value, days) {
45
  var expires;
46
  if (days) {
47
      var date = new Date();
48
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
49
      expires = "; expires=" + date.toGMTString();
50
  }
51
  else {
52
      expires = "";
53
  }
54
  document.cookie = name + "=" + value + expires + "; path=/";
55
}
56
 
57
function getCookie(c_name) {
58
    if (document.cookie.length > 0) {
59
		c_start = document.cookie.indexOf(c_name + "=");
60
		if (c_start != -1) {
61
		    c_start = c_start + c_name.length + 1;
62
		    c_end = document.cookie.indexOf(";", c_start);
63
		    if (c_end == -1) {
64
		    	c_end = document.cookie.length;
65
		    }
66
		    return unescape(document.cookie.substring(c_start, c_end));
67
		}
68
    }
69
    return "";
70
}
1127 aurelien 71
 
72
function contentLoaded(win, fn) {
73
 
74
	var done = false, top = true,
75
 
76
	doc = win.document,
77
	root = doc.documentElement,
78
	modern = doc.addEventListener,
79
 
80
	add = modern ? 'addEventListener' : 'attachEvent',
81
	rem = modern ? 'removeEventListener' : 'detachEvent',
82
	pre = modern ? '' : 'on',
83
 
84
	init = function(e) {
85
		if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
86
		(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
87
		if (!done && (done = true)) fn.call(win, e.type || e);
88
	},
89
 
90
	poll = function() {
91
		try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
92
		init('poll');
93
	};
94
 
95
	if (doc.readyState == 'complete') fn.call(win, 'lazy');
96
	else {
97
		if (!modern && root.doScroll) {
98
			try { top = !win.frameElement; } catch(e) { }
99
			if (top) poll();
100
		}
101
		doc[add](pre + 'DOMContentLoaded', init, false);
102
		doc[add](pre + 'readystatechange', init, false);
103
		win[add](pre + 'load', init, false);
104
	}
105
 
106
}
107
 
108
 
109
/**
110
 * Initialisation
111
 */
112
var tIdBandeau = setInterval(function() {
1125 aurelien 113
	if (document.readyState == "complete") {
1127 aurelien 114
	    clearInterval(tIdBandeau);
115
	    var cookieCnil = getCookie("cnil");
116
		if(cookieCnil == null || cookieCnil != 1) {
117
			initialiserBandeauCnil();
118
		}
1125 aurelien 119
	}
1127 aurelien 120
}, 200);