annotate comments/static/js/comments.js @ 798:c5d73b4a2899

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