質問編集履歴

1

インデントを修正しました。

2019/06/03 23:27

投稿

vankick
vankick

スコア22

test CHANGED
File without changes
test CHANGED
@@ -46,11 +46,9 @@
46
46
 
47
47
  </div>
48
48
 
49
+
50
+
49
- <script>
51
+ <script>
50
-
51
-
52
-
53
-
54
52
 
55
53
  const data = [
56
54
 
@@ -150,81 +148,75 @@
150
148
 
151
149
  const markup = `
152
150
 
153
- <li id="${doggo}">
151
+ <li id="${doggo}">
152
+
154
-
153
+ <svg class="icon icon-heart-outlined">
154
+
155
- <svg class="icon icon-heart-outlined"><use xlink:href="icon/sprite.svg#icon-heart-outlined"></use></svg>
155
+ <use xlink:href="icon/sprite.svg#icon-heart-outlined"></use>
156
+
157
+ </svg>
156
158
 
157
159
  ${doggo}
158
160
 
159
161
  </li>
160
162
 
161
- `;
163
+ `;
162
-
163
-
164
-
164
+
165
- elements.dom.insertAdjacentHTML('beforeend', markup);
165
+ elements.dom.insertAdjacentHTML('beforeend', markup);
166
+
167
+ }
168
+
169
+
170
+
171
+ const likeTemplate = i => `<p>${i}</p>`;
172
+
173
+
174
+
175
+ const renderLikes = () => {
176
+
177
+ $likelist.innerHTML = likes.map(i => likeTemplate(i)).join('');
178
+
179
+ }
180
+
181
+
182
+
183
+ elements.dom.addEventListener('click', e => {
184
+
185
+
186
+
187
+ const id = e.target.parentNode.id;
188
+
189
+
190
+
191
+ if (e.target.matches('.icon, .icon *')) {
192
+
193
+
194
+
195
+ const index = likes.indexOf(e.target.parentNode.id);
196
+
197
+
198
+
199
+ // If (Beagle, Golden Retriever... doesn't exist in likes array, it returns -1)
200
+
201
+ if (index === -1) {
202
+
203
+ likes.push(id);
204
+
205
+ renderLikes();
206
+
207
+ } else {
208
+
209
+ likes.splice(index, 1);
210
+
211
+ renderLikes();
212
+
213
+ }
166
214
 
167
215
  }
168
216
 
169
-
170
-
171
- const likeTemplate = i => `<p>${i}</p>`;
172
-
173
- const renderLikes = () => {
174
-
175
- $likelist.innerHTML = likes.map(i => likeTemplate(i)).join('');
176
-
177
- }
178
-
179
-
180
-
181
- elements.dom.addEventListener('click', e => {
182
-
183
-
184
-
185
-
186
-
187
- const id = e.target.parentNode.id;
188
-
189
-
190
-
191
- if (e.target.matches('.icon, .icon *')) {
192
-
193
-
194
-
195
- // If (Beagle, Golden Retriever... does not exist in likes array, it returns -1)
196
-
197
- const index = likes.indexOf(e.target.parentNode.id);
198
-
199
-
200
-
201
- if (index === -1) {
202
-
203
-
204
-
205
- likes.push(id);
206
-
207
- renderLikes();
208
-
209
-
210
-
211
- console.log(likes);
212
-
213
- } else {
214
-
215
- likes.splice(index, 1);
216
-
217
- renderLikes();
218
-
219
- console.log("updated list", likes);
220
-
221
- }
222
-
223
- }
224
-
225
217
  });
226
218
 
227
- </script>
219
+ </script>
228
220
 
229
221
  </body>
230
222