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