-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo2.js
77 lines (63 loc) · 2.28 KB
/
todo2.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
77
/// <reference path="C:\Users\TARPA\Desktop\JSExercise\typings\globals\jquery\index.d.ts" />
$(document).ready(function () {
$(document).ready(c(), display());
$("#add").click(function () {
var a = JSON.parse(localStorage.getItem("todo2"));
var input = $("input[name = task]").val();
if (a == null) {
var z = [];
z.push(input);
localStorage.setItem("todo2", JSON.stringify(z));
} else {
if (input == "") {
$("span").css("display", "inline").fadeOut(1500);
} else {
var d = JSON.parse(localStorage.getItem("todo2"));
d.push(input);
localStorage.setItem("todo2", JSON.stringify(d));
}
}
$("input[name = task]").val("");
c();
refresh();
})
function c() {
var a = JSON.parse(localStorage.getItem("todo2"));
if (a == null) {
$("div:nth-child(2)").html("<b> You Have No Task For Today !!! </b>");
} else if (a == 0) {
$("div:nth-child(2)").html("<b>You Have No Task For Today !!!</b>");
}
else {
$("div:nth-child(2)").html("Task You Have : <b>" + a.length + "</b> For Today!!!");
}
}
function display() {
var a = JSON.parse(localStorage.getItem("todo2"));
if (a == null) {
} else {
$("ul").empty();
for (let i = a.length - 1; i >= 0; i--) {
var createLI = $("<li></li>").attr({ "id": "list", "class": "list-group-item" }).text(a[i]);
var createBtn = $("<a></a>").attr({
"href": "#", "class": "close",
"value": i, "aria-hidden": "true"
}).text("x");
createLI.append(createBtn);
$("#todo").append(createLI);
}
}
}
function refresh() {
$("li").empty();
display();
c();
}
$('#todo').on('click', 'a', function () {
var update = JSON.parse(localStorage.getItem("todo2"));
update.splice(Number($(this).val()), 1);
console.log(update);
localStorage.setItem("todo2", JSON.stringify(update));
refresh();
});
});