1 /** |
1 /** |
2 * $Id: editor_plugin_src.js 42 2006-08-08 14:32:24Z spocke $ |
2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ |
3 * |
3 * |
4 * @author Moxiecode - based on work by Andrew Tetlaw |
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('xhtmlxtras'); |
9 tinymce.create('tinymce.plugins.XHTMLXtrasPlugin', { |
|
10 init : function(ed, url) { |
|
11 // Register commands |
|
12 ed.addCommand('mceCite', function() { |
|
13 ed.windowManager.open({ |
|
14 file : url + '/cite.htm', |
|
15 width : 350 + ed.getLang('xhtmlxtras.cite_delta_width', 0), |
|
16 height : 250 + ed.getLang('xhtmlxtras.cite_delta_height', 0), |
|
17 inline : 1 |
|
18 }, { |
|
19 plugin_url : url |
|
20 }); |
|
21 }); |
10 |
22 |
11 var TinyMCE_XHTMLXtrasPlugin = { |
23 ed.addCommand('mceAcronym', function() { |
12 getInfo : function() { |
24 ed.windowManager.open({ |
13 return { |
25 file : url + '/acronym.htm', |
14 longname : 'XHTML Xtras Plugin', |
26 width : 350 + ed.getLang('xhtmlxtras.acronym_delta_width', 0), |
15 author : 'Moxiecode Systems AB', |
27 height : 250 + ed.getLang('xhtmlxtras.acronym_delta_width', 0), |
16 authorurl : 'http://tinymce.moxiecode.com', |
28 inline : 1 |
17 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/xhtmlxtras', |
29 }, { |
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion |
30 plugin_url : url |
19 }; |
31 }); |
20 }, |
32 }); |
21 |
33 |
22 initInstance : function(inst) { |
34 ed.addCommand('mceAbbr', function() { |
23 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/xhtmlxtras/css/xhtmlxtras.css"); |
35 ed.windowManager.open({ |
24 }, |
36 file : url + '/abbr.htm', |
|
37 width : 350 + ed.getLang('xhtmlxtras.abbr_delta_width', 0), |
|
38 height : 250 + ed.getLang('xhtmlxtras.abbr_delta_width', 0), |
|
39 inline : 1 |
|
40 }, { |
|
41 plugin_url : url |
|
42 }); |
|
43 }); |
25 |
44 |
26 getControlHTML : function(cn) { |
45 ed.addCommand('mceDel', function() { |
27 switch (cn) { |
46 ed.windowManager.open({ |
28 case "cite": |
47 file : url + '/del.htm', |
29 return tinyMCE.getButtonHTML(cn, 'lang_xhtmlxtras_cite_desc', '{$pluginurl}/images/cite.gif', 'mceCite', true); |
48 width : 340 + ed.getLang('xhtmlxtras.del_delta_width', 0), |
|
49 height : 310 + ed.getLang('xhtmlxtras.del_delta_width', 0), |
|
50 inline : 1 |
|
51 }, { |
|
52 plugin_url : url |
|
53 }); |
|
54 }); |
30 |
55 |
31 case "acronym": |
56 ed.addCommand('mceIns', function() { |
32 return tinyMCE.getButtonHTML(cn, 'lang_xhtmlxtras_acronym_desc', '{$pluginurl}/images/acronym.gif', 'mceAcronym', true); |
57 ed.windowManager.open({ |
|
58 file : url + '/ins.htm', |
|
59 width : 340 + ed.getLang('xhtmlxtras.ins_delta_width', 0), |
|
60 height : 310 + ed.getLang('xhtmlxtras.ins_delta_width', 0), |
|
61 inline : 1 |
|
62 }, { |
|
63 plugin_url : url |
|
64 }); |
|
65 }); |
33 |
66 |
34 case "abbr": |
67 ed.addCommand('mceAttributes', function() { |
35 return tinyMCE.getButtonHTML(cn, 'lang_xhtmlxtras_abbr_desc', '{$pluginurl}/images/abbr.gif', 'mceAbbr', true); |
68 ed.windowManager.open({ |
|
69 file : url + '/attributes.htm', |
|
70 width : 380, |
|
71 height : 370, |
|
72 inline : 1 |
|
73 }, { |
|
74 plugin_url : url |
|
75 }); |
|
76 }); |
36 |
77 |
37 case "del": |
78 // Register buttons |
38 return tinyMCE.getButtonHTML(cn, 'lang_xhtmlxtras_del_desc', '{$pluginurl}/images/del.gif', 'mceDel', true); |
79 ed.addButton('cite', {title : 'xhtmlxtras.cite_desc', cmd : 'mceCite'}); |
|
80 ed.addButton('acronym', {title : 'xhtmlxtras.acronym_desc', cmd : 'mceAcronym'}); |
|
81 ed.addButton('abbr', {title : 'xhtmlxtras.abbr_desc', cmd : 'mceAbbr'}); |
|
82 ed.addButton('del', {title : 'xhtmlxtras.del_desc', cmd : 'mceDel'}); |
|
83 ed.addButton('ins', {title : 'xhtmlxtras.ins_desc', cmd : 'mceIns'}); |
|
84 ed.addButton('attribs', {title : 'xhtmlxtras.attribs_desc', cmd : 'mceAttributes'}); |
39 |
85 |
40 case "ins": |
86 if (tinymce.isIE) { |
41 return tinyMCE.getButtonHTML(cn, 'lang_xhtmlxtras_ins_desc', '{$pluginurl}/images/ins.gif', 'mceIns', true); |
87 function fix(ed, o) { |
|
88 if (o.set) { |
|
89 o.content = o.content.replace(/<abbr([^>]+)>/gi, '<mce:abbr $1>'); |
|
90 o.content = o.content.replace(/<\/abbr>/gi, '</mce:abbr>'); |
|
91 } |
|
92 }; |
42 |
93 |
43 case "attribs": |
94 ed.onBeforeSetContent.add(fix); |
44 return tinyMCE.getButtonHTML(cn, 'lang_xhtmlxtras_attribs_desc', '{$pluginurl}/images/attribs.gif', 'mceAttributes', true); |
95 ed.onPostProcess.add(fix); |
|
96 } |
|
97 |
|
98 ed.onNodeChange.add(function(ed, cm, n, co) { |
|
99 n = ed.dom.getParent(n, 'CITE,ACRONYM,ABBR,DEL,INS'); |
|
100 |
|
101 cm.setDisabled('cite', co); |
|
102 cm.setDisabled('acronym', co); |
|
103 cm.setDisabled('abbr', co); |
|
104 cm.setDisabled('del', co); |
|
105 cm.setDisabled('ins', co); |
|
106 cm.setDisabled('attribs', n && n.nodeName == 'BODY'); |
|
107 |
|
108 if (n) { |
|
109 cm.setDisabled(n.nodeName.toLowerCase(), 0); |
|
110 cm.setActive(n.nodeName.toLowerCase(), 1); |
|
111 } else { |
|
112 cm.setActive('cite', 0); |
|
113 cm.setActive('acronym', 0); |
|
114 cm.setActive('abbr', 0); |
|
115 cm.setActive('del', 0); |
|
116 cm.setActive('ins', 0); |
|
117 } |
|
118 }); |
|
119 }, |
|
120 |
|
121 getInfo : function() { |
|
122 return { |
|
123 longname : 'XHTML Xtras Plugin', |
|
124 author : 'Moxiecode Systems AB', |
|
125 authorurl : 'http://tinymce.moxiecode.com', |
|
126 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/xhtmlxtras', |
|
127 version : tinymce.majorVersion + "." + tinymce.minorVersion |
|
128 }; |
45 } |
129 } |
|
130 }); |
46 |
131 |
47 return ""; |
132 // Register plugin |
48 }, |
133 tinymce.PluginManager.add('xhtmlxtras', tinymce.plugins.XHTMLXtrasPlugin); |
49 |
134 })(); |
50 execCommand : function(editor_id, element, command, user_interface, value) { |
|
51 var template, inst, elm; |
|
52 |
|
53 switch (command) { |
|
54 case "mceCite": |
|
55 if (!this._anySel(editor_id)) |
|
56 return true; |
|
57 |
|
58 template = new Array(); |
|
59 template['file'] = '../../plugins/xhtmlxtras/cite.htm'; |
|
60 template['width'] = 350; |
|
61 template['height'] = 250; |
|
62 tinyMCE.openWindow(template, {editor_id : editor_id}); |
|
63 return true; |
|
64 |
|
65 case "mceAcronym": |
|
66 if (!this._anySel(editor_id)) |
|
67 return true; |
|
68 |
|
69 template = new Array(); |
|
70 template['file'] = '../../plugins/xhtmlxtras/acronym.htm'; |
|
71 template['width'] = 350; |
|
72 template['height'] = 250; |
|
73 tinyMCE.openWindow(template, {editor_id : editor_id}); |
|
74 return true; |
|
75 |
|
76 case "mceAbbr": |
|
77 if (!this._anySel(editor_id)) |
|
78 return true; |
|
79 |
|
80 template = new Array(); |
|
81 template['file'] = '../../plugins/xhtmlxtras/abbr.htm'; |
|
82 template['width'] = 350; |
|
83 template['height'] = 250; |
|
84 tinyMCE.openWindow(template, {editor_id : editor_id}); |
|
85 return true; |
|
86 |
|
87 case "mceIns": |
|
88 if (!this._anySel(editor_id)) |
|
89 return true; |
|
90 |
|
91 template = new Array(); |
|
92 template['file'] = '../../plugins/xhtmlxtras/ins.htm'; |
|
93 template['width'] = 350; |
|
94 template['height'] = 310; |
|
95 tinyMCE.openWindow(template, {editor_id : editor_id}); |
|
96 return true; |
|
97 |
|
98 case "mceDel": |
|
99 if (!this._anySel(editor_id)) |
|
100 return true; |
|
101 |
|
102 template = new Array(); |
|
103 template['file'] = '../../plugins/xhtmlxtras/del.htm'; |
|
104 template['width'] = 350; |
|
105 template['height'] = 310; |
|
106 tinyMCE.openWindow(template, {editor_id : editor_id}); |
|
107 return true; |
|
108 |
|
109 case "mceAttributes": |
|
110 inst = tinyMCE.getInstanceById(editor_id); |
|
111 elm = inst.getFocusElement(); |
|
112 |
|
113 if (elm && elm.nodeName !== 'BODY' && elm.className.indexOf('mceItem') == -1) { |
|
114 tinyMCE.openWindow({ |
|
115 file : '../../plugins/xhtmlxtras/attributes.htm', |
|
116 width : 380, |
|
117 height : 370 |
|
118 }, {editor_id : editor_id}); |
|
119 } |
|
120 |
|
121 return true; |
|
122 } |
|
123 |
|
124 return false; |
|
125 }, |
|
126 |
|
127 cleanup : function(type, content, inst) { |
|
128 if (type == 'insert_to_editor' && tinyMCE.isIE && !tinyMCE.isOpera) { |
|
129 content = content.replace(/<abbr([^>]+)>/gi, '<html:ABBR $1>'); |
|
130 content = content.replace(/<\/abbr>/gi, '</html:ABBR>'); |
|
131 } |
|
132 |
|
133 return content; |
|
134 }, |
|
135 |
|
136 handleNodeChange : function(editor_id, node, undo_index,undo_levels, visual_aid, any_selection) { |
|
137 var elm = tinyMCE.getParentElement(node); |
|
138 |
|
139 if (node == null) |
|
140 return; |
|
141 |
|
142 tinyMCE.switchClass(editor_id + '_attribs', 'mceButtonDisabled'); |
|
143 |
|
144 if (!any_selection) { |
|
145 // Disable the buttons |
|
146 tinyMCE.switchClass(editor_id + '_cite', 'mceButtonDisabled'); |
|
147 tinyMCE.switchClass(editor_id + '_acronym', 'mceButtonDisabled'); |
|
148 tinyMCE.switchClass(editor_id + '_abbr', 'mceButtonDisabled'); |
|
149 tinyMCE.switchClass(editor_id + '_del', 'mceButtonDisabled'); |
|
150 tinyMCE.switchClass(editor_id + '_ins', 'mceButtonDisabled'); |
|
151 } else { |
|
152 // A selection means the buttons should be active. |
|
153 tinyMCE.switchClass(editor_id + '_cite', 'mceButtonNormal'); |
|
154 tinyMCE.switchClass(editor_id + '_acronym', 'mceButtonNormal'); |
|
155 tinyMCE.switchClass(editor_id + '_abbr', 'mceButtonNormal'); |
|
156 tinyMCE.switchClass(editor_id + '_del', 'mceButtonNormal'); |
|
157 tinyMCE.switchClass(editor_id + '_ins', 'mceButtonNormal'); |
|
158 } |
|
159 |
|
160 if (elm && elm.nodeName != 'BODY' && elm.className.indexOf('mceItem') == -1) |
|
161 tinyMCE.switchClass(editor_id + '_attribs', 'mceButtonNormal'); |
|
162 |
|
163 switch (node.nodeName) { |
|
164 case "CITE": |
|
165 tinyMCE.switchClass(editor_id + '_cite', 'mceButtonSelected'); |
|
166 return true; |
|
167 |
|
168 case "ACRONYM": |
|
169 tinyMCE.switchClass(editor_id + '_acronym', 'mceButtonSelected'); |
|
170 return true; |
|
171 |
|
172 case "abbr": // IE |
|
173 case "HTML:ABBR": // FF |
|
174 case "ABBR": |
|
175 tinyMCE.switchClass(editor_id + '_abbr', 'mceButtonSelected'); |
|
176 return true; |
|
177 |
|
178 case "DEL": |
|
179 tinyMCE.switchClass(editor_id + '_del', 'mceButtonSelected'); |
|
180 return true; |
|
181 |
|
182 case "INS": |
|
183 tinyMCE.switchClass(editor_id + '_ins', 'mceButtonSelected'); |
|
184 return true; |
|
185 } |
|
186 |
|
187 return true; |
|
188 }, |
|
189 |
|
190 _anySel : function(editor_id) { |
|
191 var inst = tinyMCE.getInstanceById(editor_id), t = inst.selection.getSelectedText(), pe; |
|
192 |
|
193 pe = tinyMCE.getParentElement(inst.getFocusElement(), 'CITE,ACRONYM,ABBR,HTML:ABBR,DEL,INS'); |
|
194 |
|
195 return pe || inst.getFocusElement().nodeName == "IMG" || (t && t.length > 0); |
|
196 } |
|
197 }; |
|
198 |
|
199 tinyMCE.addPlugin("xhtmlxtras", TinyMCE_XHTMLXtrasPlugin); |
|