Guest User

Untitled

a guest
Mar 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. $(document).ready(function() {
  2. $("#tasksList").html(localStorage.getItem("tasksList"));
  3.  
  4. $(function() {
  5. var $tasksList = $("#tasksList");
  6. var $taskInput = $("#taskInput");
  7. var $notification = $("#notification");
  8.  
  9. var displayNotification = function() {
  10. if (!$tasksList.children().length) {
  11. $notification.fadeIn("fast");
  12. } else {
  13. $notification.css("display", "none");
  14. }
  15. };
  16.  
  17. $("#taskAdd").on("click", function() {
  18. if (!$taskInput.val()) {
  19. alert("Ошибка, заполните поле");
  20. return false;
  21. }
  22.  
  23. $tasksList.append(
  24. "<li>" +
  25. $taskInput.val() +
  26. "<button class='delete'>&#10006</button></li>"
  27. );
  28. localStorage.setItem("tasksList", $("#tasksList").html());
  29.  
  30. $taskInput.val("");
  31.  
  32. displayNotification();
  33.  
  34. $(".delete").on("click", function() {
  35. var $parent = $(this).parent();
  36.  
  37. $parent.css("animation", "fadeOut .3s linear");
  38.  
  39. setTimeout(function() {
  40. $parent.remove();
  41.  
  42. displayNotification();
  43. }, 295);
  44. });
  45. });
  46. });
  47. });
Add Comment
Please, Sign In to add comment