2 * $RCSfile: editor_plugin_src.js,v $
\r
4 * $Date: 2006/02/22 20:06:23 $
\r
7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
\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
14 * Steps for creating a plugin from this template:
\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
26 var TinyMCE_TemplatePlugin = {
\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
31 * @returns Name/value array containing information about the plugin.
\r
34 getInfo : function() {
\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
45 * Gets executed when a TinyMCE editor instance is initialized.
\r
47 * @param {TinyMCE_Control} Initialized TinyMCE editor control instance.
\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
53 // Register custom keyboard shortcut
\r
54 inst.addShortcut('ctrl', 't', 'lang_template_desc', 'mceTemplate');
\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
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
68 getControlHTML : function(cn) {
\r
71 return tinyMCE.getButtonHTML(cn, 'lang_template_desc', '{$pluginurl}/images/template.gif', 'mceTemplate', true);
\r
78 * Executes a specific command, this function handles plugin commands.
\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
88 execCommand : function(editor_id, element, command, user_interface, value) {
\r
91 // Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser.
\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
98 template['file'] = '../../plugins/template/popup.htm'; // Relative to theme
\r
99 template['width'] = 300;
\r
100 template['height'] = 200;
\r
102 tinyMCE.openWindow(template, {editor_id : editor_id, some_custom_arg : "somecustomdata"});
\r
104 // Let TinyMCE know that something was modified
\r
105 tinyMCE.triggerNodeChange(false);
\r
107 // Do a command this gets called from the template popup
\r
108 alert("execCommand: mceTemplate gets called from popup.");
\r
114 // Pass to next handler in chain
\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
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
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
137 // Deselect template button
\r
138 tinyMCE.switchClass(editor_id + '_template', 'mceButtonNormal');
\r
142 * Gets called when a TinyMCE editor instance gets filled with content on startup.
\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
148 setupContent : function(editor_id, body, doc) {
\r
152 * Gets called when the contents of a TinyMCE area is modified, in other words when a undo level is
\r
155 * @param {TinyMCE_Control} inst TinyMCE editor area control instance that got modified.
\r
157 onChange : function(inst) {
\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
165 * @param {Event} e HTML editor event reference.
\r
166 * @return true - pass to next handler in chain, false - stop chain execution
\r
169 handleEvent : function(e) {
\r
170 // Display event type in statusbar
\r
171 top.status = "template plugin event: " + e.type;
\r
173 return true; // Pass to next handler
\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
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
187 cleanup : function(type, content, inst) {
\r
189 case "get_from_editor":
\r
190 alert("[FROM] Value HTML string: " + content);
\r
192 // Do custom cleanup code here
\r
196 case "insert_to_editor":
\r
197 alert("[TO] Value HTML string: " + content);
\r
199 // Do custom cleanup code here
\r
203 case "get_from_editor_dom":
\r
204 alert("[FROM] Value DOM Element " + content.innerHTML);
\r
206 // Do custom cleanup code here
\r
210 case "insert_to_editor_dom":
\r
211 alert("[TO] Value DOM Element: " + content.innerHTML);
\r
213 // Do custom cleanup code here
\r
221 // Private plugin internal methods
\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
227 * @param {string} a Some arg1.
\r
228 * @param {string} b Some arg2.
\r
229 * @return Some return.
\r
232 _someInternalFunction : function(a, b) {
\r
237 // Adds the plugin class to the list of available TinyMCE plugins
\r
238 tinyMCE.addPlugin("template", TinyMCE_TemplatePlugin);
\r