动态更改tinyMce编辑器的高度
我在我的页面中使用了tinymce编辑器。 我想要做的是动态更改编辑器的高度。 我创建了一个函数:
function setComposeTextareaHeight() { $("#compose").height(200); }
但这不起作用。 我的textarea是
我已经尝试了各种方法来改变高度,但无法达成分辨率。 我有什么遗失的东西吗?
您可以使用resizeTo主题方法调整tinymce的大小:
editorinstance.theme.resizeTo (width, height);
宽度和高度设置了编辑区域的新大小 – 我还没有找到一种方法来推断编辑器实例的额外大小,所以你可能想要做这样的事情:
editorinstance.theme.resizeTo (new_width - 2, new_height - 32);
尝试:
tinyMCE.init({ mode : "exact", elements : "elm1", ....
要在javascript代码中动态更改大小:
var resizeHeight = 350; var resizeWidth = 450; tinyMCE.DOM.setStyle(tinyMCE.DOM.get("elm1" + '_ifr'), 'height', resizeHeight + 'px'); tinyMCE.DOM.setStyle(tinyMCE.DOM.get("elm1" + '_ifr'), 'width', resizeWidth + 'px');
以下来自我发布的其他SO答案 :
以上都不适用于TinyMCE v4,所以我的解决方案是根据工具栏/菜单栏/状态栏计算高度,然后设置编辑器的高度,考虑这些高度。
function resizeEditor(myHeight) { window.console.log('resizeEditor'); myEditor = getEditor(); if (myEditor) { try { if (!myHeight) { var targetHeight = window.innerHeight; // Change this to the height of your wrapper element var mce_bars_height = 0; $('.mce-toolbar, .mce-statusbar, .mce-menubar').each(function(){ mce_bars_height += $(this).height(); }); window.console.log('mce bars height total: '+mce_bars_height); myHeight = targetHeight - mce_bars_height - 8; // the extra 8 is for margin added between the toolbars } window.console.log('resizeEditor: ', myHeight); myEditor.theme.resizeTo('100%', myHeight); // sets the dimensions of the editable area } catch (err) { } } }
在我的例子中,我希望编辑器窗口与实际window
的宽度和高度相匹配,因为编辑器会出现在弹出窗口中。 要检测更改并resize,我将其设置为回调:
window.onresize = function() { resizeEditor(); }
这有点晚了,但对于像我这样的Googler,请查看autoresize插件
tinymce.init({ plugins: "autoresize" });
选项
autoresize_min_height :自动resize时编辑器的最小高度值。
autoresize_max_height :编辑器自动resize时的最大高度值。
ManseUK所说的几乎是正确的。 正确的解决方案是:
$('#compose_ifr').height(200);
或者在你的情况下
$('#composeMailContent_ifr').height(200);
更新:也许这就是你想要的更多:
// resizes editoriframe resizeIframe: function(frameid) { var frameid = frameid ? frameid : this.editor.id+'_ifr'; var currentfr=document.getElementById(frameid); if (currentfr && !window.opera){ currentfr.style.display="block"; if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax currentfr.height = 200 + 26; } else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax currentfr.height = 200; } styles = currentfr.getAttribute('style').split(';'); for (var i=0; i
如果有人发现这个并且还想要更改源代码编辑器插件的高度 。
您需要编辑以下文件:
\tiny_mce\plugins\code\plugin.min.js
注意名为minHeigh
的属性并根据您的需要进行调整。 您定义的高度不是整个框的高度,但它也不是textarea的高度。 它介于两者之间。
$(window).load(function () { $('#YourID_ifr').css('height', '550px'); });