-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (49 loc) · 1.6 KB
/
script.js
File metadata and controls
51 lines (49 loc) · 1.6 KB
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
$(document).ready(function () {
for (var x = 0; x < Object.keys(localStorage).length; x += 1){
$("#todoContainer").append("<div class=todoItem>" + localStorage.getItem(x.toString()) + "</div>");
}
Sortable.create(todoContainer, { animation: 150, chosenClass: "todoItemSelect"});
if ($('#todoContainer').children().length !== 0) {
$("#noNotes").hide();
}
$("#txtNewEntry").bind("enterKey", function () {
addNote();
});
$("#txtNewEntry").keyup(function (e) {
if (e.keyCode === 13) {
$(this).trigger("enterKey");
}
});
// remove by event delegation
$("#todoContainer").on("click", ".todoItem", function () {
$(this).remove();
$("#txtNewEntry").focus();
if ($('#todoContainer').children().length === 0) {
$("#noNotes").show();
}
});
function addNote() {
if ($("#txtNewEntry").val().length > 0) {
if ($('#todoContainer').children().length === 0) {
$("#noNotes").hide();
}
$("#todoContainer").prepend("<div class=todoItem>" + $("#txtNewEntry").val() + "</div>");
$("#txtNewEntry").val("");
$("#txtNewEntry").focus();
}
}
$(document).keyup(function (e) {
if (e.keyCode === 13) {
$("#txtNewEntry").focus();
}
if (e.keyCode === 27) {
$("#txtNewEntry").blur();
}
});
});
window.onbeforeunload = function () {
localStorage.clear();
$(".todoItem").each(function (index) {
localStorage.setItem(index, $(this).text());
});
};