]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
jquery infieldlabel.js removed from script list
[quix0rs-gnu-social.git] / js / util.js
index ceeb1776a9da07cc02e5c36db11fc19278a79592..85f917b09aeb67f107f20814c0f71166c2396342 100644 (file)
@@ -32,7 +32,6 @@ var SN = { // StatusNet
             MaxLength: 140,
             PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
             HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307],
-            NoticeFormMaster: null // to be cloned from the one at top
         },
 
         /**
@@ -94,12 +93,12 @@ var SN = { // StatusNet
          * @access private
          */
         FormNoticeEnhancements: function (form) {
-            if (jQuery.data(form[0], 'ElementData') === undefined) {
+            if ($.data(form[0], 'ElementData') === undefined) {
                 var MaxLength = form.find('.count').text();
                 if (MaxLength === undefined) {
                     MaxLength = SN.C.I.MaxLength;
                 }
-                jQuery.data(form[0], 'ElementData', {MaxLength: MaxLength});
+                $.data(form[0], 'ElementData', {MaxLength: MaxLength});
 
                 SN.U.Counter(form);
 
@@ -122,7 +121,7 @@ var SN = { // StatusNet
                 NDT.on('cut', delayedUpdate)
                     .on('paste', delayedUpdate);
             } else {
-                form.find('.count').text(jQuery.data(form[0], 'ElementData').MaxLength);
+                form.find('.count').text($.data(form[0], 'ElementData').MaxLength);
             }
         },
 
@@ -143,7 +142,7 @@ var SN = { // StatusNet
         Counter: function (form) {
             SN.C.I.FormNoticeCurrent = form;
 
-            var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
+            var MaxLength = $.data(form[0], 'ElementData').MaxLength;
 
             if (MaxLength <= 0) {
                 return;
@@ -375,7 +374,7 @@ var SN = { // StatusNet
                         if ($('.' + SN.C.S.Error, response).length > 0) {
                             form.append(document._importNode($('.' + SN.C.S.Error, response)[0], true));
                         } else {
-                            if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
+                            if (parseInt(xhr.status) === 0 || $.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
                                 form
                                     .resetForm()
                                     .find('.attach-status').remove();
@@ -411,7 +410,7 @@ var SN = { // StatusNet
                                     $(notice).insertBefore(replyItem);
                                 } // else Realtime came through before us...
 
-                                alert('reset form now');
+                                replyItem.remove();
 
                             } else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
                                 // Not a reply. If on our timeline, show it at the top!
@@ -576,6 +575,32 @@ var SN = { // StatusNet
             }
         },
 
+        /**
+         * Setup function -- DOES NOT trigger actions immediately.
+         *
+         * Sets up event handlers on all visible notice's option <a> elements
+         * so they are called with AJAX enabled.
+         *
+         * (without javascript the link goes to a page that expects you to verify
+         * the action through a form)
+         *
+         * @access private
+         */
+        NoticeOptionsAjax: function () {
+            $(document).on('click', '.notice-options > a', function (e) {
+                e.preventDefault();
+                var noticeEl = $(this).closest('.notice');
+                $.get($(this).attr('href'), {ajax: 1}, function (data, textStatus, xhr) {
+                    SN.U.NoticeOptionPopup($('body', data).html());
+                });
+                return false;
+            });
+        },
+
+        NoticeOptionPopup: function (html) {
+            dialog = $(html).dialog();
+        },
+
         /**
          * Setup function -- DOES NOT trigger actions immediately.
          *
@@ -661,42 +686,29 @@ var SN = { // StatusNet
                 }
             };
 
-            // See if the form's already open...
-            replyForm = $('.notice-reply-form', list);
-            if (replyForm.length > 0) {
-                // Update the existing form...
-                nextStep();
+            // Create the reply form entry at the end
+            var replyItem = $('li.notice-reply', list);
+            if (replyItem.length == 0) {
+                replyItem = $('<li class="notice-reply"></li>');
+
+                // Fetch a fresh copy of the notice form over AJAX.
+                var url = $('#input_form_status > form').attr('action');
+                $.get(url, {ajax: 1, inreplyto: id}, function (data, textStatus, xhr) {
+                    var formEl = document._importNode($('form', data)[0], true);
+                    replyItem.append(formEl);
+                    list.append(replyItem);
+
+                    replyForm = $(formEl);
+                    SN.Init.NoticeFormSetup(replyForm);
+                    nextStep();
+                });
             } else {
-                // Create the reply form entry at the end
-                var replyItem = $('li.notice-reply > form', list);
-                if (replyItem.length == 0) {
-                    replyItem = $('<li class="notice-reply"></li>');
-
-                    var intermediateStep = function (formMaster) {
-                        var formEl = document._importNode(formMaster, true);
-                        replyItem.append(formEl);
-                        list.append(replyItem); // *after* the placeholder
-
-                        var form = $(formEl);
-                        replyForm = form;
-                        SN.Init.NoticeFormSetup(form);
-
-                        nextStep();
-                    };
-                    if (SN.C.I.NoticeFormMaster) {
-                        // We've already saved a master copy of the form.
-                        // Clone it in!
-                        intermediateStep(SN.C.I.NoticeFormMaster);
-                    } else {
-                        // Fetch a fresh copy of the notice form over AJAX.
-                        // Warning: this can have a delay, which looks bad.
-                        // @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]);
-                        });
-                    }
+                replyForm = replyItem.children('form');
+                if (SN.Init.NoticeFormSetup(replyForm)) {
+                    nextStep();
                 }
+                replyItem.show();
+                replyItem.find('textarea').focus();
             }
         },
 
@@ -787,6 +799,14 @@ var SN = { // StatusNet
             });
         },
 
+        NoticeOptionPopup: function (html) {
+            dialog = $(html).dialog({
+                    resizable: false,
+                    height: 150,
+                    modal: true,
+                });
+        },
+
         /**
          * Setup function -- DOES NOT trigger actions immediately.
          *
@@ -1001,7 +1021,7 @@ var SN = { // StatusNet
 
             function removeNoticeDataGeo(error) {
                 label
-                    .attr('title', jQuery.trim(label.text()))
+                    .attr('title', $.trim(label.text()))
                     .removeClass('checked');
 
                 form.find('[name=lat]').val('');
@@ -1418,16 +1438,13 @@ var SN = { // StatusNet
                                 // Only close if there's been no edit.
                                 if (cur == '' || cur == textarea.data('initialText')) {
                                     var parentNotice = replyItem.closest('li.notice');
-                                    replyItem.remove();
+                                    replyItem.hide();
                                     parentNotice.find('li.notice-reply-placeholder').show();
                                 }
                             }
                         });
                     }
                 });
-
-                // Infield labels for notice form inputs.
-                $('.input_forms fieldset fieldset label').inFieldLabels({ fadeOpacity:0 });
             }
         },
 
@@ -1439,13 +1456,14 @@ var SN = { // StatusNet
          * @param {jQuery} form
          */
         NoticeFormSetup: function (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);
+            if (form.data('NoticeFormSetup')) {
+                return false;
             }
+            SN.U.NoticeLocationAttach(form);
+            SN.U.FormNoticeXHR(form);
+            SN.U.FormNoticeEnhancements(form);
+            SN.U.NoticeDataAttach(form);
+            form.data('NoticeFormSetup', true);
         },
 
         /**
@@ -1456,13 +1474,10 @@ var SN = { // StatusNet
          */
         Notices: function () {
             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.U.NoticeRepeat();
                 SN.U.NoticeReply();
                 SN.U.NoticeInlineReplySetup();
+                SN.U.NoticeOptionsAjax();
             }
 
             SN.U.NoticeAttachments();