X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=9d693160e2fbfb352131c91202acc85201e51d3c;hb=3187d6184fb957e7122b768808c6d7286e572b0a;hp=d1259b05a49441985023954a36175306f584009f;hpb=c06aba6b0a51a62dd0ef3438389e8bf5b053c7be;p=quix0rs-gnu-social.git diff --git a/js/util.js b/js/util.js index d1259b05a4..9d693160e2 100644 --- a/js/util.js +++ b/js/util.js @@ -236,10 +236,11 @@ var SN = { // StatusNet * @fixme can't submit file uploads * * @param {jQuery} form: jQuery object whose first element is a form + * @param function onSuccess: something extra to do on success * * @access public */ - FormXHR: function(form) { + FormXHR: function(form, onSuccess) { $.ajax({ type: 'POST', dataType: 'xml', @@ -261,7 +262,7 @@ var SN = { // StatusNet errorReported = $('#error', xhr.responseXML).text(); } alert(errorReported || errorThrown || textStatus); - + // Restore the form to original state. // Hopefully. :D form @@ -272,11 +273,17 @@ var SN = { // StatusNet }, success: function(data, textStatus) { if (typeof($('form', data)[0]) != 'undefined') { - form_new = document._importNode($('form', data)[0], true); + var form_new = document._importNode($('form', data)[0], true); form.replaceWith(form_new); + if (onSuccess) { + onSuccess(); + } } else if (typeof($('p', data)[0]) != 'undefined') { form.replaceWith(document._importNode($('p', data)[0], true)); + if (onSuccess) { + onSuccess(); + } } else { alert('Unknown error.'); @@ -499,7 +506,7 @@ var SN = { // StatusNet results_placeholder.replaceWith(list); } else { - var _error = $('
  • ').append(document._importNode($('p', data)[0], true)); + var _error = $('
  • ').append(document._importNode($('p', data)[0], true)); results_placeholder.html(_error); } form @@ -609,8 +616,7 @@ var SN = { // StatusNet $('#content .notice_reply').live('click', function(e) { e.preventDefault(); var notice = $(this).closest('li.notice'); - var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); - SN.U.NoticeInlineReplyTrigger(notice, '@' + nickname.text()); + SN.U.NoticeInlineReplyTrigger(notice); return false; }); }, @@ -646,6 +652,11 @@ var SN = { // StatusNet if (list.length == 0) { SN.U.NoticeInlineReplyPlaceholder(notice); list = $('ul.threaded-replies', notice); + } else { + var placeholder = $('li.notice-reply-placeholder', notice); + if (placeholder.length == 0) { + SN.U.NoticeInlineReplyPlaceholder(notice); + } } } @@ -682,7 +693,7 @@ var SN = { // StatusNet nextStep(); } else { // Hide the placeholder... - var placeholder = list.find('li.notice-reply-placeholder').hide(); + placeholder = list.find('li.notice-reply-placeholder').hide(); // Create the reply form entry at the end var replyItem = $('li.notice-reply', list); @@ -690,11 +701,10 @@ var SN = { // StatusNet replyItem = $('
  • '); var intermediateStep = function(formMaster) { - var formEl = document._importNode(formMaster, true); - replyItem.append(formEl); + replyItem.append(formMaster); list.append(replyItem); // *after* the placeholder - var form = replyForm = $(formEl); + var form = replyForm = formMaster; SN.Init.NoticeFormSetup(form); nextStep(); @@ -702,6 +712,7 @@ var SN = { // StatusNet if (SN.C.I.NoticeFormMaster) { // We've already saved a master copy of the form. // Clone it in! + console.debug("we have a saved for, using it"); intermediateStep(SN.C.I.NoticeFormMaster); } else { // Fetch a fresh copy of the notice form over AJAX. @@ -709,8 +720,8 @@ var SN = { // StatusNet // @fixme this fallback may or may not work var url = $('#form_notice').attr('action'); $.get(url, {ajax: 1}, function(data, textStatus, xhr) { - intermediateStep($('form', data)[0]); - }); + intermediateStep($('form', $(data).children())); + }, 'xml'); } } } @@ -749,11 +760,11 @@ var SN = { // StatusNet var url = $(this).attr('href'); var area = $(this).closest('.threaded-replies'); $.get(url, {ajax: 1}, function(data, textStatus, xhr) { - var replies = $('.threaded-replies', data); + var replies = $('.threaded-replies', $(data).children()); if (replies.length) { - area.replaceWith(document._importNode(replies[0], true)); + area.replaceWith(replies); } - }); + }, 'xml'); return false; }); }, @@ -765,6 +776,7 @@ var SN = { // StatusNet * popout before submitting. * * Uses 'live' rather than 'bind', so applies to future as well as present items. + * */ NoticeRepeat: function() { $('.form_repeat').live('click', function(e) { @@ -1255,7 +1267,7 @@ var SN = { // StatusNet if (NDMF.length === 0) { $(this).addClass(SN.C.S.Processing); $.get(NDM.attr('href'), null, function(data) { - $('.entity_send-a-message').append(document._importNode($('form', data)[0], true)); + $('.entity_send-a-message').append($('form', $(data).children())); NDMF = $('.entity_send-a-message .form_notice'); SN.U.FormNoticeXHR(NDMF); SN.U.FormNoticeEnhancements(NDMF); @@ -1265,7 +1277,7 @@ var SN = { // StatusNet return false; }); NDM.removeClass(SN.C.S.Processing); - }); + }, 'xml'); } else { NDMF.show(); @@ -1409,7 +1421,7 @@ var SN = { // StatusNet var form = $(this); SN.Init.NoticeFormSetup(form); }) - .find('textarea:first').focus(); + .find('.notice_data-text').focus(); } }, @@ -1468,6 +1480,10 @@ var SN = { // StatusNet }); } }); + + // Infield labels for notice form inputs. + $('.input_forms fieldset fieldset label').inFieldLabels({ fadeOpacity:0 }); + } }, @@ -1498,7 +1514,7 @@ var SN = { // StatusNet if ($('body.user_in').length > 0) { var masterForm = $('.form_notice:first'); if (masterForm.length > 0) { - SN.C.I.NoticeFormMaster = document._importNode(masterForm[0], true); + SN.C.I.NoticeFormMaster = masterForm; } SN.U.NoticeRepeat(); SN.U.NoticeReply();