4

ユーザーが別のページ要素をクリックしてテキスト領域を離れたときに、TinyMCE ツールバーを非表示にしようとしています (基本的に onBlur)。リッチ テキスト エディター機能 onBlur を非アクティブ化するソリューションを見つけましたが、ツールバーを非表示にしてリッチ テキスト表示を残すだけで済みます (html タグ付きのプレーン テキストではなく)。

どんな提案でも大歓迎です...ありがとう!

これは私が今持っているものです: (それは外部ツールバーを使用します)

<html>
<head>
<!-- TinyMCE -->
<script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
    theme_advanced_buttons1 : "fontselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,|,blockquote,image,code,|,fullscreen",
    theme_advanced_buttons2 : "bold,italic,underline,strikethrough,sub,sup,hr,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink",
    theme_advanced_buttons3 : "tablecontrols,|,charmap",
    theme_advanced_toolbar_location : "external",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true
});
</script>

</head>
<body>

<form method="post" action="somepage">
    <br />
    <br />
    <br />
    <br />
    <br />
    <textarea name="content1" id="content1" style="width: 500px;">
        This is some sample <b><u>content</u></b>.
    </textarea>
    <br />
    <br />
    <a href="javascript: void(0);" onclick="tinyMCE.getInstanceById('content1').toolbarElement.style.display = 'none'">Hide Toolbar</a>
</form>

</body>
</html>
4

3 に答える 3

6

次のコードは、フォーカスのあるツールバーをポップアップ表示し、ユーザーがエディターの外のどこかをクリックすると非表示にします。このソリューションは Safari と Firefox でテストされていますが、Internet Explorer でも機能するはずです。

 tinyMCE.init({
    ...
    oninit : function() {//fires after editor is created
        // make toolbar draggable (not essential for this anwer)
        $(tinyMCE.getInstanceById('content1').toolbarElement).draggable();

        //hide toolbar when loosing focus
        var frame = ...//get hold of iframe element which contains editable region
        if(frame.contentDocument) {
             bindEvent(frame.contentDocument.body,"blur",function() {
                 tinyMCE.getInstanceById('content1').toolbarElement.style.display = 'none';
             });
        } else {
             bindEvent(frame,"blur",function() {
                 tinyMCE.getInstanceById('content1').toolbarElement.style.display = 'none';
        }
    }
  },
  ...
 });

私の bindEvent 関数は次のとおりです。

 function bindEvent(target, eventName, fun) {
    if (target.addEventListener) {
       target.removeEventListener(eventName, fun, false);
       target.addEventListener(eventName, fun, false);
    } else {
       var name = "on"+eventName;
       target.detachEvent(name);
       target.attachEvent(name, function(){ fun(eventName); });
    }
 }

これがあなた(または誰か)に役立つことを願っています。

于 2011-08-20T10:46:37.390 に答える
1

これは仕事をするはずです

$('#' + ed.id + '_tbl '+'.mceToolbar').hide();

または、次のクラスでレイオーバー(div)を使用できます

.layover {
    background: none repeat scroll 0 0 #FFFFFF;
    display: block;
    /*you will need to set this (and the following) parameters so that the tinymce instance will be fully covered*/
    height: 100%; 
    left: 0;
    opacity: 0.6;
    position: fixed;
    top: 0;
    width: 100%;
}
于 2010-12-10T08:23:58.123 に答える
0
tinyMCE.getInstanceById(editorID).toolbarElement.style.display = 'none'
于 2010-12-09T22:23:02.607 に答える