]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Only shorten when notice length exceeds max length
authorCraig Andrews <candrews@integralblue.com>
Mon, 26 Apr 2010 19:58:35 +0000 (15:58 -0400)
committerCraig Andrews <candrews@integralblue.com>
Mon, 26 Apr 2010 19:59:13 +0000 (15:59 -0400)
plugins/ClientSideShorten/ClientSideShortenPlugin.php
plugins/ClientSideShorten/shorten.js
plugins/ClientSideShorten/shorten.php

index 21763d5b7eec8a1513008296efc109f8e495ff9a..ba1f7d3a7c3338ca47f3bd4ff1d9b00f428233cd 100644 (file)
@@ -51,6 +51,7 @@ class ClientSideShortenPlugin extends Plugin
     }
 
     function onEndShowScripts($action){
+        $action->inlineScript('var Notice_maxContent = ' . Notice::maxContent());
         if (common_logged_in()) {
             $action->script('plugins/ClientSideShorten/shorten.js');
         }
index 0db78eceaf82962f32edbdb3cc0ab93b5674f5b8..856c7f05fded90757b83762388316a6442e4168e 100644 (file)
     function shorten()
     {
         $noticeDataText = $('#'+SN.C.S.NoticeDataText);
-        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();
+        if(Notice_maxContent > 0 && $noticeDataText.val().length > Notice_maxContent){
+            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(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
+            //if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
             if(e.charCode == '32') {
                 shorten();
             }
         });
         $noticeDataText.bind('paste', function() {
-            if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
+            //if(typeof(shortenAjax) !== 'undefined') shortenAjax.abort();
             setTimeout(shorten,1);
         });
     });
index 4905c62c2191600c7541231fd9572a7988acafc3..07c19e2e7c32aa56269bfd191e06f52fe5ac7a8c 100644 (file)
@@ -61,7 +61,7 @@ class ShortenAction extends Action
     {
         parent::handle($args);
         header('Content-Type: text/plain');
-        $shortened_text = common_shorten_links($this->text, true);
+        $shortened_text = common_shorten_links($this->text);
         print $shortened_text;
     }
 }