comparison media/js/comments.js @ 126:b0d62247c3e4

Add some javascript to check for posting a blank comment. Change wording on forum error message for the same thing.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Nov 2009 20:30:31 +0000
parents 10d6182b9f6e
children 2d299909e074
comparison
equal deleted inserted replaced
125:903ae6168071 126:b0d62247c3e4
1 $(document).ready(function() { 1 $(document).ready(function() {
2 $('#comment-form-post').click(function () { 2 var postText = $('#id_comment');
3 $(this).attr('disabled', 'disabled').val('Posting Comment...'); 3 var postButton = $('#comment-form-post');
4 $.post('/comments/post/', { 4 postButton.click(function () {
5 comment : $('#id_comment').val(), 5 var text = $.trim(postText.val());
6 content_type : $('#id_content_type').val(), 6 if (text.length == 0) {
7 object_pk : $('#id_object_pk').val() 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()
8 }, 18 },
9 function (data, textStatus) { 19 dataType: 'html',
10 $('#id_comment').val(''); 20 success: function (data, textStatus) {
21 postText.val('');
11 $('#comment-list').append(data); 22 $('#comment-list').append(data);
12 var lastLi = $('#comment-list > li:last'); 23 var lastLi = $('#comment-list > li:last');
13 lastLi.hide(); 24 lastLi.hide();
14 lastLi.fadeIn(3000); 25 lastLi.fadeIn(3000);
15 $('#comment-form-post').removeAttr('disabled').val('Post Comment'); 26 postButton.removeAttr('disabled').val('Post Comment');
16 var count = $('#comment-count'); 27 var count = $('#comment-count');
17 if (count.length) { 28 if (count.length) {
18 count.html(parseInt(count.html()) + 1); 29 count.html(parseInt(count.html()) + 1);
19 } 30 }
20 }, 31 },
21 'html'); 32 error: function (xhr, textStatus, ex) {
33 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
34 xhr.responseText);
35 postButton.removeAttr('disabled').val('Post Comment');
36 }
37 });
22 return false; 38 return false;
23 }); 39 });
24 $('a.comment-flag').click(function () { 40 $('a.comment-flag').click(function () {
25 var id = this.id; 41 var id = this.id;
26 if (id.match(/fc-(\d+)/)) { 42 if (id.match(/fc-(\d+)/)) {
43 }); 59 });
44 } 60 }
45 } 61 }
46 return false; 62 return false;
47 }); 63 });
48 $('#id_comment').markItUp(mySettings); 64 postText.markItUp(mySettings);
49 }); 65 });