2010-04-22 22:57:57 +01:00
|
|
|
//wrap everything in a self-executing anonymous function to avoid conflicts
|
|
|
|
(function(){
|
2010-04-21 22:14:54 +01:00
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
// smart(x) from Paul Irish
|
|
|
|
// http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
|
2010-04-21 22:14:54 +01:00
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
(function($,sr){
|
2010-04-21 22:14:54 +01:00
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
// debouncing function from John Hann
|
|
|
|
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
|
|
|
|
var debounce = function (func, threshold, execAsap) {
|
|
|
|
var timeout;
|
|
|
|
|
|
|
|
return function debounced () {
|
|
|
|
var obj = this, args = arguments;
|
|
|
|
function delayed () {
|
|
|
|
if (!execAsap)
|
|
|
|
func.apply(obj, args);
|
|
|
|
timeout = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
clearTimeout(timeout);
|
|
|
|
else if (execAsap)
|
2010-04-21 22:14:54 +01:00
|
|
|
func.apply(obj, args);
|
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
timeout = setTimeout(delayed, threshold || 100);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
jQuery.fn[sr] = function(fn){ return fn ? this.bind('keypress', debounce(fn, 1000)) : this.trigger(sr); };
|
2010-04-21 22:14:54 +01:00
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
})(jQuery,'smartkeypress');
|
2010-04-21 22:14:54 +01:00
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
function shorten()
|
|
|
|
{
|
|
|
|
$noticeDataText = $('#'+SN.C.S.NoticeDataText);
|
|
|
|
var original = $noticeDataText.val();
|
2010-04-23 17:13:46 +01:00
|
|
|
shortenAjax = $.ajax({
|
2010-04-21 22:14:54 +01:00
|
|
|
url: $('address .url')[0].href+'/plugins/ClientSideShorten/shorten',
|
2010-04-22 22:57:57 +01:00
|
|
|
data: { text: $noticeDataText.val() },
|
2010-04-21 22:14:54 +01:00
|
|
|
dataType: 'text',
|
|
|
|
success: function(data) {
|
2010-04-22 22:57:57 +01:00
|
|
|
if(original == $noticeDataText.val()) {
|
|
|
|
$noticeDataText.val(data).keyup();
|
2010-04-21 22:14:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2010-04-22 22:57:57 +01:00
|
|
|
}
|
2010-04-23 17:13:46 +01:00
|
|
|
|
|
|
|
$(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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-04-22 22:57:57 +01:00
|
|
|
})();
|