-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfavoritos.js
40 lines (36 loc) · 1.26 KB
/
favoritos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var database = firebase.database();
var USER_ID = window.location.search.match(/\?id=(.*)/)[1];
$(document).ready(function() {
database.ref('favorites/' + USER_ID).once('value').then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
createFavorite(childData.url, childData.title, childKey);
});
});
function createFavorite(url, title, key) {
$(".favorite-list").append(`
<div class="row">
<div class="col s12 m6">
<div class="card">
<div id="card-image" class="card-image">
<img src="${url}">
</div>
<div class="card-content my-text-center">
<p id="gif-title">${title}</p>
<br>
<div class="my-d-flex">
<button class="waves-light btn" data-delete-id="${key}" >Deletar</button>
</div>
</div>
</div>
</div>
</div>
</div>
`);
$(`button[data-delete-id=${key}]`).click(function() {
$(this).closest('.row').remove().fadeOut('slow');
database.ref('favorites/'+ USER_ID + "/" + key).remove();
});
}
});