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