简体   繁体   English

TinyMCE 编辑器工具栏高度不正确?

[英]TinyMCE editor toolbar height is incorrect?

EDIT: I've now included a working jsfiddle - please go to the bottom of the post.编辑:我现在已经包含了一个有效的 jsfiddle - 请转到帖子的底部。

According to the TinyMCE docs, the height property of the editor : 根据 TinyMCE 文档,编辑器的高度属性

sets the height of the editable area only.仅设置可编辑区域的高度。 It does not include the space required for the menubar, toolbars or status bar.它不包括菜单栏、工具栏或状态栏所需的空间。

My editor only has a toolbar and I'm currently trying to derive the toolbar height so that I can set an accurate height for the whole editor.我的编辑器只有一个工具栏,我目前正在尝试导出工具栏高度,以便我可以为整个编辑器设置准确的高度。

My problem is that when I try to derive the editor toolbar height it is incorrect:我的问题是,当我尝试导出编辑器工具栏高度时,它是不正确的:

My DOM structure looks like this:我的 DOM 结构如下所示:

<div id = "outer">
   <div id = "textArea" + dynamically created unique editor id></div>
</div>

The textArea div can either be maximized or not. textArea div 可以最大化或不最大化。

Not maximized:未最大化:

Maximized:最大化:

When not maximized, I can see in Chrome DevTools that the clientHeight property of "#outer" + " .mce-toolbar-grp.mce-container.mce-panel.mce-stack-layout-item.mce-first" is 64, and 34 if maximized.未最大化时,我可以在 Chrome DevTools 中看到“#outer”+“.mce-toolbar-grp.mce-container.mce-panel.mce-stack-layout-item.mce-first”的 clientHeight 属性为 64 ,如果最大化则为 34。

Yet, when I try to get this value via code in my editor's setup callback it always comes out as 326.然而,当我尝试通过编辑器设置回调中的代码获取此值时,它总是显示为 326。

What's going on?这是怎么回事?

tinymce.init({
   selector: "#textArea" + uniqueEditorId,
   menubar: false,
   statusbar: false,
   browser_spellcheck: true,
   contextmenu: false,
   plugins: "textcolor link",
   font_formats: "Sans Serif = arial, helvetica, sans-serif;Serif = times new roman, serif;Fixed Width = monospace;Wide = arial black, sans-serif;Narrow = arial narrow, sans-serif;Comic Sans MS = comic sans ms, sans-serif;Garamond = garamond, serif;Georgia = georgia, serif;Tahoma = tahoma, sans-serif;Trebuchet MS = trebuchet ms, sans-serif;Verdana = verdana, sans-serif",
   toolbar: "fontselect | fontsizeselect | bold italic underline | forecolor | numlist bullist | alignleft aligncenter alignright alignjustify | outdent indent | link unlink | undo redo",

   width: textArea.clientWidth, 
   // I want to figure this out dynamically, rather than hard-coding it.
   height: textArea.clientHeight - 64, 

   setup: function(editor) {
      editor.on("init", function() {
         var edToolbar = document.querySelector("#outer" + " .mce-toolbar-grp.mce-container.mce-panel.mce-stack-layout-item.mce-first");
         // Always 326
         console.log("edToolbar.clientHeight: " + edToolbar.clientHeight);
      });
   }
});

Jsfiddle: https://jsfiddle.net/80351/6o9j75d1/2/ jsfiddle: https ://jsfiddle.net/80351/6o9j75d1/2/
In the Jsfiddle example above, I want the TinyMCE editor to resize in height to be the exact same overall height as the inner div.在上面的 Jsfiddle 示例中,我希望 TinyMCE 编辑器将高度调整为与内部 div 完全相同的整体高度。 Uncomment the section with the editor initialisation after watching the inner resizing to see what I mean by that.在观看内部调整大小以了解我的意思后,用编辑器初始化取消注释该部分。

Although I use editor.theme.resizeTo(getInnerWidth(), getInnerHeight());虽然我使用editor.theme.resizeTo(getInnerWidth(), getInnerHeight()); every time the outer div changes height, the resized height is mostly incorrect.每次外部 div 更改高度时,调整后的高度大多不正确。

Rather than trying to calculate the height on the fly, would you be opposed to having it not resize using multiple toolbars?与其尝试动态计算高度,您是否会反对不使用多个工具栏调整其大小? So instead of your current toolbar attribute, it would be:因此,不是您当前的工具栏属性,而是:

toolbar: ["fontselect | fontsizeselect | bold italic underline | forecolor | numlist bullist", 
    "alignleft aligncenter alignright alignjustify | outdent indent | link unlink | undo redo"]

https://www.tinymce.com/docs/configure/editor-appearance/#usingmultipletoolbars https://www.tinymce.com/docs/configure/editor-appearance/#usingmultipletoolbars

I've needed to implement something similar before.我以前需要实现类似的东西。 For me, the following code worked:对我来说,以下代码有效:

function getInnerHeight() {
  var inner = document.querySelector("#inner");
  return inner.clientHeight - document.getElementsByClassName("mce-toolbar-grp")[0].offsetHeight; 
}

Have you tried it already?你已经试过了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM