upgrading tinymce to 2.0.5.1
This commit is contained in:
parent
cb2a8d025e
commit
00d46f6148
342 changed files with 13043 additions and 11487 deletions
|
|
@ -14,239 +14,212 @@
|
|||
|
||||
<h2>Creating your own plugins</h2>
|
||||
<p>
|
||||
Creating you own plugins for the TinyMCE application is fairly easy if you know the basics of HTML, CSS and Javascript. The most easy way is to copy the "_template" directory or one of the other core plugins and work from there. The "_template" directory is a tutorial plugin that shows how to create a plugin. After you copy the template you need to change the red sections marked below to the name of your plugin this is needed so that plugins don't overlap in other words it gives the plugin a unique name. Then just alter the source code as you see fit remember that your custom plugins needs to be located in tiny_mce's "plugins" directory. If you want you may add plugin specific options/settings but remember to namespace them in the following format "<your plugin>_<option>" for example "yourplugin_someoption".
|
||||
Creating you own plugins for the TinyMCE application is fairly easy if you know the basics of HTML, CSS and Javascript. The most easy way is to copy the "_template" directory or one of the other core plugins and work from there. The "_template" directory is a tutorial plugin that shows how to create a plugin. After you copy the template you need to change the red sections marked below to the name of your plugin this is needed so that plugins don't overlap in other words it gives the plugin a unique name.
|
||||
</p>
|
||||
<p>If you want you may add plugin specific options/settings but remember to namespace them in the following format "<your plugin>_<option>" for example "yourplugin_someoption".</p>
|
||||
<p>Specific callback functions that you don't need or doesn't do anything can be removed.</p>
|
||||
|
||||
<div class="separator"></div>
|
||||
<h3>Plugin directory structure</h3>
|
||||
<p>
|
||||
The example below has three functions, these are explained in greater detail below.
|
||||
<table class="btable">
|
||||
<thead>
|
||||
<th>File/Directory</td>
|
||||
<th>Description</td>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>css</td><td>Plugin specific CSS files</td></tr>
|
||||
<tr><td>docs</td><td>Plugin specific documentation</td></tr>
|
||||
<tr><td>images</td><td>Plugin specific images</td></tr>
|
||||
<tr><td>jscripts</td><td>Plugin specific jscripts for HTML dialogs</td></tr>
|
||||
<tr><td>langs</td><td>Plugin specific language files</td></tr>
|
||||
<tr><td>editor_plugin.js</td><td>Editor plugin file (compressed).</td></tr>
|
||||
<tr><td>editor_plugin_src.js</td><td>Editor plugin file (source).</td></tr>
|
||||
<tr><td>somedialog.htm</td><td>Plugin specific dialog HTML file.</td></tr>
|
||||
</table>
|
||||
</p>
|
||||
<div class="separator"></div>
|
||||
<h3>Plugin example source</h3>
|
||||
<p>
|
||||
The example below shows a simple empty plugin and all possible callbacks.
|
||||
</p>
|
||||
<p>
|
||||
<div class="example">
|
||||
<pre>
|
||||
function TinyMCE_<span class="marked">yourplugin</span>_getInfo() {
|
||||
// Should return info about the plugin to be presented in about dialog
|
||||
return {
|
||||
longname : 'Some plugin name',
|
||||
author : 'Your name',
|
||||
authorurl : 'http://www.yoursite.com',
|
||||
infourl : 'http://www.yoursite.com/docs/..',
|
||||
version : '1.0'
|
||||
};
|
||||
var TinyMCE_<span class="marked">SomeName</span>Plugin = {
|
||||
/**
|
||||
* Returns information about the plugin as a name/value array.
|
||||
* The current keys are longname, author, authorurl, infourl and version.
|
||||
*
|
||||
* @returns Name/value array containing information about the plugin.
|
||||
* @type Array
|
||||
*/
|
||||
getInfo : function() {
|
||||
return {
|
||||
longname : 'Your plugin',
|
||||
author : 'Your name',
|
||||
authorurl : 'http://www.yoursite.com',
|
||||
infourl : 'http://www.yoursite.com/docs/template.html',
|
||||
version : "1.0"
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets executed when a TinyMCE editor instance is initialized.
|
||||
*
|
||||
* @param {TinyMCE_Control} Initialized TinyMCE editor control instance.
|
||||
*/
|
||||
initInstance : function(inst) {
|
||||
// You can take out plugin specific parameters
|
||||
alert("Initialization parameter:" + tinyMCE.getParam("<span class="marked">somename</span>_someparam", false));
|
||||
|
||||
// Register custom keyboard shortcut
|
||||
inst.addShortcut('ctrl', 't', 'lang_<span class="marked">somename</span>_desc', 'mceSomeCommand');
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the HTML code for a specific control or empty string if this plugin doesn't have that control.
|
||||
* A control can be a button, select list or any other HTML item to present in the TinyMCE user interface.
|
||||
* The variable {$editor_id} will be replaced with the current editor instance id and {$pluginurl} will be replaced
|
||||
* with the URL of the plugin. Language variables such as {$lang_somekey} will also be replaced with contents from
|
||||
* the language packs.
|
||||
*
|
||||
* @param {string} cn Editor control/button name to get HTML for.
|
||||
* @return HTML code for a specific control or empty string.
|
||||
* @type string
|
||||
*/
|
||||
getControlHTML : function(cn) {
|
||||
switch (cn) {
|
||||
case "<span class="marked">SomeControl</span>":
|
||||
return tinyMCE.getButtonHTML(cn, 'lang_<span class="marked">someplugin</span>_<span class="marked">button</span>_desc', '{$pluginurl}/images/<span class="marked">someimage</span>.gif', '<span class="marked">mceSomeCommand</span>');
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
getControlHTML : function(cn) {
|
||||
switch (cn) {
|
||||
case "advhr":
|
||||
return tinyMCE.getButtonHTML(cn, 'lang_insert_advhr_desc', '{$pluginurl}/images/advhr.gif', 'mceAdvancedHr');
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Executes a specific command, this function handles plugin commands.
|
||||
*
|
||||
* @param {string} editor_id TinyMCE editor instance id that issued the command.
|
||||
* @param {HTMLElement} element Body or root element for the editor instance.
|
||||
* @param {string} command Command name to be executed.
|
||||
* @param {string} user_interface True/false if a user interface should be presented.
|
||||
* @param {mixed} value Custom value argument, can be anything.
|
||||
* @return true/false if the command was executed by this plugin or not.
|
||||
* @type
|
||||
*/
|
||||
execCommand : function(editor_id, element, command, user_interface, value) {
|
||||
// Handle commands
|
||||
switch (command) {
|
||||
// Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser.
|
||||
case "mce<span class="marked">SomeCommand</span>":
|
||||
// Do your custom command logic here.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pass to next handler in chain
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets called ones the cursor/selection in a TinyMCE instance changes. This is useful to enable/disable
|
||||
* button controls depending on where the user are and what they have selected. This method gets executed
|
||||
* alot and should be as performance tuned as possible.
|
||||
*
|
||||
* @param {string} editor_id TinyMCE editor instance id that was changed.
|
||||
* @param {HTMLNode} node Current node location, where the cursor is in the DOM tree.
|
||||
* @param {int} undo_index The current undo index, if this is -1 custom undo/redo is disabled.
|
||||
* @param {int} undo_levels The current undo levels, if this is -1 custom undo/redo is disabled.
|
||||
* @param {boolean} visual_aid Is visual aids enabled/disabled ex: dotted lines on tables.
|
||||
* @param {boolean} any_selection Is there any selection at all or is there only a cursor.
|
||||
*/
|
||||
handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets called when a TinyMCE editor instance gets filled with content on startup.
|
||||
*
|
||||
* @param {string} editor_id TinyMCE editor instance id that was filled with content.
|
||||
* @param {HTMLElement} body HTML body element of editor instance.
|
||||
* @param {HTMLDocument} doc HTML document instance.
|
||||
*/
|
||||
setupContent : function(editor_id, body, doc) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets called when the contents of a TinyMCE area is modified, in other words when a undo level is
|
||||
* added.
|
||||
*
|
||||
* @param {TinyMCE_Control} inst TinyMCE editor area control instance that got modified.
|
||||
*/
|
||||
onChange : function(inst) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets called when TinyMCE handles events such as keydown, mousedown etc. TinyMCE
|
||||
* doesn't listen on all types of events so custom event handling may be required for
|
||||
* some purposes.
|
||||
*
|
||||
* @param {Event} e HTML editor event reference.
|
||||
* @return true - pass to next handler in chain, false - stop chain execution
|
||||
* @type boolean
|
||||
*/
|
||||
handleEvent : function(e) {
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets called when HTML contents is inserted or retrived from a TinyMCE editor instance.
|
||||
* The type parameter contains what type of event that was performed and what format the content is in.
|
||||
* Possible valuses for type is get_from_editor, insert_to_editor, get_from_editor_dom, insert_to_editor_dom.
|
||||
*
|
||||
* @param {string} type Cleanup event type.
|
||||
* @param {mixed} content Editor contents that gets inserted/extracted can be a string or DOM element.
|
||||
* @param {TinyMCE_Control} inst TinyMCE editor instance control that performes the cleanup.
|
||||
* @return New content or the input content depending on action.
|
||||
* @type string
|
||||
*/
|
||||
cleanup : function(type, content, inst) {
|
||||
return content;
|
||||
},
|
||||
|
||||
// Private plugin internal methods
|
||||
|
||||
/**
|
||||
* This is just a internal plugin method, prefix all internal methods with a _ character.
|
||||
* The prefix is needed so they doesn't collide with future TinyMCE callback functions.
|
||||
*
|
||||
* @param {string} a Some arg1.
|
||||
* @param {string} b Some arg2.
|
||||
* @return Some return.
|
||||
* @type string
|
||||
*/
|
||||
_someInternalFunction : function(a, b) {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
function TinyMCE_<span class="marked">yourplugin</span>_initInstance(inst) {
|
||||
// Gets executed when a editor instance is initialized
|
||||
}
|
||||
|
||||
function TinyMCE_<span class="marked">yourplugin</span>_getControlHTML(control_name) {
|
||||
// Gets executed when a button is to be generated
|
||||
}
|
||||
|
||||
function TinyMCE_<span class="marked">yourplugin</span>_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
|
||||
// Gets executed when the selection changes
|
||||
}
|
||||
|
||||
function TinyMCE_<span class="marked">yourplugin</span>_execCommand(editor_id, element, command, user_interface, value) {
|
||||
// Add your own custom commands here
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function TinyMCE_<span class="marked">yourplugin</span>_cleanup(type, content) {
|
||||
// Add your own custom cleanup here
|
||||
|
||||
return content;
|
||||
}
|
||||
// Adds the plugin class to the list of available TinyMCE plugins
|
||||
tinyMCE.addPlugin("<span class="marked">someplugin</span>", TinyMCE_<span class="marked">SomePlugin</span>Plugin);
|
||||
</pre>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<h3>Creating popup HTML files</h3>
|
||||
<p>
|
||||
When creating a popup you need to include the "tiny_mce_popup.js" this enables you to retrive the tinyMCE global instance in all popup windows. All variables and language definitions gets replaced in the page when it loads. So language variables such as {$lang_something} can be places in the HTML code, if you need to get a language string in JavaScript simply use the tinyMCE.getLang function.
|
||||
</p>
|
||||
<h3>Example of simple popup file:</h3>
|
||||
<div class="example">
|
||||
<pre>
|
||||
<html>
|
||||
<head>
|
||||
<title>{$lang_plugin_sample_title}</title>
|
||||
<script language="javascript" src="../../tiny_mce_popup.js"></script>
|
||||
<script language="javascript">
|
||||
// getWindowArg returns any arguments passed to the window
|
||||
alert(tinyMCE.getWindowArg('some_arg'));
|
||||
</script>
|
||||
<body>
|
||||
<strong>{$lang_plugin_sample_desc}</strong>
|
||||
</body>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<h3>The TinyMCE_<plugin>_initInstance function (Optional)</h3>
|
||||
<p>
|
||||
This function is called when a editor instance gets initialized.
|
||||
</p>
|
||||
<p>
|
||||
<table border="1" cellspacing="0" cellpadding="4">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2">Parameters</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>inst</strong></td>
|
||||
<td>Reference to editor instance that was initialized.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<h3>The TinyMCE_<plugin>_handleNodeChange function (Optional)</h3>
|
||||
<p>
|
||||
This function is called when the cursor/selection of a editor instance changes. Then the currenly selected/focused node is passed to this function. This can be useful when you want to change the UI depending on what the user has selected.
|
||||
</p>
|
||||
<p>
|
||||
<table border="1" cellspacing="0" cellpadding="4">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2">Parameters</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>editor_id</strong></td>
|
||||
<td>Unique editor id, this is the same as the $editor_id variable in getEditorTemplate.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>node</strong></td>
|
||||
<td>Reference to the Node element where the cursor is currenly located.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>undo_index</strong></td>
|
||||
<td>Current undo index, this value is -1 if the custom undo/redo support is disabled.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>undo_levels</strong></td>
|
||||
<td>Current number of undo levels, this value is -1 if the custom undo/redo support is disabled.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>visual_aid</strong></td>
|
||||
<td>True/false state of visual aid/guidelines mode.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>any_selection</strong></td>
|
||||
<td>Is any text or image selected.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<h3>The TinyMCE_<plugin>_execCommand function (Optional)</h3>
|
||||
<p>
|
||||
This function is called when a command is executed for example "bold" or "createlink" this callback/plugin function may then intercept plugin specific commands and do custom logic. If this command returns true the command handling is terminated and the default tinyMCE command handeling never gets executed.
|
||||
</p>
|
||||
<p>
|
||||
<table border="1" cellspacing="0" cellpadding="4">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2">Parameters</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>editor_id</strong></td>
|
||||
<td>Unique editor id, this is the same as the $editor_id variable in getEditorTemplate.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>element</strong></td>
|
||||
<td>Reference to the document DOM root element of the editor instance.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>command</strong></td>
|
||||
<td>Command that is to be executed for example "myCommand".</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>user_interface</strong></td>
|
||||
<td>true/false option if a user insterace is to be used or not.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>value</strong></td>
|
||||
<td>Custom data value passed with command, may be any data type.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
<p>
|
||||
Returns: <br />
|
||||
true - Command intercepted and handled do not continue with command handling.<br />
|
||||
false - Continue with execCommand handling, bubble.<br />
|
||||
</p>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<h3>The TinyMCE_<plugin>_getControlHTML(control_name) function (Optional)</h3>
|
||||
<p>
|
||||
This function is called when a editor needs to render a specific control/button. This function should return the HTML template of that control or a empty string if the control_name wasn't recognized. Notice the variable {$pluginurl} gets replaced with the URL prefix for the current plugin directory.
|
||||
</p>
|
||||
<p>
|
||||
<table border="1" cellspacing="0" cellpadding="4">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2">Parameters</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>control_name</strong></td>
|
||||
<td>Control name to match against.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
<p>
|
||||
Returns: return the HTML template of that control or a empty string if the control_name wasn't recognized.
|
||||
</p>
|
||||
<h3>The TinyMCE_<plugin>_cleanup(type, content) function (Optional)</h3>
|
||||
<p>
|
||||
This function is called when a editor does cleanup of contents. This function has the same format as the one defined in the <a href="option_cleanup_callback.html">cleanup_callback</a> option.
|
||||
</p>
|
||||
<p>
|
||||
<table border="1" cellspacing="0" cellpadding="4">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2">Parameters</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>type</strong></td>
|
||||
<td>Type of cleanup, insert_to_editor or get_from_editor. Insert to editor is passed when new content is placed within the editor and get_from_editor is when content is passed out from the editor. When dealing with the DOM representation of the same content insert_to_editor_dom or get_from_editor_dom gets passed as a type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>content</strong></td>
|
||||
<td>HTML contents to be cleaned up, this string contains the HTML code or with the _dom types the body DOM object gets passed instead.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
<p>
|
||||
Returns: return the cleaned up HTML code.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div class="helpindexlink"><a href="index.html">Index</a></div>
|
||||
<div class="copyright">Copyright © 2005 Moxiecode Systems AB</div>
|
||||
<div class="copyright">Copyright © 2003-2006 <a href="http://www.moxiecode.com">Moxiecode Systems AB</a></div>
|
||||
<br style="clear: both" />
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue