]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
add a method to Design to show custom CSS
[quix0rs-gnu-social.git] / js / util.js
index 6ca5f8cbca5d5879aa359aeac24110a6b51f58bb..31d9eb4f54706a09a384ca2cf0604ae7904373ef 100644 (file)
  */
 
 $(document).ready(function(){
+    $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; });
+        }, url:$(this).attr('href') + '/ajax'}); return false; });
+    $('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; });
+
        // count character on keyup
        function counter(event){
                var maxLength = 140;
@@ -161,40 +165,60 @@ $(document).ready(function(){
                                                                                                                                                                $("#form_notice").addClass("warning");
                                                                                                                                                                return false;
                                                                                                                                                   }
+                                                                                                                                                  $("#form_notice").addClass("processing");
                                                                                                                                                   $("#notice_action-submit").attr("disabled", "disabled");
                                                                                                                                                   $("#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);
+                                                              NoticeHover();
+                                                              NoticeReply();
+                                                         }
+                                                                                                       }
                                                                                                        $("#notice_data-text").val("");
-                                                                                                       counter();
-                                                                                                       $("#notices_primary .notice:first").css({display:"none"});
-                                                                                                       $("#notices_primary .notice:first").fadeIn(2500);
-                                                                                                       NoticeHover();
+                                                    counter();
                                                                                                }
+                                                                                               $("#form_notice").removeClass("processing");
                                                                                                $("#notice_action-submit").removeAttr("disabled");
                                                                                                $("#notice_action-submit").removeClass("disabled");
                                                                                         }
                                           };
        $("#form_notice").ajaxForm(PostNotice);
        $("#form_notice").each(addAjaxHidden);
-
     NoticeHover();
-
-    $('#content .notice').each(function() {
-        var notice = $(this);
-        $('.notice_reply', $(this)).click(function() {
-            var nickname = ($('.author .nickname', notice).length > 0) ? $('.author .nickname', notice) : $('.author .nickname');
-            NoticeReply(nickname.text(), $('.notice_id', notice).text());
-            return false;
-        });
-    });
+    NoticeReply();
 });
 
 function NoticeHover() {
@@ -208,7 +232,20 @@ function NoticeHover() {
     );
 }
 
-function NoticeReply(nick,id) {
+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());
+                return false;
+            });
+        });
+    }
+}
+
+function NoticeReplySet(nick,id) {
        rgx_username = /^[0-9a-zA-Z\-_.]*$/;
        if (nick.match(rgx_username)) {
                replyto = "@" + nick + " ";