如何為TinyMce寫一個插件
1. 目錄切換到tiny_mce\plugins, 建立一個檔案夾:myplugins
2. 目錄切換到tiny_mce\plugins\myplugins
a. 建立一個檔案夾 img, 并在其目錄下添加一個example.gif, 目錄應為tiny_mce\plugins\myplugins\img\example.gif
b. 在目錄tiny_mce\plugins\myplugins下, 建立editor_plugin.js
c. 在目錄tiny_mce\plugins\myplugins下, 建立test.html
3. 目錄切換到tiny_mce\langs, 打開en.js, 添加
myplugins:{
image_desc:"test the plugin of mine"
},
4. 打開剛剛添加的editor_plugin.js,
AdvancedMyPlugins: 和最後一行對應就行
myimage: 在工具欄上要顯示的圖示,以及點選它後執行什麼指令
mceMyPlugins: 指令名,在ed.addCommand裡定義執行什麼動作
添加下面内容
Javascript代碼

- (function() {
- tinymce.create('tinymce.plugins.AdvancedMyPlugins', {
- init : function(ed, url) {
- ed.addCommand('mceMyPlugins', function() {
- if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
- return;
- ed.windowManager.open({
- file : url + '/test.html',
- width : 590,
- height : 370,
- inline : 1
- }, {
- plugin_url : url
- });
- });
- ed.addButton('myimage', {
- title : 'myplugins.image_desc',
- cmd : 'mceMyPlugins',
- image : url + '/img/example.gif'
- });
- },
- getInfo : function() {
- return {
- longname : 'My Plugins',
- author : 'Moxiecode Systems AB',
- authorurl : 'http://tinymce.moxiecode.com',
- infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
- version : tinymce.majorVersion + "." + tinymce.minorVersion
- };
- },
- createControl : function(n, cm) {
- return null;
- }
- });
- // Register plugin
- tinymce.PluginManager.add('myplugins', tinymce.plugins.AdvancedMyPlugins);
- })();
5. 編輯html 頁面, 添加myplugins and myimage
Html代碼

- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Simple theme example</title>
- <!-- TinyMCE -->
- <script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
- <script type="text/javascript">
- tinyMCE.init({
- mode : "textareas",
- theme : "advanced",
- plugins: "safari,style,advimage,wbxadvimage,table,advlink,preview,searchreplace,paste,noneditable,contextmenu,inlinepopups,myplugins",
- theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,|,numlist,bullist,outdent,indent,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect,image,myimage",
- theme_advanced_buttons2 : "",
- theme_advanced_toolbar_location : "top",
- theme_advanced_toolbar_align : "left",
- table_row_limit: 100,
- table_col_limit: 100,
- position : 'home'
- });
- </script>
- <!-- /TinyMCE -->
- </head>
- <body>
- <form method="post" action="http://tinymce.moxiecode.com/dump.php?example=true">
- <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
- </textarea>
- </form>
- </body>
- </html>