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