]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/DirectionDetector/jquery.DirectionDetector.js
Merge branch '0.9.x' into twitstream
[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         $(document).ready(function(){
51                 var tArea = $("#notice_data-text");
52                 var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
53                 tArea.keyup(function(){
54                         var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
55                         if($().isRTL(cleaned))
56                                 tArea.css('direction', 'rtl');
57                         else
58                                 tArea.css('direction', 'ltr');
59                 });
60         });
61 })(jQuery);