From d1443a6bd9e005d8944c3b92b56a41c644b6f19f Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 15 Apr 2011 19:50:05 -0700 Subject: [PATCH] Getting some traction here on better QnA Ajax --- js/util.js | 1 + plugins/QnA/js/qna.js | 178 ++++++++++++++++++++++++++---------------- 2 files changed, 112 insertions(+), 67 deletions(-) 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); - var parentNotice = notice; - - // See if the form's already there... - var answerForm = $('#answer-form', parentNotice); - - if (answerForm) { - console.log("Found the answer form."); - } else { - console.log("Did not find the answer form."); - } - var placeholder = parentNotice.find('li.notice-answer-placeholder'); + console.log("NoticeInlineAnswerTrigger - replying to notice " + id); - // Pull the parents threaded list and we'll add on the end of it. - var list = $('ul.threaded-replies', notice); + var parentNotice = notice; - if (list) { - console.log("Found the " + list.length + " notice place holders."); + // 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("Found the notice answer placeholder"); - } - - if (list.length == 0) { - console.log("list length = 0 adding