diff options
author | jan <jan@ruken.pw> | 2016-11-14 15:55:50 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-11-14 15:55:50 (UTC) |
commit | c735553214400f3af69e516ff41a6da9214449a7 (patch) | |
tree | c9a8e8fc84fdbaffb3a3fa318453b36270550ebb /assets_src/js/like.js | |
parent | 9832cd28de49421021ed7c1f3caa7fdda7bc4372 (diff) |
likes und so.
Diffstat (limited to 'assets_src/js/like.js')
-rw-r--r-- | assets_src/js/like.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/assets_src/js/like.js b/assets_src/js/like.js new file mode 100644 index 0000000..03b15a1 --- /dev/null +++ b/assets_src/js/like.js | |||
@@ -0,0 +1,22 @@ | |||
1 | import * as ajax from './lib/ajax'; | ||
2 | import * as dom from './lib/dom'; | ||
3 | |||
4 | async function updateLikeCount(el) { | ||
5 | const type = parseInt(el.getAttribute('content-type'), 10); | ||
6 | const contentId = parseInt(el.getAttribute('content-id'), 10); | ||
7 | |||
8 | if (isNaN(type) || isNaN(contentId)) { | ||
9 | return; | ||
10 | } | ||
11 | |||
12 | const count = await ajax.get(`/api/likes/count?id=${contentId}&type=${type}`, {}); | ||
13 | |||
14 | el.textContent = count; | ||
15 | } | ||
16 | |||
17 | dom.ready(() => { | ||
18 | dom.withClass('like-count') | ||
19 | .forEach(el => { | ||
20 | updateLikeCount(el); | ||
21 | }); | ||
22 | }); | ||