]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Reusable notice form fixes for geolocation
[quix0rs-gnu-social.git] / js / util.js
index 6d0998aa429bcf2b23b52208fbbc613194bc0535..1bd011cb0d8069621c17d47c00bc5a3ffe9c3936 100644 (file)
@@ -553,13 +553,54 @@ var SN = { // StatusNet
 
             // See if the form's already open...
             var replyForm = $('.notice-reply-form', list);
-            if (replyForm.length == 0) {
+
+            var nextStep = function() {
+                // Override...?
+                replyForm.find('input[name=inreplyto]').val(id);
+
+                // Set focus...
+                var text = replyForm.find('textarea');
+                if (text.length == 0) {
+                    throw "No textarea";
+                }
+                var replyto = '';
+                if (initialText) {
+                    replyto = initialText + ' ';
+                }
+                text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
+                text.data('initialText', $.trim(initialText + ''));
+                text.focus();
+                if (text[0].setSelectionRange) {
+                    var len = text.val().length;
+                    text[0].setSelectionRange(len,len);
+                }
+            };
+            if (replyForm.length > 0) {
+                // Update the existing form...
+                nextStep();
+            } else {
                 // Remove placeholder if any
                 $('li.notice-reply-placeholder').remove();
 
                 // Create the reply form entry at the end
                 var replyItem = $('li.notice-reply', list);
                 if (replyItem.length == 0) {
+                    var url = $('#form_notice').attr('action');
+                    replyItem = $('<li class="notice-reply"></li>');
+                    $.get(url, {ajax: 1}, function(data, textStatus, xhr) {
+                        var formEl = document._importNode($('form', data)[0], true);
+                        replyItem.append(formEl);
+                        list.append(replyItem);
+
+                        var form = replyForm = $(formEl);
+                        SN.U.NoticeLocationAttach(form);
+                        SN.U.FormNoticeXHR(form);
+                        SN.U.FormNoticeEnhancements(form);
+                        SN.U.NoticeDataAttach(form);
+
+                        nextStep();
+                    });
+                    /*
                     replyItem = $('<li class="notice-reply">' +
                                       '<form class="notice-reply-form" method="post">' +
                                           '<textarea name="status_textarea"></textarea>' +
@@ -570,7 +611,6 @@ var SN = { // StatusNet
                                       '</div>' +
                                       '</form>' +
                                   '</li>');
-
                     var baseForm = $('#form_notice');
                     replyForm = replyItem.find('form');
                     replyForm.attr('action', baseForm.attr('action'));
@@ -630,28 +670,9 @@ var SN = { // StatusNet
                         event.preventDefault();
                         return false;
                     });
+                                  */
                 }
             }
-
-            // Override...?
-            replyForm.find('input[name=inreplyto]').val(id);
-
-            // Set focus...
-            var text = replyForm.find('textarea');
-            if (text.length == 0) {
-                throw "No textarea";
-            }
-            var replyto = '';
-            if (initialText) {
-                replyto = initialText + ' ';
-            }
-            text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
-            text.data('initialText', $.trim(initialText + ''));
-            text.focus();
-            if (text[0].setSelectionRange) {
-                var len = text.val().length;
-                text[0].setSelectionRange(len,len);
-            }
         },
 
         /**
@@ -969,7 +990,7 @@ var SN = { // StatusNet
             var NLN = ''; // @fixme
             var NDGe = form.find('[name=notice_data-geo]');
             var check = form.find('[name=notice_data-geo]');
-            var label = $('label[for='+check.attr('id')+']');
+            var label = form.find('label.notice_data-geo');
 
             function removeNoticeDataGeo(error) {
                 label
@@ -1143,7 +1164,6 @@ var SN = { // StatusNet
          */
         NoticeGeoStatus: function(form, status, lat, lon, url)
         {
-            var form = $('#form_notice');
             var wrapper = form.find('.geo_status_wrapper');
             if (wrapper.length == 0) {
                 wrapper = $('<div class="'+SN.C.S.Success+' geo_status_wrapper"><button class="close" style="float:right">&#215;</button><div class="geo_status"></div></div>');