bgneal@312: $(document).ready(function() { bgneal@312: var postText = $('#id_body'); bgneal@312: var postButton = $('#forums-reply-post'); bgneal@312: postButton.click(function () { bgneal@312: var text = $.trim(postText.val()); bgneal@312: $(this).attr('disabled', 'disabled').val('Posting reply...'); bgneal@312: bgneal@312: var attachments = new Array() bgneal@312: $('#attachment div input').each(function(index) { bgneal@312: attachments[index] = $(this).val(); bgneal@312: }); bgneal@312: bgneal@312: $.ajax({ bgneal@312: url: '/forums/quick-reply/', bgneal@312: type: 'POST', bgneal@312: data: { bgneal@312: body : postText.val(), bgneal@312: topic_id : $('#id_topic_id').val(), bgneal@312: attachment : attachments bgneal@312: }, bgneal@312: traditional: true, bgneal@312: dataType: 'html', bgneal@312: success: function (data, textStatus) { bgneal@312: postText.val(''); bgneal@312: var lastTr = $('#forum-topic tr:last'); bgneal@379: var newClass = lastTr.hasClass('odd') ? 'even' : 'odd'; bgneal@379: lastTr.after(data); bgneal@379: lastTr = $('#forum-topic tr:last'); bgneal@379: lastTr.addClass(newClass); bgneal@312: lastTr.hide(); bgneal@312: lastTr.fadeIn(3000); bgneal@312: postButton.removeAttr('disabled').val('Submit Reply'); bgneal@312: initAttachments(); 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('Submit Reply'); bgneal@312: initAttachments(); bgneal@312: } bgneal@312: }); bgneal@312: return false; bgneal@312: }); bgneal@312: $('a.post-flag').click(function () { bgneal@312: var id = this.id; bgneal@312: if (id.match(/fp-(\d+)/)) { bgneal@312: id = RegExp.$1; bgneal@312: if (confirm('Only flag a post 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 post. ' + bgneal@312: 'Are you sure you want to flag this post?')) { bgneal@312: $.ajax({ bgneal@312: url: '/forums/flag-post/', 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@312: $('a.post-delete').click(function () { bgneal@312: var id = this.id; bgneal@312: if (id.match(/dp-(\d+)/)) { bgneal@312: id = RegExp.$1; bgneal@312: if (confirm('Are you sure you want to delete this post?')) { bgneal@312: $.ajax({ bgneal@312: url: '/forums/delete-post/', 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: $('#post-' + id).fadeOut(3000); 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@312: $('#forum-mod-del-topic').click(function () { bgneal@312: return confirm('Are you sure you want to delete this topic?\n' + bgneal@312: 'WARNING: all posts will be lost.'); bgneal@312: }); bgneal@312: bgneal@312: var vid = 0; bgneal@312: var vidDiv = $('#attachment'); bgneal@312: bgneal@312: function clearAttachments() bgneal@312: { bgneal@312: $('#attachment div').remove(); bgneal@312: $('#attach-another').remove(); bgneal@312: } bgneal@312: bgneal@312: function processEmbeds(data, textStatus) bgneal@312: { bgneal@312: vidDiv.find('img').remove(); bgneal@312: $.each(data, function(index, value) { bgneal@312: var html = '
' + value.html + bgneal@312: '' + bgneal@312: 'Remove ' + bgneal@312: 'Remove' + bgneal@312: ''; bgneal@312: '
'; bgneal@312: vidDiv.append(html); bgneal@312: $('#video-' + index + ' a').click(function() { bgneal@312: $('#video-' + index).remove(); bgneal@312: relabelAttachLink(); bgneal@312: return false; bgneal@312: }); bgneal@312: }); bgneal@312: vid = data.length; bgneal@312: $('#video-' + (vid-1)).after('Attach another video'); bgneal@312: $('#attach-another').click(function() { bgneal@312: addVideo(); bgneal@312: relabelAttachLink(); bgneal@312: return false; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: function initAttachments() bgneal@312: { bgneal@312: clearAttachments(); bgneal@312: bgneal@312: var post_input = $('#id_post_id'); bgneal@312: var attachments = $("#forums_post_form input:hidden[name='attachment']"); bgneal@312: if (post_input.length == 1) bgneal@312: { bgneal@312: post_id = post_input.val(); bgneal@312: vidDiv.prepend('Busy'); bgneal@312: $.ajax({ bgneal@312: url: '/forums/fetch_attachments/', bgneal@312: type: 'GET', bgneal@312: data: { bgneal@312: pid : post_id bgneal@312: }, bgneal@312: dataType: 'json', bgneal@312: success: processEmbeds, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: vidDiv.find('img').remove(); bgneal@312: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@312: xhr.responseText); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: else if (attachments.length > 0) bgneal@312: { bgneal@312: vidDiv.prepend('Busy'); bgneal@312: var embeds = new Array(); bgneal@312: attachments.each(function(index) { bgneal@312: embeds[index] = $(this).val(); bgneal@312: }); bgneal@312: attachments.remove(); bgneal@312: $.ajax({ bgneal@312: url: '/oembed/fetch_saved/', bgneal@312: type: 'GET', bgneal@312: data: { bgneal@312: embeds: embeds bgneal@312: }, bgneal@312: traditional: true, bgneal@312: dataType: 'json', bgneal@312: success: processEmbeds, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: vidDiv.find('img').remove(); bgneal@312: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@312: xhr.responseText); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: else bgneal@312: { bgneal@312: vid = 0; bgneal@312: var s = '
' + bgneal@312: 'Add ' + bgneal@312: 'Attach Video
'; bgneal@312: vidDiv.prepend(s); bgneal@312: $('#attachment a').click(function () { bgneal@312: $('#init-add').remove(); bgneal@312: addVideo(); bgneal@312: return false; bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: function relabelAttachLink() bgneal@312: { bgneal@312: var another = $('#attach-another'); bgneal@312: var n = $('#attachment div').length; bgneal@312: if (n == 0) bgneal@312: { bgneal@312: another.html("Attach a video"); bgneal@312: } bgneal@312: else bgneal@312: { bgneal@312: another.html("Attach another video"); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: function addVideo() bgneal@312: { bgneal@312: var id = "video-" + vid; bgneal@312: bgneal@312: var fakeForm = '
' + bgneal@312: 'Attach ' + bgneal@312: ' ' + bgneal@312: 'Remove
'; bgneal@312: bgneal@312: var n = $('#attachment div').length; bgneal@312: bgneal@312: var another = $('#attach-another'); bgneal@312: if (n == 0) bgneal@312: { bgneal@312: if (another.length > 0) bgneal@312: { bgneal@312: another.before(fakeForm); bgneal@312: } bgneal@312: else bgneal@312: { bgneal@312: vidDiv.append(fakeForm); bgneal@312: } bgneal@312: } bgneal@312: else bgneal@312: { bgneal@312: $('#attachment div:last').after(fakeForm); bgneal@312: } bgneal@312: bgneal@312: $('#' + id + ' a').click(function() { bgneal@312: $('#' + id).remove(); bgneal@312: relabelAttachLink(); bgneal@312: return false; bgneal@312: }); bgneal@312: bgneal@312: var vidText = $('#' + id + ' input'); bgneal@312: bgneal@312: $('#' + id + ' button').click(function() { bgneal@312: var button = $(this); bgneal@312: button.attr('disabled', 'disabled'); bgneal@312: $.ajax({ bgneal@312: url: '/oembed/fetch/', bgneal@312: type: 'POST', bgneal@312: data: { bgneal@312: q : vidText.val() bgneal@312: }, bgneal@312: dataType: 'json', bgneal@312: success: function (data, textStatus) { bgneal@312: $('#' + id + " .r").remove(); bgneal@312: var myDiv = $('#' + id); bgneal@312: var html = '' + bgneal@312: 'Remove ' + bgneal@312: 'Remove' + bgneal@312: ''; bgneal@312: myDiv.prepend(html); bgneal@312: myDiv.prepend(data.embed); bgneal@312: $('#' + id + ' a').click(function() { bgneal@312: myDiv.remove(); bgneal@312: relabelAttachLink(); bgneal@312: return false; 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: button.removeAttr('disabled'); bgneal@312: } bgneal@312: }); bgneal@312: }); bgneal@312: bgneal@312: if (vid == 0) bgneal@312: { bgneal@312: $('#video-0').after('Attach another video'); bgneal@312: $('#attach-another').click(function() { bgneal@312: addVideo(); bgneal@312: relabelAttachLink(); bgneal@312: return false; bgneal@312: }); bgneal@312: } bgneal@312: ++vid; bgneal@312: } bgneal@312: bgneal@312: initAttachments(); bgneal@483: bgneal@483: $('div.forum-post-body img').fadeIn('fast', function() { bgneal@483: var pic = $(this); bgneal@483: if (pic.width() > 720) { bgneal@483: pic.css('width', '720px'); bgneal@483: } bgneal@483: }); bgneal@312: });