]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Translator documentation updated.
[quix0rs-gnu-social.git] / js / util.js
index d0d23d464d606f5c7004aefb0b2c5e22872ec811..9c074fdaa85746cf9bc372ae935c3169331e4f92 100644 (file)
@@ -253,16 +253,34 @@ var SN = { // StatusNet
                             .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.');
+                    }
                 }
             });
         },
@@ -394,16 +412,20 @@ var SN = { // StatusNet
                             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!
 
@@ -586,8 +608,8 @@ var SN = { // StatusNet
                 // 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);
@@ -597,7 +619,7 @@ var SN = { // StatusNet
                     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);
@@ -627,26 +649,35 @@ var SN = { // StatusNet
                                     '<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;
+                });
         },
 
         /**
@@ -1345,7 +1376,7 @@ var SN = { // StatusNet
                                 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();
                                 }
                             }
                         });
@@ -1433,6 +1464,18 @@ var SN = { // StatusNet
                 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);
+            });
         },
 
         /**