4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
11 /*global tinymce:true */
13 tinymce.PluginManager.add('directionality', function(editor) {
14 function setDir(dir) {
15 var dom = editor.dom, curDir, blocks = editor.selection.getSelectedBlocks();
18 curDir = dom.getAttrib(blocks[0], "dir");
20 tinymce.each(blocks, function(block) {
21 // Add dir to block if the parent block doesn't already have that dir
22 if (!dom.getParent(block.parentNode, "*[dir='" + dir + "']", dom.getRoot())) {
24 dom.setAttrib(block, "dir", dir);
26 dom.setAttrib(block, "dir", null);
35 function generateSelector(dir) {
38 tinymce.each('h1 h2 h3 h4 h5 h6 div p'.split(' '), function(name) {
39 selector.push(name + '[dir=' + dir + ']');
42 return selector.join(',');
45 editor.addCommand('mceDirectionLTR', function() {
49 editor.addCommand('mceDirectionRTL', function() {
53 editor.addButton('ltr', {
54 title: 'Left to right',
55 cmd: 'mceDirectionLTR',
56 stateSelector: generateSelector('ltr')
59 editor.addButton('rtl', {
60 title: 'Right to left',
61 cmd: 'mceDirectionRTL',
62 stateSelector: generateSelector('rtl')