Replies to replies without reloading page now work

This commit is contained in:
Mikael Nordfeldth 2015-03-06 23:47:03 +01:00
parent c48a9191c8
commit 8cf0628f28
1 changed files with 27 additions and 31 deletions

View File

@ -94,12 +94,12 @@ var SN = { // StatusNet
* @access private * @access private
*/ */
FormNoticeEnhancements: function (form) { FormNoticeEnhancements: function (form) {
if (jQuery.data(form[0], 'ElementData') === undefined) { if ($.data(form[0], 'ElementData') === undefined) {
var MaxLength = form.find('.count').text(); var MaxLength = form.find('.count').text();
if (MaxLength === undefined) { if (MaxLength === undefined) {
MaxLength = SN.C.I.MaxLength; MaxLength = SN.C.I.MaxLength;
} }
jQuery.data(form[0], 'ElementData', {MaxLength: MaxLength}); $.data(form[0], 'ElementData', {MaxLength: MaxLength});
SN.U.Counter(form); SN.U.Counter(form);
@ -122,7 +122,7 @@ var SN = { // StatusNet
NDT.on('cut', delayedUpdate) NDT.on('cut', delayedUpdate)
.on('paste', delayedUpdate); .on('paste', delayedUpdate);
} else { } else {
form.find('.count').text(jQuery.data(form[0], 'ElementData').MaxLength); form.find('.count').text($.data(form[0], 'ElementData').MaxLength);
} }
}, },
@ -143,7 +143,7 @@ var SN = { // StatusNet
Counter: function (form) { Counter: function (form) {
SN.C.I.FormNoticeCurrent = form; SN.C.I.FormNoticeCurrent = form;
var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength; var MaxLength = $.data(form[0], 'ElementData').MaxLength;
if (MaxLength <= 0) { if (MaxLength <= 0) {
return; return;
@ -375,7 +375,7 @@ var SN = { // StatusNet
if ($('.' + SN.C.S.Error, response).length > 0) { if ($('.' + SN.C.S.Error, response).length > 0) {
form.append(document._importNode($('.' + SN.C.S.Error, response)[0], true)); form.append(document._importNode($('.' + SN.C.S.Error, response)[0], true));
} else { } else {
if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) { if (parseInt(xhr.status) === 0 || $.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
form form
.resetForm() .resetForm()
.find('.attach-status').remove(); .find('.attach-status').remove();
@ -411,7 +411,7 @@ var SN = { // StatusNet
$(notice).insertBefore(replyItem); $(notice).insertBefore(replyItem);
} // else Realtime came through before us... } // else Realtime came through before us...
alert('reset form now'); replyItem.remove();
} else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) { } else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
// Not a reply. If on our timeline, show it at the top! // Not a reply. If on our timeline, show it at the top!
@ -666,28 +666,24 @@ var SN = { // StatusNet
if (replyItem.length == 0) { if (replyItem.length == 0) {
replyItem = $('<li class="notice-reply"></li>'); replyItem = $('<li class="notice-reply"></li>');
var intermediateStep = function (formMaster) { // Fetch a fresh copy of the notice form over AJAX.
var formEl = document._importNode(formMaster, true); var url = $('#input_form_status > form').attr('action');
$.get(url, {ajax: 1, inreplyto: id}, function (data, textStatus, xhr) {
var formEl = document._importNode($('form', data)[0], true);
replyItem.append(formEl); replyItem.append(formEl);
list.append(replyItem); // *after* the placeholder list.append(replyItem);
var form = $(formEl);
replyForm = form;
SN.Init.NoticeFormSetup(form);
replyForm = $(formEl);
SN.Init.NoticeFormSetup(replyForm);
nextStep(); nextStep();
}; });
if (SN.C.I.NoticeFormMaster) {
// We've already saved a master copy of the form.
// Clone it in!
intermediateStep(SN.C.I.NoticeFormMaster);
}
} else { } else {
replyItem.show(); replyForm = replyItem.children('form');
replyTextarea = replyItem.find('textarea'); if (SN.Init.NoticeFormSetup(replyForm)) {
if (replyTextarea) { nextStep();
replyTextarea.focus();
} }
replyItem.show();
replyItem.find('textarea').focus();
} }
}, },
@ -697,7 +693,6 @@ var SN = { // StatusNet
* Uses 'on' rather than 'live' or 'bind', so applies to future as well as present items. * Uses 'on' rather than 'live' or 'bind', so applies to future as well as present items.
*/ */
NoticeInlineReplySetup: function () { NoticeInlineReplySetup: function () {
$('#content .notice-reply').hide();
// Expand conversation links // Expand conversation links
$(document).on('click', 'li.notice-reply-comments a', function () { $(document).on('click', 'li.notice-reply-comments a', function () {
var url = $(this).attr('href'); var url = $(this).attr('href');
@ -993,7 +988,7 @@ var SN = { // StatusNet
function removeNoticeDataGeo(error) { function removeNoticeDataGeo(error) {
label label
.attr('title', jQuery.trim(label.text())) .attr('title', $.trim(label.text()))
.removeClass('checked'); .removeClass('checked');
form.find('[name=lat]').val(''); form.find('[name=lat]').val('');
@ -1431,13 +1426,14 @@ var SN = { // StatusNet
* @param {jQuery} form * @param {jQuery} form
*/ */
NoticeFormSetup: function (form) { NoticeFormSetup: function (form) {
if (!form.data('NoticeFormSetup')) { if (form.data('NoticeFormSetup')) {
SN.U.NoticeLocationAttach(form); return false;
SN.U.FormNoticeXHR(form);
SN.U.FormNoticeEnhancements(form);
SN.U.NoticeDataAttach(form);
form.data('NoticeFormSetup', true);
} }
SN.U.NoticeLocationAttach(form);
SN.U.FormNoticeXHR(form);
SN.U.FormNoticeEnhancements(form);
SN.U.NoticeDataAttach(form);
form.data('NoticeFormSetup', true);
}, },
/** /**