]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
No separate placeholder input element for replyforms
[quix0rs-gnu-social.git] / js / util.js
index c3ca213f3a4287a103c4baa9e63b73605cee586a..9001a401c2b373183c1697c06a912db2f4bb4bf1 100644 (file)
@@ -433,7 +433,7 @@ var SN = { // StatusNet
                                         .css({display: 'none'})
                                         .fadeIn(2500);
                                     SN.U.NoticeWithAttachment($('#' + notice.id));
-                                    SN.U.switchInputFormTab("placeholder");
+                                    SN.U.switchInputFormTab(null);
                                 }
                             } else {
                                 // Not on a timeline that this belongs on?
@@ -620,37 +620,18 @@ var SN = { // StatusNet
             var parentNotice = notice;
             var stripForm = true; // strip a couple things out of reply forms that are inline
 
-            // Find the threaded replies view we'll be adding to...
             var list = notice.closest('.notices');
-            if (list.closest('.old-school').length) {
-                // We're replying to an old-school conversation thread;
-                // use the old-style ping into the top form.
-                SN.U.switchInputFormTab("status");
-                replyForm = $('#input_form_status').find('form');
-                stripForm = false;
-            } else if (list.hasClass('threaded-replies')) {
+            if (list.hasClass('threaded-replies')) {
                 // We're replying to a reply; use reply form on the end of this list.
-                // We'll add our form at the end of this; grab the root notice.
-                parentNotice = list.closest('.notice');
-
-                // See if the form's already open...
-                replyForm = $('.notice-reply-form', list);
             } else {
                 // We're replying to a parent notice; pull its threaded list
-                // and we'll add on the end of it. Will add if needed.
-                list = $('ul.threaded-replies', notice);
+                // and we'll add on the end of it. Will add the threaded list if needed.
+                var list = $('ul.threaded-replies', notice);
                 if (list.length == 0) {
-                    SN.U.NoticeInlineReplyPlaceholder(notice);
-                    list = $('ul.threaded-replies', notice);
-                } else {
-                    placeholder = $('li.notice-reply-placeholder', notice);
-                    if (placeholder.length == 0) {
-                        SN.U.NoticeInlineReplyPlaceholder(notice);
-                    }
+                    list = $('<ul class="notices threaded-replies xoxo"></ul>');
+                    notice.append(list);
+                    list = notice.find('ul.threaded-replies');
                 }
-
-                // See if the form's already open...
-                replyForm = $('.notice-reply-form', list);
             }
 
             var nextStep = function () {
@@ -681,15 +662,15 @@ var SN = { // StatusNet
                     text[0].setSelectionRange(len, len);
                 }
             };
+
+            // See if the form's already open...
+            replyForm = $('.notice-reply-form', list);
             if (replyForm.length > 0) {
                 // Update the existing form...
                 nextStep();
             } else {
-                // Hide the placeholder...
-                placeholder = list.find('li.notice-reply-placeholder').hide();
-
                 // Create the reply form entry at the end
-                var replyItem = $('li.notice-reply', list);
+                var replyItem = $('li.notice-reply > form', list);
                 if (replyItem.length == 0) {
                     replyItem = $('<li class="notice-reply"></li>');
 
@@ -721,36 +702,14 @@ var SN = { // StatusNet
             }
         },
 
-        NoticeInlineReplyPlaceholder: function (notice) {
-            var list = notice.find('ul.threaded-replies');
-            if (list.length == 0) {
-                list = $('<ul class="notices threaded-replies xoxo"></ul>');
-                notice.append(list);
-                list = notice.find('ul.threaded-replies');
-            }
-            var placeholder = $('<li class="notice-reply-placeholder">' +
-                                    '<input class="placeholder" />' +
-                                '</li>');
-            placeholder.find('input')
-                .val(SN.msg('reply_placeholder'));
-            list.append(placeholder);
-        },
-
         /**
          * Setup function -- DOES NOT apply immediately.
          *
-         * Sets up event handlers for inline reply mini-form placeholders.
          * Uses 'on' rather than 'live' or 'bind', so applies to future as well as present items.
          */
         NoticeInlineReplySetup: function () {
-            $('li.notice-reply-placeholder input')
-                .on('focus', function () {
-                    var notice = $(this).closest('li.notice');
-                    SN.U.NoticeInlineReplyTrigger(notice);
-                    return false;
-                });
-            $('li.notice-reply-comments a')
-                .on('click', function () {
+            // Expand conversation links
+            $(document).on('click', 'li.notice-reply-comments a', function () {
                     var url = $(this).attr('href');
                     var area = $(this).closest('.threaded-replies');
                     $.get(url, {ajax: 1}, function (data, textStatus, xhr) {
@@ -773,7 +732,7 @@ var SN = { // StatusNet
          *
          */
         NoticeRepeat: function () {
-            $('.form_repeat').on('click', function (e) {
+            $('body').on('click', '.form_repeat', function (e) {
                 e.preventDefault();
 
                 SN.U.NoticeRepeatConfirmation($(this));
@@ -857,18 +816,16 @@ var SN = { // StatusNet
                 return;
             }
 
-            var attachment_more = notice.find('.attachment.more');
-            if (attachment_more.length > 0) {
-                $(attachment_more[0]).click(function () {
-                    var m = $(this);
-                    m.addClass(SN.C.S.Processing);
-                    $.get(m.attr('href'), {ajax: 1}, function (data) {
-                        m.parent('.entry-content').html($(data).find('#attachment_view .entry-content').html());
-                    });
+                       $(document).on('click','.attachment.more',function () {
+                               var m = $(this);
+                               m.addClass(SN.C.S.Processing);
+                               $.get(m.attr('href'), {ajax: 1}, function (data) {
+                                       m.parent('.e-content').html($(data).find('#attachment_view .e-content').html());
+                               });
+
+                               return false;
+                       });
 
-                    return false;
-                }).attr('title', SN.msg('showmore_tooltip'));
-            }
         },
 
         /**
@@ -1361,7 +1318,7 @@ var SN = { // StatusNet
 
             var profileLink = $('#nav_profile a').attr('href');
             if (profileLink) {
-                var authorUrl = $(notice).find('.vcard.author a.url').attr('href');
+                var authorUrl = $(notice).find('.h-card.p-author').attr('href');
                 if (authorUrl == profileLink) {
                     if (action == 'all' || action == 'showstream') {
                         // Posts always show on your own friends and profile streams.
@@ -1374,7 +1331,7 @@ var SN = { // StatusNet
             // Mismatch between id-based and name-based user/group links currently complicates
             // the lookup, since all our inline mentions contain the absolute links but the
             // UI links currently on the page use malleable names.
-
+            
             return false;
         },
 
@@ -1385,14 +1342,11 @@ var SN = { // StatusNet
          *
          * @param {String} tag
          */
-    switchInputFormTab: function (tag) {
-        // The one that's current isn't current anymore
-        $('.input_form_nav_tab.current').removeClass('current');
-            if (tag == 'placeholder') {
-                // Hack: when showing the placeholder, mark the tab
-                // as current for 'Status'.
-                $('#input_form_nav_status').addClass('current');
-            } else {
+        switchInputFormTab: function (tag, setFocus) {
+            if (typeof setFocus === 'undefined') { setFocus = true; }
+            // The one that's current isn't current anymore
+            $('.input_form_nav_tab.current').removeClass('current');
+            if (tag != null) {
                 $('#input_form_nav_' + tag).addClass('current');
             }
 
@@ -1404,17 +1358,24 @@ var SN = { // StatusNet
                 return;
             }
 
-        $('.input_form.current').removeClass('current');
-        $('#input_form_' + tag)
-                .addClass('current')
-                .find('.ajax-notice').each(function () {
-                    var form = $(this);
-                    SN.Init.NoticeFormSetup(form);
-                })
-                .find('.notice_data-text').focus();
+            $('.input_form.current').removeClass('current');
+            if (tag == null) {
+                // we're done here, no new inputform to focus on
+                return false;
+            }
 
-        return false;
-    },
+            var noticeForm = $('#input_form_' + tag)
+                    .addClass('current')
+                    .find('.ajax-notice').each(function () {
+                        var form = $(this);
+                        SN.Init.NoticeFormSetup(form);
+                    });
+            if (setFocus) {
+                noticeForm.find('.notice_data-text').focus();
+            }
+
+            return false;
+        },
 
         showMoreMenuItems: function (menuid) {
             $('#' + menuid + ' .more_link').remove();
@@ -1439,28 +1400,14 @@ var SN = { // StatusNet
                 // 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");
+                // Initialize the input form field
+                $('#input_form_nav .input_form_nav_tab.current').each(function () {
+                    current_tab_id = $(this).attr('id').substring('input_form_nav_'.length);
+                    SN.U.switchInputFormTab(current_tab_id, false);
                 });
 
                 // Make inline reply forms self-close when clicking out.
                 $('body').on('click', function (e) {
-                    var currentForm = $('#content .input_forms div.current');
-                    if (currentForm.length > 0) {
-                        if ($('#content .input_forms').has(e.target).length == 0) {
-                            // If all fields are empty, switch back to the placeholder.
-                            var fields = currentForm.find('textarea, input[type=text], input[type=""]');
-                            var anything = false;
-                            fields.each(function () {
-                                anything = anything || $(this).val();
-                            });
-                            if (!anything) {
-                                SN.U.switchInputFormTab("placeholder");
-                            }
-                        }
-                    }
-
                     var openReplies = $('li.notice-reply');
                     if (openReplies.length > 0) {
                         var target = $(e.target);
@@ -1483,7 +1430,6 @@ var SN = { // StatusNet
 
                 // Infield labels for notice form inputs.
                 $('.input_forms fieldset fieldset label').inFieldLabels({ fadeOpacity:0 });
-
             }
         },
 
@@ -1576,60 +1522,6 @@ var SN = { // StatusNet
             });
         },
 
-        /**
-         * Called when a people tag edit box is shown in the interface
-         *
-         * - loads the jQuery UI autocomplete plugin
-         * - sets event handlers for tag completion
-         *
-         */
-        PeopletagAutocomplete: function (txtBox) {
-            var split = function (val) {
-                return val.split( /\s+/ );
-            }
-            var extractLast = function (term) {
-                return split(term).pop();
-            }
-
-            // don't navigate away from the field on tab when selecting an item
-            txtBox.on( "keydown", function ( event ) {
-                if ( event.keyCode === $.ui.keyCode.TAB &&
-                        $(this).data( "autocomplete" ).menu.active ) {
-                    event.preventDefault();
-                }
-            }).autocomplete({
-                minLength: 0,
-                source: function (request, response) {
-                    // delegate back to autocomplete, but extract the last term
-                    response($.ui.autocomplete.filter(
-                        SN.C.PtagACData, extractLast(request.term)));
-                },
-                focus: function () {
-                    return false;
-                },
-                select: function (event, ui) {
-                    var terms = split(this.value);
-                    terms.pop();
-                    terms.push(ui.item.value);
-                    terms.push("");
-                    this.value = terms.join(" ");
-                    return false;
-                }
-            }).data('autocomplete')._renderItem = function (ul, item) {
-                    // FIXME: with jQuery UI you cannot have it highlight the match
-                    var _l = '<a class="ptag-ac-line-tag">' + item.tag
-                          + ' <em class="privacy_mode">' + item.mode + '</em>'
-                          + '<span class="freq">' + item.freq + '</span></a>'
-
-                    return $("<li/>")
-                            .addClass('mode-' + item.mode)
-                            .addClass('ptag-ac-line')
-                            .data("item.autocomplete", item)
-                            .append(_l)
-                            .appendTo(ul);
-                }
-        },
-
         /**
          * Run setup for the ajax people tags editor
          *
@@ -1658,7 +1550,6 @@ var SN = { // StatusNet
                         }
 
                         SN.C.PtagACData = data;
-                        SN.Init.PeopletagAutocomplete(form.find('#tags'));
                     }
                 });