.attr(SN.C.S.Disabled, SN.C.S.Disabled);
},
error: function (xhr, textStatus, errorThrown) {
- alert(errorThrown || textStatus);
+ // If the server end reported an error from StatusNet,
+ // find it -- otherwise we'll see what was reported
+ // from the browser.
+ var errorReported = null;
+ if (xhr.responseXML) {
+ errorReported = $('#error', xhr.responseXML).text();
+ }
+ alert(errorReported || errorThrown || textStatus);
+
+ // Restore the form to original state.
+ // Hopefully. :D
+ form
+ .removeClass(SN.C.S.Processing)
+ .find('.submit')
+ .removeClass(SN.C.S.Disabled)
+ .removeAttr(SN.C.S.Disabled);
},
success: function(data, textStatus) {
if (typeof($('form', data)[0]) != 'undefined') {
form_new = document._importNode($('form', data)[0], true);
form.replaceWith(form_new);
}
- else {
+ else if (typeof($('p', data)[0]) != 'undefined') {
form.replaceWith(document._importNode($('p', data)[0], true));
}
+ else {
+ alert('Unknown error.');
+ }
}
});
},
var replyItem = form.closest('li.notice-reply');
if (replyItem.length > 0) {
- // If this is an inline reply, insert it in place.
+ // If this is an inline reply, remove the form...
+ var list = form.closest('.threaded-replies');
+ var placeholder = list.find('.notice-reply-placeholder');
+ replyItem.remove();
+
var id = $(notice).attr('id');
if ($("#"+id).length == 0) {
- var parentNotice = replyItem.closest('li.notice');
- replyItem.replaceWith(notice);
- SN.U.NoticeInlineReplyPlaceholder(parentNotice);
+ $(notice).insertBefore(placeholder);
} else {
// Realtime came through before us...
- replyItem.remove();
}
+
+ // ...and show the placeholder form.
+ placeholder.show();
} else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
// Not a reply. If on our timeline, show it at the top!
// Update the existing form...
nextStep();
} else {
- // Remove placeholder if any
- list.find('li.notice-reply-placeholder').remove();
+ // Hide the placeholder...
+ var placeholder = list.find('li.notice-reply-placeholder').hide();
// Create the reply form entry at the end
var replyItem = $('li.notice-reply', list);
var intermediateStep = function(formMaster) {
var formEl = document._importNode(formMaster, true);
replyItem.append(formEl);
- list.append(replyItem);
+ list.append(replyItem); // *after* the placeholder
var form = replyForm = $(formEl);
SN.Init.NoticeFormSetup(form);
'<input class="placeholder">' +
'</li>');
placeholder.find('input')
- .val(SN.msg('reply_placeholder'))
- .focus(function() {
- SN.U.NoticeInlineReplyTrigger(notice);
- return false;
- });
+ .val(SN.msg('reply_placeholder'));
list.append(placeholder);
},
/**
* Setup function -- DOES NOT apply immediately.
*
- * Sets up event handlers for favor/disfavor forms to submit via XHR.
+ * Sets up event handlers for inline reply mini-form placeholders.
* Uses 'live' rather than 'bind', so applies to future as well as present items.
*/
NoticeInlineReplySetup: function() {
- $('.threaded-replies').each(function() {
- var list = $(this);
- var notice = list.closest('.notice');
- SN.U.NoticeInlineReplyPlaceholder(notice);
- });
+ $('li.notice-reply-placeholder input')
+ .live('focus', function() {
+ var notice = $(this).closest('li.notice');
+ SN.U.NoticeInlineReplyTrigger(notice);
+ return false;
+ });
+ $('li.notice-reply-comments a')
+ .live('click', function() {
+ var url = $(this).attr('href');
+ var area = $(this).closest('.threaded-replies');
+ $.get(url, {ajax: 1}, function(data, textStatus, xhr) {
+ var replies = $('.threaded-replies', data);
+ if (replies.length) {
+ area.replaceWith(document._importNode(replies[0], true));
+ }
+ });
+ return false;
+ });
},
/**
if (cur == '' || cur == textarea.data('initialText')) {
var parentNotice = replyItem.closest('li.notice');
replyItem.remove();
- SN.U.NoticeInlineReplyPlaceholder(parentNotice);
+ parentNotice.find('li.notice-reply-placeholder').show();
}
}
});
SN.U.FormXHR($(this));
return false;
});
+ $('form.ajax input[type=submit]').live('click', function() {
+ // Some forms rely on knowing which submit button was clicked.
+ // Save a hidden input field which'll be picked up during AJAX
+ // submit...
+ var button = $(this);
+ var form = button.closest('form');
+ form.find('.hidden-submit-button').remove();
+ $('<input class="hidden-submit-button" type="hidden" />')
+ .attr('name', button.attr('name'))
+ .val(button.val())
+ .appendTo(form);
+ });
},
/**