summaryrefslogtreecommitdiffstats
path: root/hyperkitty/static/js
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty/static/js')
-rw-r--r--hyperkitty/static/js/hyperkitty.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js
index becc171..99d16b7 100644
--- a/hyperkitty/static/js/hyperkitty.js
+++ b/hyperkitty/static/js/hyperkitty.js
@@ -37,10 +37,11 @@ function form_to_json(form) {
* Voting
*/
-function vote(elem, value) {
+function vote(elem) {
if ($(elem).hasClass("disabled")) {
- return false;
+ return;
}
+ var value = parseInt($(elem).attr("data-vote"));
var form = $(elem).parents("form").first();
var data = form_to_json(form);
data['vote'] = value;
@@ -50,21 +51,25 @@ function vote(elem, value) {
dataType: "json",
data: data,
success: function(response) {
- form.replaceWith(response.html);
+ var newcontent = $(response.html);
+ form.replaceWith(newcontent);
+ setup_vote(newcontent); // re-bind events
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
- return false;
}
-function setup_vote() {
- /*
- $("a.youlike").click(function(e) { e.preventDefault(); vote(this, 1); });
- $("a.youdislike").click(function(e) { e.preventDefault(); vote(this, -1); });
- */
+function setup_vote(baseElem) {
+ if (!baseElem) {
+ baseElem = document;
+ }
+ $(baseElem).find("a.vote").click(function(e) {
+ e.preventDefault();
+ vote(this);
+ });
}