-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.js
77 lines (66 loc) · 2.27 KB
/
todo.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
$(document).ready(function(){
var addTask = function(value, priority){
//var priority;
if(typeof priority !== "string"){priority = $("input:radio[name='priority']:checked").val();}
var cls;
var exc;
if(priority === "high"){
cls = "btn-danger";
exc = "Chop-chop!"
}
else if(priority === "med"){
cls = "btn-warning";
exc = "Watch out.."
}
else {
cls = "btn-success";
exc = "You can do it"
}
console.log('value= ' + value + ' priority= ' + priority);
if(typeof value !== "string"){value = $('#newtask').val(); }
localStorage.setItem(value, priority);
$("#list").append("<div><blockquote><span class='tasktext'>" + value + "</span><button class='btn " + cls + "'>" + exc + "</button><button class='btn btn-default del'>x</button></blockquote></div>");
$("#list blockquote").last().hide();
$("#list blockquote").last().slideDown();
$("#newtask").val("");
$(".btn").css("margin-left", "8");
if(priority === "high"){
$("#list blockquote .tasktext").last().addClass("lead");
}
else {
$("#list blockquote .tasktext").last().css("font-size", "16");
}
$('.del').click(function(event){
$(this).parent().slideUp();
console.log($(this).parent().children('span').text());
localStorage.removeItem($(this).parent().children('span').text());
});
};
if(localStorage.length > 0){
for(var item in localStorage){
var priority = localStorage.getItem(item);
// console.log(item + ' ' + priority);
addTask(item, priority);
// if(priority === "high"){
// cls = "btn-danger";
// exc = "Chop-chop!"
// }
// else if(priority === "med"){
// cls = "btn-warning";
// exc = "Watch out.."
// }
// else {
// cls = "btn-success";
// exc = "You can do it"
// }
// $('#list').append("<div><blockquote><span class='tasktext'>" + item + "</span><button class='btn " + cls + "'>" + exc + "</button><button class='btn btn-default del'>x</button></blockquote></div>");
//localStorage.clear();
};
}
$("#newtask").keypress(function(key){
if(key.which === 13){
addTask();
}
});
$("#newtaskbutton").click(addTask);
});