-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
76 lines (64 loc) · 1.61 KB
/
script.js
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
var tab = [];
class ListItem {
constructor(mes, disp) {
if (typeof(mes) === 'string') {
this.mes = mes;
}
else {
console.error('mes not string');
}
if (typeof(disp) === 'boolean') {
this.disp = disp;
}
else {
console.error('disp not bool');
};
};
};
function load() {
$('li').remove();
tab=JSON.parse(localStorage.getItem('tab'));
$.each(tab, function (index, obj) {
if (obj.disp == true) {
$('ul').append("<li class=\"notclique\">"+obj.mes+"</li>");
}
else {
$('ul').append("<li class=\"clique\">"+obj.mes+"</li>");
}
});
};
$(document).ready(function () {
$('#add_todo').click(function () {
$('ul').append("<li class=\"notclique\">"+$('#name_of_todo').val()+"</li>");
$('#name_of_todo').val("");
});
$('ul').on("click", "li", function () {
$(this).toggleClass("notclique");
$(this).toggleClass("clique");
});
if(typeof(Storage) !== "undefined") {
if (localStorage.getItem('tab') != null) {
load();
}
$('#save').click( function () {
tab = [];
$('li').each(function(){
if($(this).hasClass('clique')){
tab.push(new ListItem($(this).text(), false));
}
else {
tab.push(new ListItem($(this).text(), true));
}
});
localStorage.setItem('tab', JSON.stringify(tab));
});
$('#load').click(load());
$('#rm').click( function () {
localStorage.removeItem('tab');
$('li').remove();
});
}
else {
alert("Malheureusement votre navigateur ne permet pas de sauvegarder vos todo");
}
});