]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Shorten text after paste operation
authorCraig Andrews <candrews@integralblue.com>
Fri, 23 Apr 2010 16:13:46 +0000 (12:13 -0400)
committerCraig Andrews <candrews@integralblue.com>
Fri, 23 Apr 2010 16:14:55 +0000 (12:14 -0400)
Abort ajax shorten request if the user pastes/pushes another key

plugins/ClientSideShorten/shorten.js

index b3a6146339db29ff814a435c833a67d754ed8549..0db78eceaf82962f32edbdb3cc0ab93b5674f5b8 100644 (file)
 
     })(jQuery,'smartkeypress');
 
-    $(document).ready(function(){
-        $noticeDataText = $('#'+SN.C.S.NoticeDataText);
-        $noticeDataText.smartkeypress(function(e){
-            if(e.charCode == '32') {
-                shorten();
-            }
-        });
-        $noticeDataText.bind('paste', shorten);
-    });
-
     function shorten()
     {
         $noticeDataText = $('#'+SN.C.S.NoticeDataText);
         var original = $noticeDataText.val();
-        $.ajax({
+        shortenAjax = $.ajax({
             url: $('address .url')[0].href+'/plugins/ClientSideShorten/shorten',
             data: { text: $noticeDataText.val() },
             dataType: 'text',
             }
         });
     }
+
+    $(document).ready(function(){
+        $noticeDataText = $('#'+SN.C.S.NoticeDataText);
+        $noticeDataText.smartkeypress(function(e){
+            if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
+            if(e.charCode == '32') {
+                shorten();
+            }
+        });
+        $noticeDataText.bind('paste', function() {
+            if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
+            setTimeout(shorten,1);
+        });
+    });
+
 })();