lavkach3

Форк
0
170 строк · 5.6 Кб
1
$(function () {
2
  function removeNote() {
3
    $(".remove-note")
4
      .off("click")
5
      .on("click", function (event) {
6
        event.stopPropagation();
7
        $(this).parents(".single-note-item").remove();
8
      });
9
  }
10

11
  function favouriteNote() {
12
    $(".favourite-note")
13
      .off("click")
14
      .on("click", function (event) {
15
        event.stopPropagation();
16
        $(this).parents(".single-note-item").toggleClass("note-favourite");
17
      });
18
  }
19

20
  function addLabelGroups() {
21
    $(".category-selector .badge-group-item")
22
      .off("click")
23
      .on("click", function (event) {
24
        event.preventDefault();
25
        /* Act on the event */
26
        var getclass = this.className;
27
        var getSplitclass = getclass.split(" ")[0];
28
        if ($(this).hasClass("badge-business")) {
29
          $(this).parents(".single-note-item").removeClass("note-social");
30
          $(this).parents(".single-note-item").removeClass("note-important");
31
          $(this).parents(".single-note-item").toggleClass(getSplitclass);
32
        } else if ($(this).hasClass("badge-social")) {
33
          $(this).parents(".single-note-item").removeClass("note-business");
34
          $(this).parents(".single-note-item").removeClass("note-important");
35
          $(this).parents(".single-note-item").toggleClass(getSplitclass);
36
        } else if ($(this).hasClass("badge-important")) {
37
          $(this).parents(".single-note-item").removeClass("note-social");
38
          $(this).parents(".single-note-item").removeClass("note-business");
39
          $(this).parents(".single-note-item").toggleClass(getSplitclass);
40
        }
41
      });
42
  }
43

44
  var $btns = $(".note-link").click(function () {
45
    if (this.id == "all-category") {
46
      var $el = $("." + this.id).fadeIn();
47
      $("#note-full-container > div").not($el).hide();
48
    }
49
    if (this.id == "important") {
50
      var $el = $("." + this.id).fadeIn();
51
      $("#note-full-container > div").not($el).hide();
52
    } else {
53
      var $el = $("." + this.id).fadeIn();
54
      $("#note-full-container > div").not($el).hide();
55
    }
56
    $btns.removeClass("active");
57
    $(this).addClass("active");
58
  });
59

60
  $("#add-notes").on("click", function (event) {
61
    $("#addnotesmodal").modal("show");
62
    $("#btn-n-save").hide();
63
    $("#btn-n-add").show();
64
  });
65

66
  // Button add
67
  $("#btn-n-add").on("click", function (event) {
68
    event.preventDefault();
69
    /* Act on the event */
70
    var today = new Date();
71
    var dd = String(today.getDate()).padStart(2, "0");
72
    var mm = String(today.getMonth()); //January is 0!
73
    var yyyy = today.getFullYear();
74
    var monthNames = [
75
      "Jan",
76
      "Feb",
77
      "Mar",
78
      "Apr",
79
      "May",
80
      "Jun",
81
      "Jul",
82
      "Aug",
83
      "Sep",
84
      "Oct",
85
      "Nov",
86
      "Dec",
87
    ];
88
    today = dd + " " + monthNames[mm] + " " + yyyy;
89

90
    var $_noteTitle = document.getElementById("note-has-title").value;
91
    var $_noteDescription = document.getElementById(
92
      "note-has-description"
93
    ).value;
94

95
    $html =
96
      '<div class="col-md-4 single-note-item all-category"><div class="card card-body">' +
97
      '<span class="side-stick"></span>' +
98
      '<h6 class="note-title text-truncate w-75 mb-0" data-noteHeading="' +
99
      $_noteTitle +
100
      '">' +
101
      $_noteTitle +
102
      "</h6>" +
103
      '<p class="note-date fs-2">' +
104
      today +
105
      "</p>" +
106
      '<div class="note-content">' +
107
      '<p class="note-inner-content" data-noteContent="' +
108
      $_noteDescription +
109
      '">' +
110
      $_noteDescription +
111
      "</p>" +
112
      "</div>" +
113
      '<div class="d-flex align-items-center">' +
114
      '<a href="javascript:void(0)" class="link me-1"><i class="ti ti-star fs-4 favourite-note"></i></a>' +
115
      '<a href="javascript:void(0)" class="link text-danger ms-2"><i class="ti ti-trash fs-4 remove-note"></i></a>' +
116
      '<div class="ms-auto">' +
117
      '<div class="category-selector btn-group">' +
118
      '<a class="nav-link category-dropdown label-group p-0" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="true">' +
119
      '<div class="category">' +
120
      '<div class="category-business"></div>' +
121
      '<div class="category-social"></div>' +
122
      '<div class="category-important"></div>' +
123
      '<span class="more-options text-dark"><i class="ti ti-dots-vertical fs-5"></i></span>' +
124
      "</div>" +
125
      "</a>" +
126
      '<div class="dropdown-menu dropdown-menu-right category-menu">' +
127
      '<a class="note-business badge-group-item badge-business dropdown-item position-relative category-business" href="javascript:void(0);">Business</a>' +
128
      '<a class="note-social badge-group-item badge-social dropdown-item position-relative category-social" href="javascript:void(0);"> Social</a>' +
129
      '<a class="note-important badge-group-item badge-important dropdown-item position-relative category-important" href="javascript:void(0);"> Important</a>' +
130
      "</div>" +
131
      "</div>" +
132
      "</div>" +
133
      "</div>" +
134
      "</div></div> ";
135

136
    $("#note-full-container").prepend($html);
137
    $("#addnotesmodal").modal("hide");
138

139
    removeNote();
140
    favouriteNote();
141
    addLabelGroups();
142
  });
143

144
  $("#addnotesmodal").on("hidden.bs.modal", function (event) {
145
    event.preventDefault();
146
    document.getElementById("note-has-title").value = "";
147
    document.getElementById("note-has-description").value = "";
148
  });
149

150
  removeNote();
151
  favouriteNote();
152
  addLabelGroups();
153

154
  $("#btn-n-add").attr("disabled", "disabled");
155
});
156

157
$("#note-has-title").keyup(function () {
158
  var empty = false;
159
  $("#note-has-title").each(function () {
160
    if ($(this).val() == "") {
161
      empty = true;
162
    }
163
  });
164

165
  if (empty) {
166
    $("#btn-n-add").attr("disabled", "disabled");
167
  } else {
168
    $("#btn-n-add").removeAttr("disabled");
169
  }
170
});
171

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.