Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created January 13, 2013 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bueltge/4526553 to your computer and use it in GitHub Desktop.
Save bueltge/4526553 to your computer and use it in GitHub Desktop.
// path/to/theme/tinymce/en.js
// plugin.jsと同じディレクトリに設置
tinyMCE.addI18n("en.test_plugin",{
test_listbox : "Test listbox",
test_button : "Test button",
});
if(is_admin() && current_user_can('edit_posts') &&
current_user_can('edit_pages') && get_user_option('rich_editing') == 'true') {
add_filter('tiny_mce_version', 'my_tiny_mce_version');
add_filter('mce_external_plugins', 'my_mce_external_plugins');
add_filter('mce_buttons_3', 'my_mce_buttons');
}
function my_mce_buttons($buttons) {
// 追加したい要素の名前を定義(separatorは区切り)
array_push($buttons, "test_listbox", "separator", "test_button");
return $buttons;
}
function my_mce_external_plugins($plugin_array) {
// プラグインファイルのurl(今回はテーマの中に"tinymce"というディレクトリを作成)
$plugin_array['test_plugin'] = get_template_directory_uri().'/tinymce/plugin.js';
return $plugin_array;
}
function my_tiny_mce_version($version) {
return ++$version;
}
// path/to/theme/tinymce/ja.js
// plugin.jsと同じディレクトリに設置
tinyMCE.addI18n("ja.test_plugin",{
test_listbox : "Test listbox",
test_button : "Test button",
});
// path/to/theme/tinymce/plugin.js
// functions.phpのmy_mce_external_pluginで指定したファイル
(function(){
tinymce.PluginManager.requireLangPack('test_plugin');
tinymce.create('tinymce.plugins.test_plugin', {
init : function(ed, url){
//コマンドを追加
ed.addCommand('listbox_1', function(){
tinyMCE.activeEditor.selection.setContent('<ul>' +
'<li>リストです。</li>' +
'<li>リストです。</li>' +
'</ul>');
});
//コマンドを追加
ed.addCommand('listbox_2', function(){
tinyMCE.activeEditor.selection.setContent('<table>' +
'<tr><th>表見出し</th><td>テーブルです。</td></tr>' +
'<tr><th>表見出し</th><td>テーブルです。</td></tr>' +
'</table>');
});
//コマンドを追加
ed.addCommand('button_1', function(){
tinyMCE.activeEditor.selection.setContent('Hello, world!');
});
//ボタンを追加
ed.addButton('test_button', {
title: 'ボタン',
cmd: 'button_1',
image: url + '/test.png'
});
},
createControl : function(n, cm){
switch (n) {
// functions.phpで定義したリストボックス名
case 'test_listbox':
var mlb = cm.createListBox('test_listbox_object', {
title : 'リストボックス',
onselect : function(v) {
tinyMCE.activeEditor.execCommand('listbox_'+v, false, v);
}
});
// リストボックスにメニューを追加
mlb.add('メニュー1', 1);
mlb.add('メニュー2', 2);
return mlb;
}
return null;
},
getInfo : function(){
return {
longname: 'Test plugin',
author: 'ringo',
authorurl: 'http://example.com',
infourl: 'http://example.com',
version: "1.0"
};
}
});
tinymce.PluginManager.add('test_plugin', tinymce.plugins.test_plugin);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment