Completed
Push — dev5 ( 76b71a...013a5b )
by Ron
11:53
created

resources/js/template_files/todolist.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 34
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 20
mnd 2
bc 2
fnc 5
dl 0
loc 34
rs 10
bpm 0.4
cpm 1.4
noi 0
c 0
b 0
f 0
1
(function($) {
2
  'use strict';
3
  $(function() {
4
    var todoListItem = $('.todo-list');
5
    var todoListInput = $('.todo-list-input');
6
    $('.todo-list-add-btn').on("click", function(event) {
7
      event.preventDefault();
8
9
      var item = $(this).prevAll('.todo-list-input').val();
10
11
      if (item) {
12
        todoListItem.append("<li><div class='form-check'><label class='form-check-label'><input class='checkbox' type='checkbox'/>" + item + "<i class='input-helper'></i></label></div><i class='remove ti-trash'></i></li>");
13
        todoListInput.val("");
14
      }
15
16
    });
17
18
    todoListItem.on('change', '.checkbox', function() {
19
      if ($(this).attr('checked')) {
20
        $(this).removeAttr('checked');
21
      } else {
22
        $(this).attr('checked', 'checked');
23
      }
24
25
      $(this).closest("li").toggleClass('completed');
26
27
    });
28
29
    todoListItem.on('click', '.remove', function() {
30
      $(this).parent().remove();
31
    });
32
33
  });
34
})(jQuery);