1
var bookmarkButton = new Vue({
2
el: '#bookmarkButton',
3
data() {
4
return {
5
bookmark: false,
6
articleId: window.article_id,
7
};
8
},
9
mounted() {
10
ids = [];
11
let cooks = Cookies.get('favourites_ids');
12
if(typeof cooks == 'undefined') {
13
Cookies.set('favourites_ids', JSON.stringify(ids));
14
} else {
15
ids = JSON.parse(cooks);
16
}
17
if(ids.indexOf(this.articleId) !== -1) {
18
this.bookmark = true;
19
}
20
},
21
methods: {
22
toggle() {
23
ids = [];
24
let cooks = Cookies.get('favourites_ids');
25
if(typeof cooks == 'undefined') {
26
Cookies.set('favourites_ids', JSON.stringify(ids));
27
} else {
28
ids = JSON.parse(cooks);
29
}
30
if(ids.indexOf(this.articleId) !== -1) {
31
let ids = JSON.parse(cooks);
32
var index = ids.indexOf(this.articleId);
33
ids.splice(index, 1);
34
Cookies.set('favourites_ids', JSON.stringify(ids));
35
window.vHeader.favouritesCount = ids.length;
36
this.bookmark = false;
37
} else {
38
ids.push(this.articleId);
39
Cookies.set('favourites_ids', JSON.stringify(ids));
40
window.vHeader.favouritesCount = ids.length;
...
</html>