Skip to content

Node.js based forum software built for the modern web

started favourites/rep

psychobunnyc73d1237d21e
diff --git a/public/css/style.less b/public/css/style.less
index f29dce41e5..81c55db407 100644
--- a/public/css/style.less
+++ b/public/css/style.less
@@ -193,6 +193,10 @@ footer.footer {
padding-right: 5px;
}
}
+
+ .icon-star {
+ //theme this to make it yellow eventually
+ }
}
background: #fff;
}
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index e9402b7f82..5f91ff0917 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -21,7 +21,7 @@
posted by <strong>{posts.userName}</strong> {posts.relativeTime}
<span class="post-buttons">
<div id="quote_{posts.pid}" class="quote"><i class="icon-quote-left"></i></div>
- <div class="favourite"><i class="icon-star-empty"></i></div>
+ <div id="favs_{posts.pid}" class="favourite"><span id="favs_counter_{posts.pid}">0</span><i class="icon-star-empty"></i></div>
<div class="post_reply">Reply <i class="icon-reply"></i></div>
</span>
</div>
@@ -47,7 +47,20 @@ jQuery('.quote').click(function() {
});
jQuery('.favourite').click(function() {
- if (this.children[0].className == 'icon-star-empty') this.children[0].className = 'icon-star';
- else this.children[0].className = 'icon-star-empty';
+ var pid = this.id.replace('favs_', ''),
+ favs_counter = document.getElementById('favs_counter_' + pid);
+
+ var total = parseInt(favs_counter.innerHTML, 10);
+
+ if (this.children[1].className == 'icon-star-empty') {
+ this.children[1].className = 'icon-star';
+ total++;
+ favs_counter.innerHTML = total;
+ }
+ else {
+ this.children[1].className = 'icon-star-empty';
+ total--;
+ favs_counter.innerHTML = total;
+ }
})
</script>
\ No newline at end of file
diff --git a/src/websockets.js b/src/websockets.js
index 17018a4f70..33ac1ea8ab 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -124,6 +124,10 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
modules.user.active.get();
});
+ socket.on('api:posts.favourite', function(data) {
+ modules.posts.favourite(socket, data.pid);
+ })
+
socket.on('api:user.active.get_record', function() {
modules.user.active.get_record(socket);
});