当用户将注意力集中到编辑器中并隐藏工具提示模糊时,我想向tinyMCE编辑器添加工具提示。问题是tinyMCE注入一个iframe,但div我想添加css类,以便切换工具提示驻留在tinyMCE iframe之外。
所以基本上在下面的示例中,我想将类hasfocus
添加到焦点上具有类form-group
的div,并移除模糊。我怎么能实现这个目标。以下不起作用?
<style>
.hasfocus .tool-tip {
display: block;
opacity: 1;
}
.tool-tip {
display: none;
background: #e4f7f9 none repeat scroll 0 0;
border-radius: 4px;
box-shadow: 3px 3px lightgrey;
line-height: 1.3;
min-height: 36px;
padding: 20px;
position: absolute;
right: -305px;
top: 0;
transition: opacity 0.125s ease-in-out 0s;
width: 300px;
z-index: 500;
}
</style>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor"
],
toolbar: "insertfile undo redo | styleselect | bold italic,
setup : function(ed) {
ed.on('init', function()
{
var a = "hasfocus";
var c = $(this); // this would be the text area
var b = $(this).parents(".form-group").first();
var d = b.find(".tool-tip").eq(0), e;
$(ed.getBody()).on('blur', function(f) {
b.removeClass(a);
});
$(ed.getBody()).on('focus', function(f) {
// here i need to get the body which is outside the iframe
e = $("body").width() - (c.offset().left + c.outerWidth());
d.css("top", c.position().top);
b.addClass(a);
});
});
}
});
</script>
<body>
<div class="form-group ">
<label class="h4" for="Description">Description</label>
<div>
<!-- all the stuff tinyMCE injects -->
<div id="mceu_11" class="mce-tinymce mce-container mce-panel" role="application" tabindex="-1" hidefocus="1" style="visibility: hidden; border- width: 1px;">
<div id="mceu_11-body" class="mce-container-body mce-stack-layout">
<div id="mceu_12" class="mce-toolbar-grp mce-container mce-panel mce-stack-layout-item mce-first" role="group" tabindex="-1" hidefocus="1">
...
</div>
<div id="mceu_17" class="mce-edit-area mce-container mce-panel mce-stack-layout-item" role="group" tabindex="-1" hidefocus="1" style="border-width: 1px 0px 0px;">
<iframe id="PostContent_ifr" frameborder="0" allowtransparency="true" title="Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 175px; display: block;" src="javascript:""">
<!DOCTYPE html>
<html>
<head>...</head>
<body id="tinymce" class="mce-content-body " contenteditable="true" data-id="PostContent" spellcheck="false">
<p>This is the editor field</p>
</body>
</html>
</iframe>
</div>
</div>
</div>
<textarea name="Description"></textarea>
</div>
<div class="tool-tip" >
Please provide a detailed description
</div>
</div>
</body>
答案 0 :(得分:1)
Tinymce为访问编辑器的iframe,容器等提供了可靠的api。它还有自定义事件,尽管名称不同,但它们与DOM事件不同。
我用它们来重写你的设置功能。</ p>
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor"
],
toolbar: "insertfile undo redo | styleselect | bold italic",
setup : function(ed) {
ed.on('init', function(event) {
var a = "hasfocus";
var c = $(ed.getContainer()); // this would be the text area
var b = c.parents(".form-group").first();
var d = b.find(".tool-tip").eq(0), e;
ed.on('blur', function(f) {
b.removeClass(a);
});
ed.on('focus', function(f) {
e = $("body").width() - (c.offset().left + c.outerWidth());
d.css("top", c.position().top);
b.addClass(a);
});
});
}
});