]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Make inline reply forms close when clicking outside them if there's no text again.
[quix0rs-gnu-social.git] / js / util.js
index cc95a08bf58049232abfd41557e2dc5e6213c583..29fdfe2a98f47f0ac8fa5d2c278af0cd1abf7df6 100644 (file)
@@ -640,6 +640,7 @@ var SN = { // StatusNet
                                 '</li>');
             placeholder.click(function() {
                 SN.U.NoticeInlineReplyTrigger(notice);
+                return false;
             });
             placeholder.find('input').val(SN.msg('reply_placeholder'));
             list.append(placeholder);
@@ -1309,6 +1310,27 @@ var SN = { // StatusNet
                     var form = $(this);
                     SN.Init.NoticeFormSetup(form);
                 });
+
+                // Make inline reply forms self-close when clicking out.
+                $('body').bind('click', function(e) {
+                    var openReplies = $('li.notice-reply');
+                    if (openReplies.length > 0) {
+                        var target = $(e.target).closest('li.notice-reply');
+                        if (target.length == 0) {
+                            // There are inline replies open, and we
+                            // clicked outside of one...
+                            openReplies.each(function() {
+                                var replyItem = $(this);
+                                // Only close if there's been no edit.
+                                if (replyItem.find('.notice_data-text:first').val() == '') {
+                                    var parentNotice = replyItem.closest('li.notice');
+                                    replyItem.remove();
+                                    SN.U.NoticeInlineReplyPlaceholder(parentNotice);
+                                }
+                            });
+                        }
+                    }
+                });
             }
         },