gpt4 book ai didi

javascript - 如何在不完全停用富文本编辑器的情况下隐藏 TinyMCE 工具栏 onBlur?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:28:44 24 4
gpt4 key购买 nike

当用户单击另一个页面元素并离开文本区域(本质上是 onBlur)时,我试图隐藏 TinyMCE 工具栏。我找到了可以在 Blur 上停用富文本编辑器功能的解决方案,但我只需要隐藏工具栏并保留富文本显示(而不是带有 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>

最佳答案

以下代码在焦点处弹出工具栏,并在用户单击编辑器外部某处时将其隐藏。此解决方案已针对 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); });
}
}

希望这对您(或某人)有帮助。

关于javascript - 如何在不完全停用富文本编辑器的情况下隐藏 TinyMCE 工具栏 onBlur?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4401982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com