4 // hide all the 'close' and 'best' buttons for this question
6 // @fixme: Should use ID
7 close: function(closeButt) {
8 notice = $(closeButt).closest('li.hentry.notice.question');
9 notice.find('input[name=best],[name=close]').hide();
10 notice.find('textarea').hide();
11 notice.find('li.notice-answer-placeholder').hide();
12 notice.find('#answer-form').hide();
19 QnA.NoticeInlineAnswerSetup();
21 $('input[name=close]').live('click', function() {
24 $('input[name=best]').live('click', function() {
33 * Open up a question's inline answer box.
35 * @param {jQuery} notice: jQuery object containing one notice
37 NoticeInlineAnswerTrigger: function(notice) {
38 console.log('NoticeInlineAnswerTrigger - begin');
40 // Find the question notice we're answering...
41 var id = $($('.notice_id', notice)[0]).text();
42 console.log("parent notice id = " + id);
43 var parentNotice = notice;
45 // See if the form's already there...
46 var answerForm = $('#answer-form', parentNotice);
49 console.log("Found the answer form.");
51 console.log("Did not find the answer form.");
54 var placeholder = parentNotice.find('li.notice-answer-placeholder');
56 // Pull the parents threaded list and we'll add on the end of it.
57 var list = $('ul.threaded-replies', notice);
60 console.log("Found the " + list.length + " notice place holders.");
62 console.log("Found the notice answer placeholder");
65 if (list.length == 0) {
66 console.log("list length = 0 adding <ul>");
67 list = $('<ul class="notices threaded-replies xoxo"></ul>');
69 } else if (list.length == 2) {
70 // remove duplicate ul added by util.js
74 var answerItem = $('li.notice-answer', list);
76 var nextStep = function() {
77 console.log("nextStep - enter");
80 var text = answerForm.find('textarea');
82 if (text.length == 0) {
86 $('body').click(function(e) {
87 console.log("got click");
89 var openAnswers = $('li.notice-answer');
90 if (openAnswers.length > 0) {
91 var target = $(e.target);
92 openAnswers.each(function() {
93 // Did we click outside this one?
94 var answerItem = $(this);
95 if (answerItem.has(e.target).length == 0) {
96 var textarea = answerItem.find('.notice_data-text:first');
97 var cur = $.trim(textarea.val());
98 // Only close if there's been no edit.
99 if (cur == '' || cur == textarea.data('initialText')) {
100 var parentNotice = answerItem.closest('li.notice');
102 parentNotice.find('li.notice-answer-placeholder').show();
114 if (answerItem.length > 0) {
115 console.log('answerItem length > 0');
116 // Update the existing form...
120 // Create the answer form entry at the end
122 if (answerItem.length == 0) {
123 console.log("QQQQQ no notice-answer li");
124 answerItem = $('<li class="notice-answer"></li>');
126 var intermediateStep = function(formMaster) {
127 console.log("Intermediate step");
128 var formEl = document._importNode(formMaster, true);
129 answerItem.append(formEl);
130 console.log("appending answerItem");
131 list.append(answerItem); // *after* the placeholder
132 console.log("appended answerItem");
133 console.log(answerItem);
134 var form = answerForm = $(formEl);
135 QnA.AnswerFormSetup(form);
140 if (QnA.AnswerFormMaster) {
141 // We've already saved a master copy of the form.
143 intermediateStep(QnA.AnswerFormMaster);
145 // Fetch a fresh copy of the answer form over AJAX.
146 // Warning: this can have a delay, which looks bad.
147 // @fixme this fallback may or may not work
148 var url = $('#answer-action').attr('value');
150 console.log("fetching new form via HXR");
152 $.get(url, {ajax: 1}, function(data, textStatus, xhr) {
153 intermediateStep($('form', data)[0]);
158 console.log('NoticeInlineAnswerTrigger - exit');
163 AnswerFormSetup: function(form) {
164 console.log("AnswerFormSetup - begin");
165 if (!form.data('AnswerFormSetup')) {
166 form.data('AnswerFormSetup', true);
168 console.log("AnswerFormSetup - exit");
172 * Setup function -- DOES NOT apply immediately.
174 * Sets up event handlers for inline reply mini-form placeholders.
175 * Uses 'live' rather than 'bind', so applies to future as well as present items.
177 NoticeInlineAnswerSetup: function() {
178 console.log("NoticeInlineAnswerSetup - begin");
179 $('li.notice-answer-placeholder input.placeholder')
180 .live('focus', function() {
181 var notice = $(this).closest('li.notice');
182 QnA.NoticeInlineAnswerTrigger(notice);
185 console.log("NoticeInlineAnswerSetup - exit");
190 $(document).ready(function() {