Mercurial > public > sg101
comparison gpp/comments/static/js/comments.js @ 312:88b2b9cb8c1f
Fixing #142; cut over to the django.contrib.staticfiles app.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 27 Jan 2011 02:56:10 +0000 |
parents | |
children | f785a646a5fc |
comparison
equal
deleted
inserted
replaced
311:b1c39788e511 | 312:88b2b9cb8c1f |
---|---|
1 $(document).ready(function() { | |
2 var postText = $('#id_comment'); | |
3 var postButton = $('#comment-form-post'); | |
4 postButton.click(function () { | |
5 var text = $.trim(postText.val()); | |
6 if (text.length == 0) { | |
7 alert('Please enter some text.'); | |
8 return false; | |
9 } | |
10 postButton.attr('disabled', 'disabled').val('Posting Comment...'); | |
11 $.ajax({ | |
12 url: '/comments/post/', | |
13 type: 'POST', | |
14 data: { | |
15 comment : text, | |
16 content_type : $('#id_content_type').val(), | |
17 object_pk : $('#id_object_pk').val() | |
18 }, | |
19 dataType: 'html', | |
20 success: function (data, textStatus) { | |
21 postText.val(''); | |
22 $('#comment-container').append(data); | |
23 var newDiv = $('#comment-container > div:last'); | |
24 newDiv.hide(); | |
25 var num = $('.comment-list', newDiv); | |
26 num.html($('#comment-container > div').size() + "."); | |
27 newDiv.fadeIn(3000); | |
28 postButton.removeAttr('disabled').val('Post Comment'); | |
29 var count = $('#comment-count'); | |
30 if (count.length) { | |
31 count.html(parseInt(count.html()) + 1); | |
32 } | |
33 }, | |
34 error: function (xhr, textStatus, ex) { | |
35 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | |
36 xhr.responseText); | |
37 postButton.removeAttr('disabled').val('Post Comment'); | |
38 } | |
39 }); | |
40 return false; | |
41 }); | |
42 $('a.comment-flag').click(function () { | |
43 var id = this.id; | |
44 if (id.match(/fc-(\d+)/)) { | |
45 id = RegExp.$1; | |
46 if (confirm('Only flag a comment if you feel it is spam, abuse, violates site rules, ' + | |
47 'or is not appropriate. ' + | |
48 'A moderator will be notified and will review the comment. ' + | |
49 'Are you sure you want to flag this comment?')) { | |
50 $.ajax({ | |
51 url: '/comments/flag/', | |
52 type: 'POST', | |
53 data: {id: id}, | |
54 dataType: 'text', | |
55 success: function (response, textStatus) { | |
56 alert(response); | |
57 }, | |
58 error: function (xhr, textStatus, ex) { | |
59 alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); | |
60 } | |
61 }); | |
62 } | |
63 } | |
64 return false; | |
65 }); | |
66 }); |