From: Craig Andrews Date: Fri, 23 Apr 2010 16:13:46 +0000 (-0400) Subject: Shorten text after paste operation X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1de8877cad94e1f9252b1f6ccdea57ff3339c367;p=quix0rs-gnu-social.git Shorten text after paste operation Abort ajax shorten request if the user pastes/pushes another key --- diff --git a/plugins/ClientSideShorten/shorten.js b/plugins/ClientSideShorten/shorten.js index b3a6146339..0db78eceaf 100644 --- a/plugins/ClientSideShorten/shorten.js +++ b/plugins/ClientSideShorten/shorten.js @@ -31,21 +31,11 @@ })(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', @@ -56,4 +46,19 @@ } }); } + + $(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); + }); + }); + })();