]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/directionality/editor_plugin_src.js
Wordpress 3.5
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / directionality / editor_plugin_src.js
1 /**
2  * editor_plugin_src.js
3  *
4  * Copyright 2009, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://tinymce.moxiecode.com/license
8  * Contributing: http://tinymce.moxiecode.com/contributing
9  */
10
11 (function() {
12         tinymce.create('tinymce.plugins.Directionality', {
13                 init : function(ed, url) {
14                         var t = this;
15
16                         t.editor = ed;
17
18                         function setDir(dir) {
19                                 var dom = ed.dom, curDir, blocks = ed.selection.getSelectedBlocks();
20
21                                 if (blocks.length) {
22                                         curDir = dom.getAttrib(blocks[0], "dir");
23
24                                         tinymce.each(blocks, function(block) {
25                                                 // Add dir to block if the parent block doesn't already have that dir
26                                                 if (!dom.getParent(block.parentNode, "*[dir='" + dir + "']", dom.getRoot())) {
27                                                         if (curDir != dir) {
28                                                                 dom.setAttrib(block, "dir", dir);
29                                                         } else {
30                                                                 dom.setAttrib(block, "dir", null);
31                                                         }
32                                                 }
33                                         });
34
35                                         ed.nodeChanged();
36                                 }
37                         }
38
39                         ed.addCommand('mceDirectionLTR', function() {
40                                 setDir("ltr");
41                         });
42
43                         ed.addCommand('mceDirectionRTL', function() {
44                                 setDir("rtl");
45                         });
46
47                         ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'});
48                         ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'});
49
50                         ed.onNodeChange.add(t._nodeChange, t);
51                 },
52
53                 getInfo : function() {
54                         return {
55                                 longname : 'Directionality',
56                                 author : 'Moxiecode Systems AB',
57                                 authorurl : 'http://tinymce.moxiecode.com',
58                                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
59                                 version : tinymce.majorVersion + "." + tinymce.minorVersion
60                         };
61                 },
62
63                 // Private methods
64
65                 _nodeChange : function(ed, cm, n) {
66                         var dom = ed.dom, dir;
67
68                         n = dom.getParent(n, dom.isBlock);
69                         if (!n) {
70                                 cm.setDisabled('ltr', 1);
71                                 cm.setDisabled('rtl', 1);
72                                 return;
73                         }
74
75                         dir = dom.getAttrib(n, 'dir');
76                         cm.setActive('ltr', dir == "ltr");
77                         cm.setDisabled('ltr', 0);
78                         cm.setActive('rtl', dir == "rtl");
79                         cm.setDisabled('rtl', 0);
80                 }
81         });
82
83         // Register plugin
84         tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality);
85 })();