]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Let's you upload a file with a notice and have it shown with other attachments.
[quix0rs-gnu-social.git] / js / util.js
index 81139744ff9cdab7eb928df3f2e83a5df5611562..85ab48b4c0887638a20cdaa75967b5ff2fe11100 100644 (file)
  */
 
 $(document).ready(function(){
+    $('input#notice_data-attach').toggle();
+    $('label[for=notice_data-attach]').text('Upload a file as an attachment?');
+    $('label[for=notice_data-attach]').click(function () {
+        if ('Upload a file as an attachment?' == $(this).text()) {
+            $(this).text('Upload: ');
+            $('input#notice_data-attach').slideDown('fast');
+        } else {
+            $('input#notice_data-attach').slideUp('fast', function() {$('label[for=notice_data-attach]').text('Upload a file as an attachment?');});
+        }
+    });
+
+    $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; });
+    $("a.thumbnail").hover(
+        function() {
+            var anchor = $(this);
+            $("a.thumbnail").children('img').remove();
+
+            setTimeout(function() {
+                anchor.closest(".entry-title").addClass('ov');
+                $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
+                    anchor.append(data);
+                });
+            }, 250);
+
+            setTimeout(function() {
+                anchor.children('img').remove();
+                anchor.closest(".entry-title").removeClass('ov');
+            }, 3000);
+        },
+        function() {
+            $(this).children('img').remove();
+            $(this).closest(".entry-title").removeClass('ov');
+        }
+    );
+
        // count character on keyup
        function counter(event){
                var maxLength = 140;
@@ -166,19 +201,45 @@ $(document).ready(function(){
                                                                                                                                                   $("#notice_action-submit").addClass("disabled");
                                                                                                                                                   return true;
                                                                                                                                                 },
-                                          success: function(xml) {     if ($("#error", xml).length > 0 || $("#command_result", xml).length > 0) {
+                                          timeout: '60000',
+                                          error: function (xhr, textStatus, errorThrown) {     $("#form_notice").removeClass("processing");
+                                                                                                                                               $("#notice_action-submit").removeAttr("disabled");
+                                                                                                                                               $("#notice_action-submit").removeClass("disabled");
+                                                                                                                                               if (textStatus == "timeout") {
+                                                                                                                                                       alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists");
+                                                                                                                                               }
+                                                                                                                                               else {
+                                                                                                                                                       if ($(".error", xhr.responseXML).length > 0) {
+                                                                                                                                                               $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true));
+                                                                                                                                                       }
+                                                                                                                                                       else {
+                                                                                                                                                               alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again.");
+                                                                                                                                                       }
+                                                                                                                                               }
+                                                                                                                                         },
+                                          success: function(xml) {     if ($("#error", xml).length > 0) {
                                                                                                        var result = document._importNode($("p", xml).get(0), true);
                                                                                                        result = result.textContent || result.innerHTML;
                                                                                                        alert(result);
                                                                                                }
                                                                                                else {
-                                                                                                       $("#notices_primary .notices").prepend(document._importNode($("li", xml).get(0), true));
+                                                                                                   if ($("#command_result", xml).length > 0) {
+                                                                                                           var result = document._importNode($("p", xml).get(0), true);
+                                                                                                           result = result.textContent || result.innerHTML;
+                                                                                                           alert(result);
+                                                    }
+                                                    else {
+                                                         li = $("li", xml).get(0);
+                                                         if ($("#"+li.id).length == 0) {
+                                                              $("#notices_primary .notices").prepend(document._importNode(li, true));
+                                                              $("#notices_primary .notice:first").css({display:"none"});
+                                                              $("#notices_primary .notice:first").fadeIn(2500);
+                                                              NoticeReply();
+                                                         }
+                                                                                                       }
                                                                                                        $("#notice_data-text").val("");
-                                                                                                       counter();
-                                                                                                       $("#notices_primary .notice:first").css({display:"none"});
-                                                                                                       $("#notices_primary .notice:first").fadeIn(2500);
-                                                                                                       NoticeHover();
-                                                                                                       NoticeReply();
+                                                                                               $("#notice_data-attach").val("");
+                                                    counter();
                                                                                                }
                                                                                                $("#form_notice").removeClass("processing");
                                                                                                $("#notice_action-submit").removeAttr("disabled");
@@ -187,29 +248,27 @@ $(document).ready(function(){
                                           };
        $("#form_notice").ajaxForm(PostNotice);
        $("#form_notice").each(addAjaxHidden);
-
     NoticeHover();
     NoticeReply();
 });
 
+
 function NoticeHover() {
-    $("#content .notice").hover(
-        function () {
-            $(this).addClass('hover');
-        },
-        function () {
-            $(this).removeClass('hover');
-        }
-    );
+    function mouseHandler(e) {
+        $(e.target).closest('li.hentry')[(e.type === 'mouseover') ? 'addClass' : 'removeClass']('hover');
+    };
+    $('#content .notices').mouseover(mouseHandler);
+    $('#content .notices').mouseout(mouseHandler);
 }
 
+
 function NoticeReply() {
     if ($('#notice_data-text').length > 0) {
         $('#content .notice').each(function() {
-            var notice = $(this);
-            $('.notice_reply', $(this)).click(function() {
-                var nickname = ($('.author .nickname', notice).length > 0) ? $('.author .nickname', notice) : $('.author .nickname');
-                NoticeReplySet(nickname.text(), $('.notice_id', notice).text());
+            var notice = $(this)[0];
+            $($('.notice_reply', notice)[0]).click(function() {
+                var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname');
+                NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
                 return false;
             });
         });