4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 tinymce.create('tinymce.plugins.Directionality', {
13 init : function(ed, url) {
18 function setDir(dir) {
19 var dom = ed.dom, curDir, blocks = ed.selection.getSelectedBlocks();
22 curDir = dom.getAttrib(blocks[0], "dir");
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())) {
28 dom.setAttrib(block, "dir", dir);
30 dom.setAttrib(block, "dir", null);
39 ed.addCommand('mceDirectionLTR', function() {
43 ed.addCommand('mceDirectionRTL', function() {
47 ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'});
48 ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'});
50 ed.onNodeChange.add(t._nodeChange, t);
53 getInfo : function() {
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
65 _nodeChange : function(ed, cm, n) {
66 var dom = ed.dom, dir;
68 n = dom.getParent(n, dom.isBlock);
70 cm.setDisabled('ltr', 1);
71 cm.setDisabled('rtl', 1);
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);
84 tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality);