+ NoticeInlineReplyTrigger: function(notice, initialText) {
+ // Find the notice we're replying to...
+ var id = $($('.notice_id', notice)[0]).text();
+ var parentNotice = notice;
+
+ // Find the threaded replies view we'll be adding to...
+ var list = notice.closest('.notices');
+ if (list.hasClass('threaded-replies')) {
+ // 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');
+ } else {
+ // 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);
+ if (list.length == 0) {
+ list = $('<ul class="notices threaded-replies xoxo"></ul>');
+ notice.append(list);
+ }
+ }
+
+ // See if the form's already open...
+ var replyForm = $('.notice-reply-form', list);
+
+ var nextStep = function() {
+ // Override...?
+ replyForm.find('input[name=inreplyto]').val(id);
+
+ // Set focus...
+ var text = replyForm.find('textarea');
+ if (text.length == 0) {
+ throw "No textarea";
+ }
+ var replyto = '';
+ if (initialText) {
+ replyto = initialText + ' ';
+ }
+ text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
+ text.data('initialText', $.trim(initialText + ''));
+ text.focus();
+ if (text[0].setSelectionRange) {
+ var len = text.val().length;
+ text[0].setSelectionRange(len,len);
+ }
+ };
+ if (replyForm.length > 0) {
+ // Update the existing form...
+ nextStep();
+ } else {
+ // Remove placeholder if any
+ $('li.notice-reply-placeholder').remove();
+
+ // Create the reply form entry at the end
+ var replyItem = $('li.notice-reply', list);
+ if (replyItem.length == 0) {
+ var url = $('#form_notice').attr('action');
+ replyItem = $('<li class="notice-reply"></li>');
+ $.get(url, {ajax: 1}, function(data, textStatus, xhr) {
+ var formEl = document._importNode($('form', data)[0], true);
+ replyItem.append(formEl);
+ list.append(replyItem);
+
+ var form = replyForm = $(formEl);
+ SN.U.NoticeLocationAttach(form);
+ SN.U.FormNoticeXHR(form);
+ SN.U.FormNoticeEnhancements(form);
+ SN.U.NoticeDataAttach(form);
+
+ nextStep();
+ });
+ /*
+ replyItem = $('<li class="notice-reply">' +
+ '<form class="notice-reply-form" method="post">' +
+ '<textarea name="status_textarea"></textarea>' +
+ '<div class="controls">' +
+ '<input type="hidden" name="token">' +
+ '<input type="hidden" name="inreplyto">' +
+ '<input type="submit" class="submit">' +
+ '</div>' +
+ '</form>' +
+ '</li>');
+ var baseForm = $('#form_notice');
+ replyForm = replyItem.find('form');
+ replyForm.attr('action', baseForm.attr('action'));
+ replyForm.find('input[name="token"]').val(baseForm.find('input[name=token]').val());
+ replyForm.find('input[type="submit"]').val(SN.msg('reply_submit'));
+ list.append(replyItem);
+
+ replyForm.find('textarea').blur(function() {
+ var textarea = $(this);
+ var txt = $.trim(textarea.val());
+ if (txt == '' || txt == textarea.data('initialText')) {
+ // Nothing to say? Begone!
+ replyItem.remove();
+ if (list.find('li').length > 0) {
+ SN.U.NoticeInlineReplyPlaceholder(parentNotice);
+ } else {
+ list.remove();
+ }
+ }
+ });
+ replyForm.submit(function(event) {
+ var form = replyForm;
+ $.ajax({
+ type: 'POST',
+ dataType: 'xml',
+ url: SN.U.RewriteAjaxAction(form.attr('action')),
+ data: form.serialize() + '&ajax=1',
+ beforeSend: function(xhr) {
+ form
+ .addClass(SN.C.S.Processing)
+ .find('.submit')
+ .addClass(SN.C.S.Disabled)
+ .attr(SN.C.S.Disabled, SN.C.S.Disabled)
+ .end()
+ .find('textarea')
+ .addClass(SN.C.S.Disabled)
+ .attr(SN.C.S.Disabled, SN.C.S.Disabled);
+ },
+ error: function (xhr, textStatus, errorThrown) {
+ alert(errorThrown || textStatus);
+ },
+ success: function(data, textStatus) {
+ var orig_li = $('li', data)[0];
+ if (orig_li) {
+ var li = document._importNode(orig_li, true);
+ var id = $(li).attr('id');
+ if ($("#"+id).length == 0) {
+ replyItem.replaceWith(li);
+ SN.U.NoticeInlineReplyPlaceholder(parentNotice);
+ } else {
+ // Realtime came through before us...
+ replyItem.remove();
+ }
+ }
+ }
+ });
+ event.preventDefault();
+ return false;
+ });
+ */