Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

I've solved your "Multiple ReplyTo forms" problem

edited February 2011 in Vanilla 2.0 - 2.8
Here is the code as i'm using 't right now :-)

Thanx for the great addon!

jQuery(document).ready(function($) { /** * HACKED IN BY GK * 16-02-2010 * Do not show multiple comment forms */ function BeforeReplyFormShown() { // Identify the "ReplyTo" form $('.CommentForm').each(function(i) { // Identify the "ReplyTo" form var isReplyToForm = $(this).find('div.Buttons a.Cancel').length > 0; if(isReplyToForm) { // Remove all other open ReplyTo forms $(this).remove(); } else { // Hide the orriginal comment form $(this).hide(); } }); } /** * HACKED IN BY GK * 16-02-2010 * Do not show multiple comment forms */ function OnReplyFormClosed() { // Identify the "ReplyTo" form $('.CommentForm').each(function(i) { // Identify the "ReplyTo" form var isReplyToForm = $(this).find('div.Buttons a.Cancel').length > 0; if(isReplyToForm) { // Remove all other open ReplyTo forms $(this).remove(); } else { // Hide the orriginal comment form $(this).show(); } }); } // When the edit link is clicked, save the nesting level categories for // restoring later, after the edited comment is submitted. // TODO: now we need a trigger once the edited comment is sent back on // form submission, so we can put the saved classes back onto it. $('a.EditComment').livequery('click', function() { var btn = this; var parent = $(btn).parents('div.Comment'); var saveclass = $(parent).attr('class'); // Store it against the parent of 'parent', which does not get // removed (i.e. the list item). if (saveclass != 'Comment') $(parent).parent().data('saveclass', saveclass); }); // Reply to comment // We want to show the comment form, but unlike editing, there is no need // to hide the comment we are replying to. $('a.ReplyComment').livequery('click', function() { var btn = this; // Widest wrapper around the comment. var container = $(btn).parents('li.Comment'); $(container).addClass('Editing'); // Second wrapper around the comment. var parent = $(btn).parents('div.Comment'); // Message body, after the title and options. var msg = $(parent).find('div.Message'); // Put spinner on end of options list. $(parent).find('div.Meta span:last').after('<span class="TinyProgress">&nbsp;</span>'); // Check if the child comment form is already open within this comment. var CommentForm = $(parent).find('div.CommentForm').length; // If the comment form is not there, then open it, otherwise close it. Simples. if (!CommentForm) { $.ajax({ type: "POST", url: $(btn).attr('href'), data: 'DeliveryType=VIEW&DeliveryMethod=JSON', dataType: 'json', error: function(XMLHttpRequest, textStatus, errorThrown) { // Remove any old popups $('div.Popup,.Overlay').remove(); $.popup({}, XMLHttpRequest.responseText); }, success: function(json) { json = $.postParseJson(json); /** * HACK: Remove all existing comment forms */ BeforeReplyFormShown(); // Place the form after the original comment and hide the spinner. $(msg).after(json.Data); $(parent).find('span.TinyProgress').hide(); // Replace the "Back to Discussions" with a "Cancel" button. // There is no easy way to do it in the back end without consequences. // TODO: some translation would probably be needed here in the long term. $(parent).find('a.Back').removeClass('Back').addClass('Cancel').text('Annuleren'); /** * HACK: Remove all existing comment forms * Hack close button must show the orriginal comment form */ var $cancelButton = $(parent).find('a.Cancel'); $cancelButton.unbind('click'); $cancelButton.click(function() { OnReplyFormClosed(); }); } }); } else { // Take the comment form off. $(parent).find('div.CommentForm').remove(); /** * HACK: Show the normal comment form again */ OnReplyFormClosed(); // Take the spinner off, now the form has loaded. $(parent).find('span.TinyProgress').remove(); } $(document).trigger('CommentReplyingComplete', [msg]); return false; }); });

Comments

  • Thanks! I'll take that for a test drive (next week though).
  • One problem though, it doesn't remove any saved drafts. No problem for me, because i disabled the autosave draft (requires a plugin).

    If i may guess, that problem can perhaps be solved by removing the original form instead of hiding it. But then you should also add it back when closing the ReplyTo form, instead of unhiding (showing) it again.

    Can't you just "move" the original form instead of loading a new one ? I'm guessing that shouldn't be to hard to implement, right?

    I'm new to vanilla so i do not understand every line of code yet, so don't take it to hard on me if I'm wrong :-).
Sign In or Register to comment.