]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / js / util.js
index 1e6dc725117cf5c3e3247a1bcc5ec31acaaf67d4..4f731f30a1e62aa6e9d0b6001f2aa62cc889072c 100644 (file)
  */
 
 $(document).ready(function(){
+       var counterBlackout = false;
+       
        // count character on keyup
        function counter(event){
-               var maxLength = 140;
+         if (maxLength <= 0) {
+              return;
+         }
                var currentLength = $("#notice_data-text").val().length;
                var remaining = maxLength - currentLength;
                var counter = $("#notice_text-count");
-               counter.text(remaining);
+               
+               if (remaining.toString() != counter.text()) {
+                   if (!counterBlackout || remaining == 0) {
+                        if (counter.text() != String(remaining)) {
+                            counter.text(remaining);
+                       }
 
-               if (remaining <= 0) {
-                       $("#form_notice").addClass("warning");
-               } else {
-                       $("#form_notice").removeClass("warning");
-               }
+                        if (remaining < 0) {
+                            $("#form_notice").addClass("warning");
+                        } else {
+                            $("#form_notice").removeClass("warning");
+                        }
+                        // Skip updates for the next 500ms.
+                        // On slower hardware, updating on every keypress is unpleasant.
+                        if (!counterBlackout) {
+                            counterBlackout = true;
+                            window.setTimeout(clearCounterBlackout, 500);
+                        }
+                    }
+                }
+       }
+       
+       function clearCounterBlackout() {
+               // Allow keyup events to poke the counter again
+               counterBlackout = false;
+               // Check if the string changed since we last looked
+               counter(null);
        }
 
        function submitonreturn(event) {
-               if (event.keyCode == 13) {
+               if (event.keyCode == 13 || event.keyCode == 10) {
+                       // iPhone sends \n not \r for 'return'
                        $("#form_notice").submit();
                        event.preventDefault();
                        event.stopPropagation();
+                       $("#notice_data-text").blur();
+                       $("body").focus();
                        return false;
                }
                return true;
        }
 
+     // define maxLength if it wasn't defined already
+
+    if (typeof(maxLength) == "undefined") {
+         maxLength = 140;
+    }
+
        if ($("#notice_data-text").length) {
-               $("#notice_data-text").bind("keyup", counter);
-               $("#notice_data-text").bind("keydown", submitonreturn);
+         if (maxLength > 0) {
+              $("#notice_data-text").bind("keyup", counter);
+              // run once in case there's something in there
+              counter();
+         }
 
-               // run once in case there's something in there
-               counter();
+               $("#notice_data-text").bind("keydown", submitonreturn);
 
-               // set the focus
-               $("#notice_data-text").focus();
+        if($('body')[0].id != 'conversation') {
+            $("#notice_data-text").focus();
+        }
        }
 
        // XXX: refactor this code
 
        var favoptions = { dataType: 'xml',
+                                          beforeSubmit: function(data, target, options) {
+                                                                                               $(target).addClass('processing');
+                                                                                               return true;
+                                                                                         },
                                           success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
                                                                                                var dis = new_form.id;
                                                                                                var fav = dis.replace('disfavor', 'favor');
@@ -65,6 +105,10 @@ $(document).ready(function(){
                                         };
 
        var disoptions = { dataType: 'xml',
+                                          beforeSubmit: function(data, target, options) {
+                                                                                               $(target).addClass('processing');
+                                                                                               return true;
+                                                                                         },
                                           success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
                                                                                                var fav = new_form.id;
                                                                                                var dis = fav.replace('favor', 'disfavor');
@@ -184,7 +228,9 @@ $(document).ready(function(){
                                                                                                                                                                }
                                                                                                                                                                else {
                                                                                                                                                                        $("#notice_data-text").val("");
-                                                                                                                                                                       counter();
+                                                                                     if (maxLength > 0) {
+                                                                                          counter();
+                                                                                     }
                                                                                                                                                                }
                                                                                                                                                        }
                                                                                                                                                }
@@ -222,8 +268,11 @@ $(document).ready(function(){
                                                                                                        }
                                                                                                        $("#notice_data-text").val("");
                                                                                                $("#notice_data-attach").val("");
+                                                                                               $("#notice_in-reply-to").val("");
                                                     $('#notice_data-attach_selected').remove();
-                                                    counter();
+                                                     if (maxLength > 0) {
+                                                          counter();
+                                                     }
                                                                                                }
                                                                                                $("#form_notice").removeClass("processing");
                                                                                                $("#notice_action-submit").removeAttr("disabled");
@@ -242,7 +291,7 @@ function NoticeReply() {
         $('#content .notice').each(function() {
             var notice = $(this)[0];
             $($('.notice_reply', notice)[0]).click(function() {
-                var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname');
+                var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
                 NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
                 return false;
             });
@@ -253,11 +302,16 @@ function NoticeReply() {
 function NoticeReplySet(nick,id) {
        rgx_username = /^[0-9a-zA-Z\-_.]*$/;
        if (nick.match(rgx_username)) {
-               replyto = "@" + nick + " ";
-               if ($("#notice_data-text").length) {
-                       $("#notice_data-text").val(replyto);
+               var text = $("#notice_data-text");
+               if (text.length) {
+                       replyto = "@" + nick + " ";
+                       text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
                        $("#form_notice input#notice_in-reply-to").val(id);
-                       $("#notice_data-text").focus();
+                       if (text.get(0).setSelectionRange) {
+                               var len = text.val().length;
+                               text.get(0).setSelectionRange(len,len);
+                               text.get(0).focus();
+                       }
                        return false;
                }
        }
@@ -272,7 +326,7 @@ function NoticeAttachments() {
         color : '#000',
         opacity : '0.6',
         zIndex : 99,
-        center : true,
+        center : false,
         imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
         bgClickToClose : true,
         success : function() {
@@ -281,14 +335,14 @@ function NoticeAttachments() {
         },
         timeout : 0,
         autoHide : true,
-        css : {'max-width':'502px'}
+        css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
     };
 
     $('#content .notice a.attachment').click(function() {
-        $().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
+        $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
         return false;
     });
-    
+
     var t;
     $("body:not(#shownotice) #content .notice a.thumbnail").hover(
         function() {
@@ -298,7 +352,7 @@ function NoticeAttachments() {
 
             if (anchor.children('img').length == 0) {
                 t = setTimeout(function() {
-                    $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
+                    $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
                         anchor.append(data);
                     });
                 }, 500);