1 // smart(x) from Paul Irish
2 // http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
6 // debouncing function from John Hann
7 // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
8 var debounce = function (func, threshold, execAsap) {
11 return function debounced () {
12 var obj = this, args = arguments;
15 func.apply(obj, args);
20 clearTimeout(timeout);
22 func.apply(obj, args);
24 timeout = setTimeout(delayed, threshold || 100);
27 jQuery.fn[sr] = function(fn){ return fn ? this.bind('keypress', debounce(fn, 1000)) : this.trigger(sr); };
29 })(jQuery,'smartkeypress');
31 $(document).ready(function(){
32 $('#notice_data-text').smartkeypress(function(e){
33 var original = $('#notice_data-text').val();
35 url: $('address .url')[0].href+'/plugins/ClientSideShorten/shorten',
36 data: { text: $('#notice_data-text').val() },
38 success: function(data) {
39 if(original == $('#notice_data-text').val()) {
40 $('#notice_data-text').val(data);
41 $('#notice_data-text').keyup();