1 //wrap everything in a self-executing anonymous function to avoid conflicts
4 // smart(x) from Paul Irish
5 // http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
9 // debouncing function from John Hann
10 // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
11 var debounce = function (func, threshold, execAsap) {
14 return function debounced () {
15 var obj = this, args = arguments;
18 func.apply(obj, args);
23 clearTimeout(timeout);
25 func.apply(obj, args);
27 timeout = setTimeout(delayed, threshold || 100);
30 jQuery.fn[sr] = function(fn){ return fn ? this.bind('keypress', debounce(fn, 1000)) : this.trigger(sr); };
32 })(jQuery,'smartkeypress');
34 function longestWordInString(string)
36 var words = string.split(/\s/);
38 for(var i=0;i<words.length;i++)
39 if(words[i].length > longestWord) longestWord = words[i].length;
45 var $noticeDataText = $('#'+SN.C.S.NoticeDataText);
46 var noticeText = $noticeDataText.val();
48 if(noticeText.length > maxNoticeLength || longestWordInString(noticeText) > maxUrlLength) {
49 var original = $noticeDataText.val();
50 shortenAjax = $.ajax({
51 url: $('address .url')[0].href+'/plugins/ClientSideShorten/shorten',
52 data: { text: $noticeDataText.val() },
54 success: function(data) {
55 if(original == $noticeDataText.val()) {
56 $noticeDataText.val(data).keyup();
63 $(document).ready(function(){
64 $noticeDataText = $('#'+SN.C.S.NoticeDataText);
65 $noticeDataText.smartkeypress(function(e){
66 //if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
67 if(e.charCode == '32') {
71 $noticeDataText.bind('paste', function() {
72 //if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
73 setTimeout(shorten,1);