1
var likes = new Vue({
2
el: '#like_button',
3
delimiters: ['*{', '}*'],
4
data() {
5
return {
6
inProcess: false,
7
count: window.entity_like_count,
8
already: window.entity_liked_already,
9
};
10
},
11
methods: {
12
toggle() {
13
if(this.inProcess === true) {
14
return false;
15
}
16
if(this.already === true) {
17
this.count = this.count - 1;
18
this.already = false;
19
document.getElementById('like_button').classList.remove('active');
20
} else {
21
this.count = this.count + 1;
22
this.already = true;
23
document.getElementById('like_button').classList.add('active');
24
}
25
document.getElementById('postLikes').innerHTML = this.count;
26
this.inProcess = true;
27
this.$api.get('/like', { params: { id: window.entity_id } }).then( response => {
28
this.inProcess = false;
29
this.count = response.data.count;
30
document.getElementById('postLikes').innerHTML = this.count;
31
});
32
}
33
}
34
});