Subversion Repositories Sites.tela-botanica.org

Rev

Rev 1125 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1125 Rev 1127
1
function ajouterStyle() {
1
function ajouterStyle() {
2
  var urlCss = "http://resources.tela-botanica.org/tb/reseau/bandeau_cnil.css";
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
3
  // http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript
4
  link = document.createElement("link");
4
  link = document.createElement("link");
5
  link.href = urlCss;
5
  link.href = urlCss;
6
  link.type = "text/css";
6
  link.type = "text/css";
7
  link.rel = "stylesheet";
7
  link.rel = "stylesheet";
8
  link.media = "screen,print";
8
  link.media = "screen,print";
9
  document.getElementsByTagName( "head" )[0].appendChild(link);
9
  document.getElementsByTagName( "head" )[0].appendChild(link);
10
}
10
}
11
 
11
 
12
function ajouterBandeau() {
12
function ajouterBandeau() {
13
  var divCookie = 
13
  var divCookie = 
14
    '<div class="bandeau" id="bandeau_cookie_cnil">'+
14
    '<div class="bandeau" id="bandeau_cookie_cnil">'+
15
    	'<div class="bandeau_cookie_cnil_titre"> Utilisation des cookies </div>'+
15
    	'<div class="bandeau_cookie_cnil_titre"> Utilisation des cookies </div>'+
16
    	'<hr />'+
16
    	'<hr />'+
17
		'<div class="avertissement_cookie">  '+
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 />'+
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>'+
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>'+
20
		'<a class="button" id="accepterCookie" onclick="javascript:accepterCookie()" href="#" > OK </a>'+
21
		'</div>'+
21
		'</div>'+
22
    '</div>';
22
    '</div>';
-
 
23
  var nDiv = document.createElement('div');
23
  document.body.innerHTML += divCookie;
24
  nDiv.innerHTML = divCookie;
-
 
25
  document.getElementsByTagName("body")[0].appendChild(nDiv);
24
}
26
}
25
 
27
 
26
function accepterCookie() {
28
function accepterCookie() {
27
  var element = document.getElementById("bandeau_cookie_cnil");
29
  var element = document.getElementById("bandeau_cookie_cnil");
28
  element.parentNode.removeChild(element);
30
  element.parentNode.removeChild(element);
29
  createCookie("cnil", 1, 365);
31
  createCookie("cnil", 1, 365);
30
  return false;
32
  return false;
31
}
33
}
32
 
34
 
33
function initialiserBandeauCnil() {
35
function initialiserBandeauCnil() {
34
    ajouterStyle();
36
    ajouterStyle();
35
    ajouterBandeau();
37
    ajouterBandeau();
36
}
38
}
37
 
39
 
38
/**
40
/**
39
 * Fonctions tirées de stackoverflow
41
 * Fonctions tirées de stackoverflow
40
 */
42
 */
41
// http://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie
43
// http://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie
42
function createCookie(name, value, days) {
44
function createCookie(name, value, days) {
43
  var expires;
45
  var expires;
44
  if (days) {
46
  if (days) {
45
      var date = new Date();
47
      var date = new Date();
46
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
48
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
47
      expires = "; expires=" + date.toGMTString();
49
      expires = "; expires=" + date.toGMTString();
48
  }
50
  }
49
  else {
51
  else {
50
      expires = "";
52
      expires = "";
51
  }
53
  }
52
  document.cookie = name + "=" + value + expires + "; path=/";
54
  document.cookie = name + "=" + value + expires + "; path=/";
53
}
55
}
54
 
56
 
55
function getCookie(c_name) {
57
function getCookie(c_name) {
56
    if (document.cookie.length > 0) {
58
    if (document.cookie.length > 0) {
57
		c_start = document.cookie.indexOf(c_name + "=");
59
		c_start = document.cookie.indexOf(c_name + "=");
58
		if (c_start != -1) {
60
		if (c_start != -1) {
59
		    c_start = c_start + c_name.length + 1;
61
		    c_start = c_start + c_name.length + 1;
60
		    c_end = document.cookie.indexOf(";", c_start);
62
		    c_end = document.cookie.indexOf(";", c_start);
61
		    if (c_end == -1) {
63
		    if (c_end == -1) {
62
		    	c_end = document.cookie.length;
64
		    	c_end = document.cookie.length;
63
		    }
65
		    }
64
		    return unescape(document.cookie.substring(c_start, c_end));
66
		    return unescape(document.cookie.substring(c_start, c_end));
65
		}
67
		}
66
    }
68
    }
67
    return "";
69
    return "";
68
}
70
}
69
 
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) {
70
//http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery#answer-18775368
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);
71
document.onreadystatechange = function () {
102
		doc[add](pre + 'readystatechange', init, false);
-
 
103
		win[add](pre + 'load', init, false);
-
 
104
	}
-
 
105
 
-
 
106
}
-
 
107
 
-
 
108
 
-
 
109
/**
-
 
110
 * Initialisation
-
 
111
 */
72
	// tant pis pour les vieux navigateurs qui ne supportent pas document.readyState
112
var tIdBandeau = setInterval(function() {
73
	if (document.readyState == "complete") {
113
	if (document.readyState == "complete") {
-
 
114
	    clearInterval(tIdBandeau);    
74
		var cookieCnil = getCookie("cnil");
115
	    var cookieCnil = getCookie("cnil");
75
	    if(cookieCnil == null || cookieCnil != 1) {
116
		if(cookieCnil == null || cookieCnil != 1) {
76
	    	initialiserBandeauCnil();
117
			initialiserBandeauCnil();
77
	    }
118
		} 
78
	}
119
	}
79
}
-
 
80
120
}, 200);
-
 
121
81
122