diff --git a/js/util.js b/js/util.js index 2cb370ef5f..811e124086 100644 --- a/js/util.js +++ b/js/util.js @@ -428,6 +428,7 @@ var SN = { // StatusNet var id = $(notice).attr('id'); if ($("#"+id).length == 0) { + console.log("inserting before placeholder"); $(notice).insertBefore(placeholder); } else { // Realtime came through before us... diff --git a/plugins/QnA/js/qna.js b/plugins/QnA/js/qna.js index c83440452f..c7add55ca6 100644 --- a/plugins/QnA/js/qna.js +++ b/plugins/QnA/js/qna.js @@ -32,46 +32,42 @@ var QnA = { * @param {jQuery} notice: jQuery object containing one notice */ NoticeInlineAnswerTrigger: function(notice) { - console.log('NoticeInlineAnswerTrigger - begin'); - - // Find the question notice we're answering... + // Find the notice we're replying to... var id = $($('.notice_id', notice)[0]).text(); - console.log("parent notice id = " + id); + + console.log("NoticeInlineAnswerTrigger - replying to notice " + id); + var parentNotice = notice; - // See if the form's already there... - var answerForm = $('#answer-form', parentNotice); - - if (answerForm) { - console.log("Found the answer form."); + // Find the threaded replies view we'll be adding to... + var list = notice.closest('.notices'); + if (list.hasClass('threaded-replies')) { + console.log("NoticeInlineAnswerTrigger - there's already a threaded-replies ul above me"); + // We're replying to a reply; use reply form on the end of this list. + // We'll add our form at the end of this; grab the root notice. + parentNotice = list.closest('.notice'); + console.log("NoticeInlineAnswerTrigger - trying to find the closed .notice above me"); + if (parentNotice.length > 0) { + console.log("NoticeInlineAnswerTrigger - found that closest .notice"); + } } else { - console.log("Did not find the answer form."); + console.log("NoticeInlineAnswerTrigger - this notice does not have a threaded-reples ul"); + // We're replying to a parent notice; pull its threaded list + // and we'll add on the end of it. Will add if needed. + list = $('ul.threaded-replies', notice); + console.log('NoticeInlineAnswerTrigger - looking for threaded-replies ul on the parent notice (on the passed in notice)'); + if (list.length == 0) { + console.log("NoticeInlineAnswerTrigger - there is no threaded-replies ul on the parent notice"); + console.log("NoticeInlineAnswerTrigger - calling NoticeInlineAnswerPlaceholder(notice)"); + QnA.NoticeInlineAnswerPlaceholder(notice); + console.log("NoticeInlineAnswerTrigger - checking once again for a ul.threaded-replies on the notice"); + list = $('ul.threaded-replies', notice); + } } - var placeholder = parentNotice.find('li.notice-answer-placeholder'); - - // Pull the parents threaded list and we'll add on the end of it. - var list = $('ul.threaded-replies', notice); - - if (list) { - console.log("Found the " + list.length + " notice place holders."); - } else { - console.log("Found the notice answer placeholder"); - } - - if (list.length == 0) { - console.log("list length = 0 adding