notes.js
3.77 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
$(function () {
function removeNote() {
$(".remove-note")
.off("click")
.on("click", function (event) {
event.stopPropagation();
$(this).parents(".single-note-item").remove();
});
}
function favouriteNote() {
$(".favourite-note")
.off("click")
.on("click", function (event) {
event.stopPropagation();
$(this).parents(".single-note-item").toggleClass("note-favourite");
});
}
var $btns = $(".note-link").click(function () {
if (this.id == "all-category") {
var $el = $("." + this.id).fadeIn();
$("#note-full-container > div").not($el).hide();
}
if (this.id == "important") {
var $el = $("." + this.id).fadeIn();
$("#note-full-container > div").not($el).hide();
} else {
var $el = $("." + this.id).fadeIn();
$("#note-full-container > div").not($el).hide();
}
$btns.removeClass("active");
$(this).addClass("active");
});
$("#add-notes").on("click", function (event) {
HSOverlay.open("#notes-modal");
$("#btn-n-save").hide();
$("#btn-n-add").show();
});
// Button add
$("#btn-n-add").on("click", function (event) {
event.preventDefault();
/* Act on the event */
var today = new Date();
var dd = String(today.getDate()).padStart(2, "0");
var mm = String(today.getMonth()); //January is 0!
var yyyy = today.getFullYear();
var monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
today = dd + " " + monthNames[mm] + " " + yyyy;
var $_noteTitle = document.getElementById("note-has-title").value;
var $_noteDescription = document.getElementById(
"note-has-description"
).value;
$html =
'<div class="lg:col-span-4 md:col-span-4 sm:col-span-6 single-note-item all-category"><div class="card card-body sm:px-7">' +
'<span class="side-stick"></span>' +
'<h6 class="font-medium text-sm text-dark dark:text-white" data-noteHeading="' +
$_noteTitle +
'">' +
$_noteTitle +
'</h6>' +
'<p class="note-date text-xs">' +
today +
"</p>" +
'<div class="note-content mt-3">' +
'<p class="note-inner-content text-sm" data-noteContent="' +
$_noteDescription +
'">' +
$_noteDescription +
"</p>" +
"</div>" +
'<div class="flex items-center mt-3">' +
'<a href="javascript:void(0)" class="link me-1"><i class="ti ti-star text-base favourite-note text-dark dark:text-darklink hover:text-primary dark:hover:text-primary"></i></a>' +
'<a href="javascript:void(0)" class="link text-error ms-2"><i class="ti ti-trash text-base remove-note"></i></a>' +
"</div>"+
"</div> ";
$("#note-full-container").prepend($html);
HSOverlay.close("#notes-modal");
removeNote();
favouriteNote();
});
removeNote();
favouriteNote();
$("#btn-n-add").attr("disabled", "disabled");
});
$("#note-has-title").keyup(function () {
var empty = false;
$("#note-has-title").each(function () {
if ($(this).val() == "") {
empty = true;
}
});
if (empty) {
$("#btn-n-add").attr("disabled", "disabled");
} else {
$("#btn-n-add").removeAttr("disabled");
}
});