tagging as ATutor 1.5.4-release
[atutor.git] / jscripts / tiny_mce / plugins / _template / editor_plugin_src.js
1 /**\r
2  * $RCSfile: editor_plugin_src.js,v $\r
3  * $Revision: 1.12 $\r
4  * $Date: 2006/02/22 20:06:23 $\r
5  *\r
6  * @author Moxiecode\r
7  * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.\r
8  */\r
9 \r
10 /* Import plugin specific language pack */\r
11 tinyMCE.importPluginLanguagePack('template', 'en,tr,he,nb,ru,ru_KOI8-R,ru_UTF-8,nn,fi,cy,es,is,pl'); // <- Add a comma separated list of all supported languages\r
12 \r
13 /****\r
14  * Steps for creating a plugin from this template:\r
15  *\r
16  * 1. Change all "template" to the name of your plugin.\r
17  * 2. Remove all the callbacks in this file that you don't need.\r
18  * 3. Remove the popup.htm file if you don't need any popups.\r
19  * 4. Add your custom logic to the callbacks you needed.\r
20  * 5. Write documentation in a readme.txt file on how to use the plugin.\r
21  * 6. Upload it under the "Plugins" section at sourceforge.\r
22  *\r
23  ****/\r
24 \r
25 // Singleton class\r
26 var TinyMCE_TemplatePlugin = {\r
27         /**\r
28          * Returns information about the plugin as a name/value array.\r
29          * The current keys are longname, author, authorurl, infourl and version.\r
30          *\r
31          * @returns Name/value array containing information about the plugin.\r
32          * @type Array \r
33          */\r
34         getInfo : function() {\r
35                 return {\r
36                         longname : 'Template plugin',\r
37                         author : 'Your name',\r
38                         authorurl : 'http://www.yoursite.com',\r
39                         infourl : 'http://www.yoursite.com/docs/template.html',\r
40                         version : "1.0"\r
41                 };\r
42         },\r
43 \r
44         /**\r
45          * Gets executed when a TinyMCE editor instance is initialized.\r
46          *\r
47          * @param {TinyMCE_Control} Initialized TinyMCE editor control instance. \r
48          */\r
49         initInstance : function(inst) {\r
50                 // You can take out plugin specific parameters\r
51                 alert("Initialization parameter:" + tinyMCE.getParam("template_someparam", false));\r
52 \r
53                 // Register custom keyboard shortcut\r
54                 inst.addShortcut('ctrl', 't', 'lang_template_desc', 'mceTemplate');\r
55         },\r
56 \r
57         /**\r
58          * Returns the HTML code for a specific control or empty string if this plugin doesn't have that control.\r
59          * A control can be a button, select list or any other HTML item to present in the TinyMCE user interface.\r
60          * The variable {$editor_id} will be replaced with the current editor instance id and {$pluginurl} will be replaced\r
61          * with the URL of the plugin. Language variables such as {$lang_somekey} will also be replaced with contents from\r
62          * the language packs.\r
63          *\r
64          * @param {string} cn Editor control/button name to get HTML for.\r
65          * @return HTML code for a specific control or empty string.\r
66          * @type string\r
67          */\r
68         getControlHTML : function(cn) {\r
69                 switch (cn) {\r
70                         case "template":\r
71                                 return tinyMCE.getButtonHTML(cn, 'lang_template_desc', '{$pluginurl}/images/template.gif', 'mceTemplate', true);\r
72                 }\r
73 \r
74                 return "";\r
75         },\r
76 \r
77         /**\r
78          * Executes a specific command, this function handles plugin commands.\r
79          *\r
80          * @param {string} editor_id TinyMCE editor instance id that issued the command.\r
81          * @param {HTMLElement} element Body or root element for the editor instance.\r
82          * @param {string} command Command name to be executed.\r
83          * @param {string} user_interface True/false if a user interface should be presented.\r
84          * @param {mixed} value Custom value argument, can be anything.\r
85          * @return true/false if the command was executed by this plugin or not.\r
86          * @type\r
87          */\r
88         execCommand : function(editor_id, element, command, user_interface, value) {\r
89                 // Handle commands\r
90                 switch (command) {\r
91                         // Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser.\r
92                         case "mceTemplate":\r
93                                 // Show UI/Popup\r
94                                 if (user_interface) {\r
95                                         // Open a popup window and send in some custom data in a window argument\r
96                                         var template = new Array();\r
97 \r
98                                         template['file'] = '../../plugins/template/popup.htm'; // Relative to theme\r
99                                         template['width'] = 300;\r
100                                         template['height'] = 200;\r
101 \r
102                                         tinyMCE.openWindow(template, {editor_id : editor_id, some_custom_arg : "somecustomdata"});\r
103 \r
104                                         // Let TinyMCE know that something was modified\r
105                                         tinyMCE.triggerNodeChange(false);\r
106                                 } else {\r
107                                         // Do a command this gets called from the template popup\r
108                                         alert("execCommand: mceTemplate gets called from popup.");\r
109                                 }\r
110 \r
111                                 return true;\r
112                 }\r
113 \r
114                 // Pass to next handler in chain\r
115                 return false;\r
116         },\r
117 \r
118         /**\r
119          * Gets called ones the cursor/selection in a TinyMCE instance changes. This is useful to enable/disable\r
120          * button controls depending on where the user are and what they have selected. This method gets executed\r
121          * alot and should be as performance tuned as possible.\r
122          *\r
123          * @param {string} editor_id TinyMCE editor instance id that was changed.\r
124          * @param {HTMLNode} node Current node location, where the cursor is in the DOM tree.\r
125          * @param {int} undo_index The current undo index, if this is -1 custom undo/redo is disabled.\r
126          * @param {int} undo_levels The current undo levels, if this is -1 custom undo/redo is disabled.\r
127          * @param {boolean} visual_aid Is visual aids enabled/disabled ex: dotted lines on tables.\r
128          * @param {boolean} any_selection Is there any selection at all or is there only a cursor.\r
129          */\r
130         handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
131                 // Select template button if parent node is a strong or b\r
132                 if (node.parentNode.nodeName == "STRONG" || node.parentNode.nodeName == "B") {\r
133                         tinyMCE.switchClass(editor_id + '_template', 'mceButtonSelected');\r
134                         return true;\r
135                 }\r
136 \r
137                 // Deselect template button\r
138                 tinyMCE.switchClass(editor_id + '_template', 'mceButtonNormal');\r
139         },\r
140 \r
141         /**\r
142          * Gets called when a TinyMCE editor instance gets filled with content on startup.\r
143          *\r
144          * @param {string} editor_id TinyMCE editor instance id that was filled with content.\r
145          * @param {HTMLElement} body HTML body element of editor instance.\r
146          * @param {HTMLDocument} doc HTML document instance.\r
147          */\r
148         setupContent : function(editor_id, body, doc) {\r
149         },\r
150 \r
151         /**\r
152          * Gets called when the contents of a TinyMCE area is modified, in other words when a undo level is\r
153          * added.\r
154          *\r
155          * @param {TinyMCE_Control} inst TinyMCE editor area control instance that got modified.\r
156          */\r
157         onChange : function(inst) {\r
158         },\r
159 \r
160         /**\r
161          * Gets called when TinyMCE handles events such as keydown, mousedown etc. TinyMCE\r
162          * doesn't listen on all types of events so custom event handling may be required for\r
163          * some purposes.\r
164          *\r
165          * @param {Event} e HTML editor event reference.\r
166          * @return true - pass to next handler in chain, false - stop chain execution\r
167          * @type boolean\r
168          */\r
169         handleEvent : function(e) {\r
170                 // Display event type in statusbar\r
171                 top.status = "template plugin event: " + e.type;\r
172 \r
173                 return true; // Pass to next handler\r
174         },\r
175 \r
176         /**\r
177          * Gets called when HTML contents is inserted or retrived from a TinyMCE editor instance.\r
178          * The type parameter contains what type of event that was performed and what format the content is in.\r
179          * Possible valuses for type is get_from_editor, insert_to_editor, get_from_editor_dom, insert_to_editor_dom.\r
180          *\r
181          * @param {string} type Cleanup event type.\r
182          * @param {mixed} content Editor contents that gets inserted/extracted can be a string or DOM element.\r
183          * @param {TinyMCE_Control} inst TinyMCE editor instance control that performes the cleanup.\r
184          * @return New content or the input content depending on action.\r
185          * @type string\r
186          */\r
187         cleanup : function(type, content, inst) {\r
188                 switch (type) {\r
189                         case "get_from_editor":\r
190                                 alert("[FROM] Value HTML string: " + content);\r
191 \r
192                                 // Do custom cleanup code here\r
193 \r
194                                 break;\r
195 \r
196                         case "insert_to_editor":\r
197                                 alert("[TO] Value HTML string: " + content);\r
198 \r
199                                 // Do custom cleanup code here\r
200 \r
201                                 break;\r
202 \r
203                         case "get_from_editor_dom":\r
204                                 alert("[FROM] Value DOM Element " + content.innerHTML);\r
205 \r
206                                 // Do custom cleanup code here\r
207 \r
208                                 break;\r
209 \r
210                         case "insert_to_editor_dom":\r
211                                 alert("[TO] Value DOM Element: " + content.innerHTML);\r
212 \r
213                                 // Do custom cleanup code here\r
214 \r
215                                 break;\r
216                 }\r
217 \r
218                 return content;\r
219         },\r
220 \r
221         // Private plugin internal methods\r
222 \r
223         /**\r
224          * This is just a internal plugin method, prefix all internal methods with a _ character.\r
225          * The prefix is needed so they doesn't collide with future TinyMCE callback functions.\r
226          *\r
227          * @param {string} a Some arg1.\r
228          * @param {string} b Some arg2.\r
229          * @return Some return.\r
230          * @type string\r
231          */\r
232         _someInternalFunction : function(a, b) {\r
233                 return 1;\r
234         }\r
235 };\r
236 \r
237 // Adds the plugin class to the list of available TinyMCE plugins\r
238 tinyMCE.addPlugin("template", TinyMCE_TemplatePlugin);\r