別の方法があるかもしれません。この例を見てください。http://tinymce.moxiecode.com/examples/example_23.php
下部のリンク (Show、Hide、Bold、Get Contents など) をメニューとして使用できます (スタイリングが必要な場合があります)。次に、現在フォーカスされているテキストエリアの ID を取得し、それをメニュー (#current) に渡し、それを使用してそのテキストエリアを変更します。
あなたが説明していることを達成するには:
- まず、個々の TinyMCE メニュー項目をすべて無効にします。
- それらが無効になったら、HTML で独自の TinyMCE メニューを作成し、それに応じてスタイルを設定します。
- フォーカスされている TinyMCE テキストエリアを特定する
- 新しいメニューのアクションを、フォーカスされている Textarea に適用します
次に、いくつかのコードについて説明します(デバッグが必要になる場合があります...)
まず、TinyMCE を初期化し、メニューを無効にします。
tinyMCE configs
({
mode : "textareas",
theme : "advanced",
editor_selector : "editable"
theme_advanced_buttons1 : "",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "botton",
theme_advanced_statusbar_location : "bottom" });
tiny_mce/themes/advanced/editor_template_src.js の _addToolbars 関数を編集してからパックすることもできると思います。
次に、jQuery バインドを使用して、現在フォーカスされているテキスト領域を特定します。
$().ready(function() {
var current;
$('.editable').focus(
current = this.id;
);
$('.editable').blur(
//maybe hide the menu (?)
);
}
次に、テキストエリアとメニューで HTML を作成します
<form method="post" action="somepage">
<div id="independent_menu">
<!-- The Menu, Please Style Accordingly -->
<a href="javascript:;" onmousedown="$('#current').tinymce().show();">[Show]</a>
<a href="javascript:;" onmousedown="$('#current').tinymce().hide();">[Hide]</a>
<a href="javascript:;" onmousedown="$('#current').tinymce().execCommand('Bold');">[Bold]</a>
<a href="javascript:;" onmousedown="alert($('#current').html());">[Get contents]</a>
<a href="javascript:;" onmousedown="alert($('#current').tinymce().selection.getContent());">[Get selected HTML]</a>
<a href="javascript:;" onmousedown="alert($('#current').tinymce().selection.getContent({format : 'text'}));">[Get selected text]</a>
<a href="javascript:;" onmousedown="alert($('#current').tinymce().selection.getNode().nodeName);">[Get selected element]</a>
<a href="javascript:;" onmousedown="$('#current').tinymce().execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a>
<a href="javascript:;" onmousedown="$('#current').tinymce().execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a>
</div>
<!-- The Text Areas -->
<textarea class="editable" id="one">Some Text Here</textarea>
<textarea class="editable" id="two">Yet another text area</textarea>
<textarea class="editable" id="three">Final Text Area</textarea>