File: Sauvegardes.js

package info (click to toggle)
openboard 1.7.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 57,404 kB
  • sloc: cpp: 76,443; javascript: 10,089; xml: 234; ansic: 38; makefile: 23; sh: 8
file content (106 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Fonctions permettant de sauvegarder les options

var optionsLoaded = false;

function setCookie(nom,valeur){
	var jours = 545; // Durée de validité des cookies
	var date = new Date();
	date.setDate(date.getDate()+jours);
	document.cookie = nom + "=" + escape(valeur) + "; expires="+date.toGMTString();
}

function getCookie(nom){
	var start = 0;
	var end = 0;
	if(document.cookie.length>0){
		start = document.cookie.indexOf(nom + "=");
		if(start!=-1){
			start = start + nom.length+1;
			end = document.cookie.indexOf(";",start);
			if(end==-1){
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(start,end));
		}
	}
	return "";
}

function delCookie(nom){
	var date = new Date();
	date.setDate(date.getDate()-1);
	document.cookie = nom + "=; expires="+date.toGMTString();
}

function saveOptions(){
	if(!optionsLoaded){
		return;
	}
	var state = JSON.stringify(widget.getState());
	if(window.sankore){
		sankore.setPreference("state", state);
	}
	else if(navigator.cookieEnabled){
		setCookie("state", state);
	}
}

async function loadOptions(){
	var state;
	if(window.sankore){
        state = await sankore.async.preference("state", null);
	}
	else if(navigator.cookieEnabled){
		state = getCookie("state");
	}
	if(!state){
		optionsLoaded = true;
		return;
	}
	var stateObject = JSON.parse(state);
	var goodState = widget.getState();
	if(!checkState(stateObject, goodState)){
		loadOptionsFailed();
	}
	try{
		widget.setState(stateObject);
		optionsLoaded = true;
	}
	catch(e){
		loadOptionsFailed();
	}
}

function loadOptionsFailed(){
	var text = "Unable to load the saved parameters...";
	try{
		text = languages.getText("unableLoadParameters");
	}
	catch(e){}
	alert(text);
	delOptions();
}

function checkState(state, goodState){
	for(var i in goodState){
		if(! i in state){
			return false;
		}
	}
	return true;
}

function delOptions(){
	if(window.sankore){
		sankore.setPreference("state", "");
	}
	else if(navigator.cookieEnabled){
		delCookie("state");
	}
}

function alertOptions(){
// 	alert("Options actuellement sauvegardées\n------------------------------------------------------------\n"+document.cookie);
	document.getElementById("divAlertCookies").innerHTML = document.cookie;
	afficherMenu("menuAlertCookies");
}