Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. index
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9.  
  10. <link rel="stylesheet" type="text/css" href="style.css">
  11. </head>
  12. <body>
  13.  
  14.  
  15. <h1>To-Do List</h1>
  16. <div class="container">
  17. <form action="#">
  18. <input type="text" name="item" id="item" placeholder="Add New" />
  19. <input type="date" id="date" name="to-do-start" value="2018-07-22">
  20. <button type="button" id="add-me-button" class="add-me-button">Add Me</button>
  21. </form>
  22.  
  23. <ul id="list"></ul>
  24.  
  25. </div>
  26.  
  27. <script src="js.js"></script>
  28. </body>
  29. </html>
  30. =====
  31.  
  32. style
  33. body {
  34. background: #eee;
  35. color: #444;
  36. font-family: 'Helvetica', arial, sans-serif;
  37. }
  38.  
  39.  
  40. .container {
  41. background: #fff;
  42. max-width: 600px;
  43. width: 100%;
  44. display: table;
  45. margin: 0 auto;
  46. margin-top: 40px;
  47. border: 2px solid #cfcbcc;
  48. }
  49.  
  50. .add-me-button {
  51. -webkit-transition-duration: 0.4s; /* Safari */
  52. transition-duration: 0.4s;
  53. margin: 20px;
  54. padding: 10px;
  55. }
  56.  
  57. .add-me-button:hover {
  58. background-color: rgb(175, 30, 156);
  59. color: white;
  60. }
  61. input {
  62. border: none;
  63. display: block;
  64. width: 98.4%;
  65. line-height: 1.5;
  66. padding: 8px 0 8px 10px;
  67. border-bottom: 1px solid #cfcbcc;
  68. outline: 0;
  69. }
  70. h1, h2 {
  71. text-align: center;
  72. margin-bottom: 0px;
  73. line-height: 1;
  74. }
  75. h2 {
  76. color: gray;
  77. }
  78. ul {
  79. list-style: none;
  80. margin: 0;
  81. padding: 0;
  82. }
  83. ul li {
  84. color: #899098;
  85. font-weight: 400;
  86. border-bottom: 1px solid #cfcbcc;
  87. line-height: 1.5;
  88. padding: 8px 0;
  89. }
  90. ul li:before {
  91. content: "\25A1";
  92. padding: 10px 10px;
  93. font-size: 20px;
  94. }
  95. ul li:hover {
  96. text-decoration: line-through;
  97. cursor: pointer;
  98. }
  99. ul li:last-child {
  100. border-bottom: none;
  101. }
  102. .checked {
  103. color: green;
  104. }
  105. .checked:before {
  106. content: "\2713";
  107. padding: 10px;
  108. font-size: 20px;
  109. }
  110. .checked:hover {
  111. text-decoration: none;
  112. }
  113. .checked:hover:after {
  114. content: " (click to remove this)";
  115. color: tomato;
  116. text-align: right;
  117. }
  118.  
  119. ===
  120.  
  121. js
  122. (function(){
  123.  
  124. var list = document.querySelector('#list');
  125. var form = document.querySelector('form');
  126. var item = document.querySelector('#item');
  127. var date = document.getElementById('date').value;
  128. var collection = [];
  129.  
  130. /*
  131. form.addEventListener('submit',function(e){
  132. e.preventDefault();
  133. list.innerHTML += ` <li> <b>Name: </b>${item.value} <br> <b>Deadline:</b> ${date} </li> `;
  134. collection.push({item,date});
  135. console.log(collection);
  136.  
  137. store();
  138. item.value = "";
  139. },false) */
  140.  
  141. var addButton = document.getElementById("add-me-button");
  142.  
  143. function myFunction() {
  144. list.innerHTML += `<li><b>Name: </b>${item.value} / <b>Deadline:</b> ${date} </li> `;
  145. collection.push({item,date});
  146. store();
  147. item.value = "";
  148. date.value = "";
  149. }
  150.  
  151. addButton.addEventListener('click', () => {
  152. var title = document.querySelector('#item');
  153.  
  154. var flag = false;
  155.  
  156. for (i = 0; i < collection.length; i++) {
  157. if (collection[i].item == title && collection[i].date == date) {
  158. flag = true;
  159. }
  160. }
  161.  
  162. if (collection.length > 0 && flag == true) {
  163. alert("You cannot add two identical items for the same date sorry.");
  164. }
  165.  
  166. if (flag == false && title != '' && date != '') {
  167. myFunction();
  168. }
  169. })
  170.  
  171. list.addEventListener('click',function(e){
  172. var t = e.target;
  173. if(t.classList.contains('checked')){
  174. t.parentNode.removeChild(t);
  175. } else {
  176. t.classList.add('checked');
  177. }
  178. store();
  179. },false)
  180.  
  181. function store() {
  182. window.localStorage.myitems = list.innerHTML;
  183. }
  184.  
  185. function getValues() {
  186. var storedValues = window.localStorage.myitems;
  187. if(!storedValues) {
  188. list.innerHTML = '<li><b>Name: </b> Some item here / <b>Deadline: </b> 2018-07-22</li>';
  189. }
  190. else {
  191. list.innerHTML = storedValues;
  192. }
  193. }
  194. getValues();
  195. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement