bgneal@312: $(document).ready(function() { bgneal@312: var postText = $('#id_comment'); bgneal@312: var postButton = $('#comment-form-post'); bgneal@312: postButton.click(function () { bgneal@312: var text = $.trim(postText.val()); bgneal@312: if (text.length == 0) { bgneal@312: alert('Please enter some text.'); bgneal@312: return false; bgneal@312: } bgneal@312: postButton.attr('disabled', 'disabled').val('Posting Comment...'); bgneal@312: $.ajax({ bgneal@312: url: '/comments/post/', bgneal@312: type: 'POST', bgneal@312: data: { bgneal@312: comment : text, bgneal@312: content_type : $('#id_content_type').val(), bgneal@312: object_pk : $('#id_object_pk').val() bgneal@312: }, bgneal@312: dataType: 'html', bgneal@312: success: function (data, textStatus) { bgneal@312: postText.val(''); bgneal@312: $('#comment-container').append(data); bgneal@312: var newDiv = $('#comment-container > div:last'); bgneal@312: newDiv.hide(); bgneal@312: var num = $('.comment-list', newDiv); bgneal@312: num.html($('#comment-container > div').size() + "."); bgneal@312: newDiv.fadeIn(3000); bgneal@312: postButton.removeAttr('disabled').val('Post Comment'); bgneal@312: var count = $('#comment-count'); bgneal@312: if (count.length) { bgneal@312: count.html(parseInt(count.html()) + 1); bgneal@312: } bgneal@312: }, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@312: xhr.responseText); bgneal@312: postButton.removeAttr('disabled').val('Post Comment'); bgneal@312: } bgneal@312: }); bgneal@312: return false; bgneal@312: }); bgneal@312: $('a.comment-flag').click(function () { bgneal@312: var id = this.id; bgneal@312: if (id.match(/fc-(\d+)/)) { bgneal@312: id = RegExp.$1; bgneal@312: if (confirm('Only flag a comment if you feel it is spam, abuse, violates site rules, ' + bgneal@312: 'or is not appropriate. ' + bgneal@312: 'A moderator will be notified and will review the comment. ' + bgneal@312: 'Are you sure you want to flag this comment?')) { bgneal@312: $.ajax({ bgneal@312: url: '/comments/flag/', bgneal@312: type: 'POST', bgneal@312: data: {id: id}, bgneal@312: dataType: 'text', bgneal@312: success: function (response, textStatus) { bgneal@312: alert(response); bgneal@312: }, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: return false; bgneal@312: }); bgneal@489: bgneal@489: $('.comment-text img').fadeIn('fast', function() { bgneal@489: var pic = $(this); bgneal@489: if (pic.width() > 720) { bgneal@489: pic.css('width', '720px'); bgneal@489: } bgneal@489: }); bgneal@312: });