123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- (function(){
-
-
- (function($,sr){
-
-
- 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)
- func.apply(obj, args);
- timeout = setTimeout(delayed, threshold || 100);
- };
- }
- jQuery.fn[sr] = function(fn){ return fn ? this.bind('keypress', debounce(fn, 1000)) : this.trigger(sr); };
- })(jQuery,'smartkeypress');
- function longestWordInString(string)
- {
- var words = string.split(/\s/);
- var longestWord = 0;
- for(var i=0;i<words.length;i++)
- if(words[i].length > longestWord) longestWord = words[i].length;
- return longestWord;
- }
- function shorten()
- {
- var $noticeDataText = $('#'+SN.C.S.NoticeDataText);
- var noticeText = $noticeDataText.val();
- if(noticeText.length > maxNoticeLength || longestWordInString(noticeText) > maxUrlLength) {
- var original = $noticeDataText.val();
- shortenAjax = $.ajax({
- url: $('address .url')[0].href+'/plugins/ClientSideShorten/shorten',
- data: { text: $noticeDataText.val() },
- dataType: 'text',
- success: function(data) {
- if(original == $noticeDataText.val()) {
- $noticeDataText.val(data).keyup();
- }
- }
- });
- }
- }
- $(document).ready(function(){
- $noticeDataText = $('#'+SN.C.S.NoticeDataText);
- $noticeDataText.smartkeypress(function(e){
-
- if(e.charCode == '32') {
- shorten();
- }
- });
- $noticeDataText.bind('paste', function() {
-
- setTimeout(shorten,1);
- });
- });
- })();
|