nouveau style menu_top
[mtweb] / mw / libs / tiny_mce / plugins / directionality / editor_plugin_src.js
1 /**\r
2  * editor_plugin_src.js\r
3  *\r
4  * Copyright 2009, Moxiecode Systems AB\r
5  * Released under LGPL License.\r
6  *\r
7  * License: http://tinymce.moxiecode.com/license\r
8  * Contributing: http://tinymce.moxiecode.com/contributing\r
9  */\r
10 \r
11 (function() {\r
12         tinymce.create('tinymce.plugins.Directionality', {\r
13                 init : function(ed, url) {\r
14                         var t = this;\r
15 \r
16                         t.editor = ed;\r
17 \r
18                         ed.addCommand('mceDirectionLTR', function() {\r
19                                 var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock);\r
20 \r
21                                 if (e) {\r
22                                         if (ed.dom.getAttrib(e, "dir") != "ltr")\r
23                                                 ed.dom.setAttrib(e, "dir", "ltr");\r
24                                         else\r
25                                                 ed.dom.setAttrib(e, "dir", "");\r
26                                 }\r
27 \r
28                                 ed.nodeChanged();\r
29                         });\r
30 \r
31                         ed.addCommand('mceDirectionRTL', function() {\r
32                                 var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock);\r
33 \r
34                                 if (e) {\r
35                                         if (ed.dom.getAttrib(e, "dir") != "rtl")\r
36                                                 ed.dom.setAttrib(e, "dir", "rtl");\r
37                                         else\r
38                                                 ed.dom.setAttrib(e, "dir", "");\r
39                                 }\r
40 \r
41                                 ed.nodeChanged();\r
42                         });\r
43 \r
44                         ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'});\r
45                         ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'});\r
46 \r
47                         ed.onNodeChange.add(t._nodeChange, t);\r
48                 },\r
49 \r
50                 getInfo : function() {\r
51                         return {\r
52                                 longname : 'Directionality',\r
53                                 author : 'Moxiecode Systems AB',\r
54                                 authorurl : 'http://tinymce.moxiecode.com',\r
55                                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',\r
56                                 version : tinymce.majorVersion + "." + tinymce.minorVersion\r
57                         };\r
58                 },\r
59 \r
60                 // Private methods\r
61 \r
62                 _nodeChange : function(ed, cm, n) {\r
63                         var dom = ed.dom, dir;\r
64 \r
65                         n = dom.getParent(n, dom.isBlock);\r
66                         if (!n) {\r
67                                 cm.setDisabled('ltr', 1);\r
68                                 cm.setDisabled('rtl', 1);\r
69                                 return;\r
70                         }\r
71 \r
72                         dir = dom.getAttrib(n, 'dir');\r
73                         cm.setActive('ltr', dir == "ltr");\r
74                         cm.setDisabled('ltr', 0);\r
75                         cm.setActive('rtl', dir == "rtl");\r
76                         cm.setDisabled('rtl', 0);\r
77                 }\r
78         });\r
79 \r
80         // Register plugin\r
81         tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality);\r
82 })();