1 /** |
1 /** |
2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ |
2 * $Id: editor_plugin_src.js 372 2007-11-11 18:38:50Z spocke $ |
3 * |
3 * |
4 * @author Moxiecode |
4 * @author Moxiecode |
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. |
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. |
6 */ |
6 */ |
7 |
7 |
8 /* Import plugin specific language pack */ |
8 (function() { |
9 tinyMCE.importPluginLanguagePack('directionality'); |
9 tinymce.create('tinymce.plugins.Directionality', { |
|
10 init : function(ed, url) { |
|
11 var t = this; |
10 |
12 |
11 var TinyMCE_DirectionalityPlugin = { |
13 t.editor = ed; |
12 getInfo : function() { |
|
13 return { |
|
14 longname : 'Directionality', |
|
15 author : 'Moxiecode Systems AB', |
|
16 authorurl : 'http://tinymce.moxiecode.com', |
|
17 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality', |
|
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion |
|
19 }; |
|
20 }, |
|
21 |
14 |
22 getControlHTML : function(cn) { |
15 ed.addCommand('mceDirectionLTR', function() { |
23 switch (cn) { |
16 var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock); |
24 case "ltr": |
|
25 return tinyMCE.getButtonHTML(cn, 'lang_directionality_ltr_desc', '{$pluginurl}/images/ltr.gif', 'mceDirectionLTR'); |
|
26 |
17 |
27 case "rtl": |
18 if (e) { |
28 return tinyMCE.getButtonHTML(cn, 'lang_directionality_rtl_desc', '{$pluginurl}/images/rtl.gif', 'mceDirectionRTL'); |
19 if (ed.dom.getAttrib(e, "dir") != "ltr") |
|
20 ed.dom.setAttrib(e, "dir", "ltr"); |
|
21 else |
|
22 ed.dom.setAttrib(e, "dir", ""); |
|
23 } |
|
24 |
|
25 ed.nodeChanged(); |
|
26 }); |
|
27 |
|
28 ed.addCommand('mceDirectionRTL', function() { |
|
29 var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock); |
|
30 |
|
31 if (e) { |
|
32 if (ed.dom.getAttrib(e, "dir") != "rtl") |
|
33 ed.dom.setAttrib(e, "dir", "rtl"); |
|
34 else |
|
35 ed.dom.setAttrib(e, "dir", ""); |
|
36 } |
|
37 |
|
38 ed.nodeChanged(); |
|
39 }); |
|
40 |
|
41 ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'}); |
|
42 ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'}); |
|
43 |
|
44 ed.onNodeChange.add(t._nodeChange, t); |
|
45 }, |
|
46 |
|
47 getInfo : function() { |
|
48 return { |
|
49 longname : 'Directionality', |
|
50 author : 'Moxiecode Systems AB', |
|
51 authorurl : 'http://tinymce.moxiecode.com', |
|
52 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality', |
|
53 version : tinymce.majorVersion + "." + tinymce.minorVersion |
|
54 }; |
|
55 }, |
|
56 |
|
57 // Private methods |
|
58 |
|
59 _nodeChange : function(ed, cm, n) { |
|
60 var dom = ed.dom, dir; |
|
61 |
|
62 n = dom.getParent(n, dom.isBlock); |
|
63 if (!n) { |
|
64 cm.setDisabled('ltr', 1); |
|
65 cm.setDisabled('rtl', 1); |
|
66 return; |
|
67 } |
|
68 |
|
69 dir = dom.getAttrib(n, 'dir'); |
|
70 cm.setActive('ltr', dir == "ltr"); |
|
71 cm.setDisabled('ltr', 0); |
|
72 cm.setActive('rtl', dir == "rtl"); |
|
73 cm.setDisabled('rtl', 0); |
29 } |
74 } |
|
75 }); |
30 |
76 |
31 return ""; |
77 // Register plugin |
32 }, |
78 tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality); |
33 |
79 })(); |
34 execCommand : function(editor_id, element, command, user_interface, value) { |
|
35 // Handle commands |
|
36 switch (command) { |
|
37 case "mceDirectionLTR": |
|
38 var inst = tinyMCE.getInstanceById(editor_id); |
|
39 var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address"); |
|
40 |
|
41 if (elm) |
|
42 elm.setAttribute("dir", "ltr"); |
|
43 |
|
44 tinyMCE.triggerNodeChange(false); |
|
45 return true; |
|
46 |
|
47 case "mceDirectionRTL": |
|
48 var inst = tinyMCE.getInstanceById(editor_id); |
|
49 var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address"); |
|
50 |
|
51 if (elm) |
|
52 elm.setAttribute("dir", "rtl"); |
|
53 |
|
54 tinyMCE.triggerNodeChange(false); |
|
55 return true; |
|
56 } |
|
57 |
|
58 // Pass to next handler in chain |
|
59 return false; |
|
60 }, |
|
61 |
|
62 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { |
|
63 function getAttrib(elm, name) { |
|
64 return elm.getAttribute(name) ? elm.getAttribute(name) : ""; |
|
65 } |
|
66 |
|
67 if (node == null) |
|
68 return; |
|
69 |
|
70 var elm = tinyMCE.getParentElement(node, "p,div,td,h1,h2,h3,h4,h5,h6,pre,address"); |
|
71 if (!elm) { |
|
72 tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonDisabled'); |
|
73 tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonDisabled'); |
|
74 return true; |
|
75 } |
|
76 |
|
77 tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonNormal'); |
|
78 tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonNormal'); |
|
79 |
|
80 var dir = getAttrib(elm, "dir"); |
|
81 if (dir == "ltr" || dir == "") |
|
82 tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonSelected'); |
|
83 else |
|
84 tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonSelected'); |
|
85 |
|
86 return true; |
|
87 } |
|
88 }; |
|
89 |
|
90 tinyMCE.addPlugin("directionality", TinyMCE_DirectionalityPlugin); |
|