]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
TinyMCE: counter support (may not be 100% exact match to server-side count, but there...
authorBrion Vibber <brion@status.net>
Thu, 12 Aug 2010 19:47:07 +0000 (12:47 -0700)
committerBrion Vibber <brion@status.net>
Thu, 12 Aug 2010 19:47:07 +0000 (12:47 -0700)
Fix for bad char conversions also, caused short text to not be saved in some cases.

js/util.js
plugins/TinyMCE/TinyMCEPlugin.php

index 6a67da4bcd25ac82bac1cc13a1854b59dd1c0129..ad8a44c82ad5d9fa76fe47197bb30796d45a685f 100644 (file)
@@ -110,7 +110,7 @@ var SN = { // StatusNet
                 return;
             }
 
-            var remaining = MaxLength - form.find('#'+SN.C.S.NoticeDataText).val().length;
+            var remaining = MaxLength - SN.U.CharacterCount(form);
             var counter = form.find('#'+SN.C.S.NoticeTextCount);
 
             if (remaining.toString() != counter.text()) {
@@ -134,6 +134,10 @@ var SN = { // StatusNet
             }
         },
 
+        CharacterCount: function(form) {
+            return form.find('#'+SN.C.S.NoticeDataText).val().length;
+        },
+
         ClearCounterBlackout: function(form) {
             // Allow keyup events to poke the counter again
             SN.C.I.CounterBlackout = false;
index 47d3d059f2ddd7e0d9bf7b7263774e83edb0113e..ca16f60591de8ef42b7cc17a14a5bfb6a6648123 100644 (file)
@@ -102,7 +102,7 @@ class TinyMCEPlugin extends Plugin
      */
     private function stripHtml($html)
     {
-        return str_replace("\n", " ", html_entity_decode(strip_tags($html)));
+        return str_replace("\n", " ", html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8'));
     }
 
     /**
@@ -281,6 +281,7 @@ class TinyMCEPlugin extends Plugin
         // on our send button click.
         $scr = <<<END_OF_SCRIPT
         $().ready(function() {
+            var noticeForm = $('#form_notice');
             $('textarea#notice_data-text').tinymce({
                 script_url : '{$path}',
                 // General options
@@ -291,26 +292,29 @@ class TinyMCEPlugin extends Plugin
                 theme_advanced_buttons3 : "",
                 add_form_submit_trigger : false,
                 theme_advanced_resizing : true,
-                tabfocus_elements: ":prev,:next"
-            });
-            $('#form_notice').append('<input type="hidden" name="richedit" value="1">');
-            $('#notice_action-submit').click(function() {
-                if (typeof tinymce != "undefined") {
-                    tinymce.triggerSave();
-                }
-            });
-            $('#'+SN.C.S.NoticeDataAttach).change(function() {
-                /*
-                S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">&#215;</button></div>';
-                NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
-                if (NDAS.length > 0) {
-                    NDAS.replaceWith(S);
+                tabfocus_elements: ":prev,:next",
+                setup: function(ed) {
+                    noticeForm.append('<input type="hidden" name="richedit" value="1">');
+
+                    $('#notice_action-submit').click(function() {
+                        tinymce.triggerSave();
+                    });
+
+                    var origCounter = SN.U.CharacterCount;
+                    SN.U.CharacterCount = function(form) {
+                        var text = $(ed.getDoc()).text();
+                        return text.length;
+                    };
+                    ed.onKeyUp.add(function (ed, e) {
+                        SN.U.Counter(noticeForm);
+                    });
+
+                    $('#'+SN.C.S.NoticeDataAttach).change(function() {
+                        var img = '<img src="{$placeholder}" class="placeholder" width="320" height="240">';
+                        var html = tinyMCE.activeEditor.getContent();
+                        ed.setContent(html + img);
+                    });
                 }
-                */
-                //alert('yay');
-                var img = '<img src="{$placeholder}" class="placeholder" width="320" height="240">';
-                var html = tinyMCE.activeEditor.getContent();
-                tinyMCE.activeEditor.setContent(html + img);
             });
         });
 END_OF_SCRIPT;
@@ -319,4 +323,3 @@ END_OF_SCRIPT;
     }
 
 }
-