]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Update DirectionDetector for reusable notice forms.
authorBrion Vibber <brion@pobox.com>
Thu, 10 Mar 2011 02:11:08 +0000 (18:11 -0800)
committerBrion Vibber <brion@pobox.com>
Thu, 10 Mar 2011 02:11:08 +0000 (18:11 -0800)
Also tweaked it to trigger on cut/paste, and to reset when the form resets.

plugins/DirectionDetector/jquery.DirectionDetector.js

index 6808bcabd8e21b1899921cd02aee477de349b314..840cd690976c08f28fecfbb94ece6bfb573f33ac 100644 (file)
                        return true;
                return false;
        };
-       $(document).ready(function(){
-               var tArea = $("#notice_data-text");
-               var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
-               tArea.keyup(function(){
-                       var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
-                       if($().isRTL(cleaned))
-                               tArea.css('direction', 'rtl');
-                       else
-                               tArea.css('direction', 'ltr');
-               });
-       });
+    var origInit = SN.Init.NoticeFormSetup;
+    SN.Init.NoticeFormSetup = function(form) {
+        origInit(form);
+        var tArea = form.find(".notice_data-text:first");
+        if (tArea.length > 0) {
+            var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
+            var ping = function(){
+                var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
+                if($().isRTL(cleaned))
+                    tArea.css('direction', 'rtl');
+                else
+                    tArea.css('direction', 'ltr');
+            };
+            tArea.bind('keyup cut paste', function() {
+                // cut/paste trigger before the change
+                window.setTimeout(ping, 0);
+            });
+            form.bind('reset', function() {
+                tArea.css('direction', 'ltr');
+            });
+        }
+    };
 })(jQuery);