]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Focus in textarea when popping up the status tab
[quix0rs-gnu-social.git] / js / util.js
index 29fdfe2a98f47f0ac8fa5d2c278af0cd1abf7df6..4ff2b661feb684e1b3516080a4fa36bb631927a6 100644 (file)
@@ -599,7 +599,7 @@ var SN = { // StatusNet
                 nextStep();
             } else {
                 // Remove placeholder if any
-                $('li.notice-reply-placeholder').remove();
+                list.find('li.notice-reply-placeholder').remove();
 
                 // Create the reply form entry at the end
                 var replyItem = $('li.notice-reply', list);
@@ -638,11 +638,12 @@ var SN = { // StatusNet
             var placeholder = $('<li class="notice-reply-placeholder">' +
                                     '<input class="placeholder">' +
                                 '</li>');
-            placeholder.click(function() {
-                SN.U.NoticeInlineReplyTrigger(notice);
-                return false;
-            });
-            placeholder.find('input').val(SN.msg('reply_placeholder'));
+            placeholder.find('input')
+                .val(SN.msg('reply_placeholder'))
+                .focus(function() {
+                    SN.U.NoticeInlineReplyTrigger(notice);
+                    return false;
+                });
             list.append(placeholder);
         },
 
@@ -1016,8 +1017,7 @@ var SN = { // StatusNet
                 }
 
                 var NGW = form.find('.notice_data-geo_wrap');
-                var geocodeURL = NGW.attr('title');
-                NGW.removeAttr('title');
+                var geocodeURL = NGW.attr('data-api');
 
                 label
                     .attr('title', label.text());
@@ -1117,6 +1117,7 @@ var SN = { // StatusNet
                 wrapper = $('<div class="'+SN.C.S.Success+' geo_status_wrapper"><button class="close" style="float:right">&#215;</button><div class="geo_status"></div></div>');
                 wrapper.find('button.close').click(function() {
                     form.find('[name=notice_data-geo]').removeAttr('checked').change();
+                    return false;
                 });
                 form.append(wrapper);
             }
@@ -1291,7 +1292,13 @@ var SN = { // StatusNet
            $('#input_form_nav_'+tag).addClass('current');
 
            $('.input_form.current').removeClass('current');
-           $('#input_form_'+tag).addClass('current');
+           $('#input_form_'+tag)
+                .addClass('current')
+                .find('.ajax-notice').each(function() {
+                    var form = $(this);
+                    SN.Init.NoticeFormSetup(form);
+                })
+                .find('textarea:first').focus();
        }
     },
 
@@ -1306,29 +1313,33 @@ var SN = { // StatusNet
          */
         NoticeForm: function() {
             if ($('body.user_in').length > 0) {
-                $('.ajax-notice').each(function() {
-                    var form = $(this);
-                    SN.Init.NoticeFormSetup(form);
+                // SN.Init.NoticeFormSetup() will get run
+                // when forms get displayed for the first time...
+
+                // Hack to initialize the placeholder at top
+                $('#input_form_placeholder input.placeholder').focus(function() {
+                    SN.U.switchInputFormTab("status");
                 });
 
                 // 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);
+                        var target = $(e.target);
+                        openReplies.each(function() {
+                            // Did we click outside this one?
+                            var replyItem = $(this);
+                            if (replyItem.has(e.target).length == 0) {
+                                var textarea = replyItem.find('.notice_data-text:first');
+                                var cur = $.trim(textarea.val());
                                 // Only close if there's been no edit.
-                                if (replyItem.find('.notice_data-text:first').val() == '') {
+                                if (cur == '' || cur == textarea.data('initialText')) {
                                     var parentNotice = replyItem.closest('li.notice');
                                     replyItem.remove();
                                     SN.U.NoticeInlineReplyPlaceholder(parentNotice);
                                 }
-                            });
-                        }
+                            }
+                        });
                     }
                 });
             }
@@ -1342,10 +1353,13 @@ var SN = { // StatusNet
          * @param {jQuery} form
          */
         NoticeFormSetup: function(form) {
-            SN.U.NoticeLocationAttach(form);
-            SN.U.FormNoticeXHR(form);
-            SN.U.FormNoticeEnhancements(form);
-            SN.U.NoticeDataAttach(form);
+            if (!form.data('NoticeFormSetup')) {
+                SN.U.NoticeLocationAttach(form);
+                SN.U.FormNoticeXHR(form);
+                SN.U.FormNoticeEnhancements(form);
+                SN.U.NoticeDataAttach(form);
+                form.data('NoticeFormSetup', true);
+            }
         },
 
         /**