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