]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/DirectionDetector/jquery.DirectionDetector.js
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / DirectionDetector / jquery.DirectionDetector.js
1
2 /**
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
16  *
17  * @category     Plugin
18  * @package      StatusNet
19  * @author               Behrooz shabani (everplays) - <behrooz@rock.com>
20  * @copyright    2009-2010 Behrooz shabani
21  * @license      http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
22  *
23  */
24
25 (function($){
26         $.fn.isRTL = function(str){
27                 if(typeof str != typeof "" || str.length<1)
28                         return false;
29                 var cc = str.charCodeAt(0);
30                 if(cc>=1536 && cc<=1791) // arabic, persian, ...
31                         return true;
32                 if(cc>=65136 && cc<=65279) // arabic peresent 2
33                         return true;
34                 if(cc>=64336 && cc<=65023) // arabic peresent 1
35                         return true;
36                 if(cc>=1424 && cc<=1535) // hebrew
37                         return true;
38                 if(cc>=64256 && cc<=64335) // hebrew peresent
39                         return true;
40                 if(cc>=1792 && cc<=1871) // Syriac
41                         return true;
42                 if(cc>=1920 && cc<=1983) // Thaana
43                         return true;
44                 if(cc>=1984 && cc<=2047) // NKo
45                         return true;
46                 if(cc>=11568 && cc<=11647) // Tifinagh
47                         return true;
48                 return false;
49         };
50     var origInit = SN.Init.NoticeFormSetup;
51     SN.Init.NoticeFormSetup = function(form) {
52         origInit(form);
53         var tArea = form.find(".notice_data-text:first");
54         if (tArea.length > 0) {
55             var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
56             var ping = function(){
57                 var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
58                 if($().isRTL(cleaned))
59                     tArea.css('direction', 'rtl');
60                 else
61                     tArea.css('direction', 'ltr');
62             };
63             tArea.bind('keyup cut paste', function() {
64                 // cut/paste trigger before the change
65                 window.setTimeout(ping, 0);
66             });
67             form.bind('reset', function() {
68                 tArea.css('direction', 'ltr');
69             });
70         }
71     };
72 })(jQuery);