comparison comments/static/js/comments.js @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/comments/static/js/comments.js@f785a646a5fc
children
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
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
67 $('.comment-text img').fadeIn('fast', function() {
68 var pic = $(this);
69 if (pic.width() > 720) {
70 pic.css('width', '720px');
71 }
72 });
73 });