我需要在初始化后以编程方式将焦点设置到编辑器实例。
该框获得焦点,您可以开始输入,但除非您在编辑器框架中单击,否则不会显示外部工具栏。
我尝试更改一些 css 设置并显示工具栏,但单击编辑器框架时它会消失。
var toolbar = $('#' + ed.id + '_external').hide().appendTo("#tiny_toolbar");
toolbar.show();
toolbar.css('top','50px');
toolbar.css('display','block');
$(".defaultSkin,.mceExternalToolbar").css("position","").css("z-index","1000");
有没有办法通过 js 代码模拟编辑器单击,以便正确显示工具栏?
更新:
不,我没有错!微小的 iframe 出现在我的文本容器左侧的不同顶部。此代码将更好地解释问题所在。
<html>
<head>
<script type="text/javascript" src="js/lib/jquery.js"></script>
<script type="text/javascript" src="js/lib/jquery-ui.js"></script>
<script src="js/lib/tiny/tiny_mce.js"></script>
<script type="text/javascript">
function initTiny(){
tinyMCE.init({
language: false,
mode: "none",
theme: "advanced",
dialog_type: "modal",
theme_advanced_buttons1: ",bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "none",
theme_advanced_path: "none",
theme_advanced_toolbar_location: "external",
setup: function (ed) {
ed.onInit.add(function (ed) {
var visible = 1;
var tout = null;
var $toolbar = $('#' + ed.id + '_external');
$toolbar.css('top', '50px');
$toolbar.css('display', 'block');
$toolbar.hide();
$toolbar.show();
var show = function () {
tout && clearTimeout(tout);
tout = setTimeout(function () {
tout = null;
$toolbar.css({
top: "50px",
display: 'block'
});
visible = 1;
}, 250);
};
$(ed.getWin()).bind('click', function () {
if (ed.isHidden()) {
show();
}
});
})
}
});
}
$(document).ready(function(){
initTiny();
$('#content3').click(function(){
tinyMCE.execCommand("mceAddControl", false, 'content3');
});
$('html').click(function(){
tinyMCE.execCommand("mceRemoveControl", false, 'content3');
});
});
</script>
</head>
<body>
<div id="tiny_toolbar" class="defaultSkin" style="position:relative;"> toolbar </div>
<div id="content3" style="top:120px;left:180px;width:180px;height:200px;border:1px solid;position:absolute;">
<p>CONTENT 3!</p>
</div>
</body>
</html>
不,我没有错!微小的 iframe 出现在我的文本容器左侧的不同顶部。此代码将更好地解释问题所在。
<html>
<head>
<script type="text/javascript" src="js/lib/jquery.js"></script>
<script type="text/javascript" src="js/lib/jquery-ui.js"></script>
<script src="js/lib/tiny/tiny_mce.js"></script>
<script type="text/javascript">
function initTiny(){
tinyMCE.init({
language: false,
mode: "none",
theme: "advanced",
dialog_type: "modal",
theme_advanced_buttons1: ",bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "none",
theme_advanced_path: "none",
theme_advanced_toolbar_location: "external",
setup: function (ed) {
ed.onInit.add(function (ed) {
var visible = 1;
var tout = null;
var $toolbar = $('#' + ed.id + '_external');
$toolbar.css('top', '50px');
$toolbar.css('display', 'block');
$toolbar.hide();
$toolbar.show();
var show = function () {
tout && clearTimeout(tout);
tout = setTimeout(function () {
tout = null;
$toolbar.css({
top: "50px",
display: 'block'
});
visible = 1;
}, 250);
};
$(ed.getWin()).bind('click', function () {
if (ed.isHidden()) {
show();
}
});
})
}
});
}
$(document).ready(function(){
initTiny();
$('#content3').click(function(){
tinyMCE.execCommand("mceAddControl", false, 'content3');
});
$('html').click(function(){
tinyMCE.execCommand("mceRemoveControl", false, 'content3');
});
});
</script>
</head>
<body>
<div id="tiny_toolbar" class="defaultSkin" style="position:relative;"> toolbar </div>
<div id="content3" style="top:120px;left:180px;width:180px;height:200px;border:1px solid;position:absolute;">
<p>CONTENT 3!</p>
</div>
</body>
</html>