mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-24 00:35:59 +00:00
Add likebutton.js
This commit is contained in:
parent
1a423ce139
commit
f65ce65ddd
1 changed files with 29 additions and 0 deletions
29
resources/assets/js/components/likebutton.js
vendored
Normal file
29
resources/assets/js/components/likebutton.js
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
$(document).ready(function() {
|
||||
if(!ls.get('likes')) {
|
||||
ls.set('likes', []);
|
||||
}
|
||||
|
||||
$('.like-form').submit(function(e) {
|
||||
e.preventDefault();
|
||||
var el = $(this);
|
||||
var id = el.data('id');
|
||||
var res = axios.post('/i/like', {item: id});
|
||||
var likes = ls.get('likes');
|
||||
var action = false;
|
||||
var counter = el.parent().parent().find('.like-count');
|
||||
var count = parseInt(counter.text());
|
||||
if(likes.indexOf(id) > -1) {
|
||||
likes.splice(id, 1);
|
||||
count--;
|
||||
counter.text(count);
|
||||
action = 'unlike';
|
||||
} else {
|
||||
likes.push(id);
|
||||
count++;
|
||||
counter.text(count);
|
||||
action = 'like';
|
||||
}
|
||||
ls.set('likes', likes);
|
||||
console.log(action + ' - ' + $(this).data('id') + ' like event');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue