diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-04-30 10:42:08 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-04-30 10:42:08 +0200 |
commit | 120a4affe1881dbb7383c65175851dba3bb1e87b (patch) | |
tree | 6481a33bdca67a7694192890be0d95af603a9f33 /hyperkitty/static/js/hyperkitty.js | |
parent | 3ac9cab8bd7b44c0cdf4f0a39ea378542061184e (diff) | |
download | hyperkitty-120a4affe1881dbb7383c65175851dba3bb1e87b.tar.gz hyperkitty-120a4affe1881dbb7383c65175851dba3bb1e87b.tar.xz hyperkitty-120a4affe1881dbb7383c65175851dba3bb1e87b.zip |
Refactor voting JS for better separation of concerns
Diffstat (limited to 'hyperkitty/static/js/hyperkitty.js')
-rw-r--r-- | hyperkitty/static/js/hyperkitty.js | 23 |
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); + }); } |