【问题标题】:make both editors in the same size when they autogrowing自动增长时使两个编辑器的大小相同
【发布时间】:2015-04-02 13:07:37
【问题描述】:

我在一个页面中使用了两个 CKEDITOR 的编辑器,而且我始终保持它们的大小相同。我正在使用自动增长插件,所以我尝试了一下:

CKEDITOR.plugins.addExternal( 'autogrow', location.href + 'ckeditor/autogrow/', 'plugin.js' );
var e1 = CKEDITOR.replace("heb_editor", {extraPlugins: 'autogrow'});
var e2 = CKEDITOR.replace("eng_editor", {extraPlugins: 'autogrow'});
e1.on("resize", r);
e2.on("resize", r);

function r(){
    if($("#cke_1_contents").height() > e2.config.height)
        $("#cke_2_contents").height($("#cke_1_contents").height());
    else
        $("#cke_1_contents").height($("#cke_2_contents").height());
}

没有用。它确实将第二个编辑器的大小调整为第一个的大小,但在需要时它没有将第一个编辑器的大小调整为第二个的大小。怎么办?

这是一个 JSfiddle:http://jsfiddle.net/povw33x7/

【问题讨论】:

标签: javascript jquery ckeditor autogrow


【解决方案1】:

忘记我之前所说的(我删除了它,但你仍然可以在revision history看到它)。

使用我在Web site 上找到的一些代码,您可以计算盒子的高度。现在,您只需要应用它来更新调整大小时的框高度:

function getBoxHeight(boxId) {

    // using a function to get the height of the box from ==> 
    var ckeditorFrame = $('#' + boxId + ' iframe');
    var innerDoc = (ckeditorFrame.get(0).contentDocument) ? ckeditorFrame.get(0).contentDocument : ckeditorFrame.get(0).contentWindow.document;
    var messageHeight = $(innerDoc.body).height();

    return messageHeight ? messageHeight : 0;
}

function r() {

    if (getBoxHeight("cke_1_contents") > getBoxHeight("cke_2_contents")) {
        $("#cke_2_contents").height($("#cke_1_contents").height());
    } else {
        $("#cke_1_contents").height($("#cke_2_contents").height());
    }

}

正如您在此 JSFiddle 上看到的:http://jsfiddle.net/povw33x7/3/。这种解决方案比另一种解决方案更干净,尽管它仍然存在一个小故障,因为它可能会在其中一个框中留下额外的空白空间(一行的高度)。

【讨论】:

  • 这样好多了,但还是不行。如果您从其中一个框中删除线条,即使另一个框填充了文本,它也会使另一个框变小。 prntscr.com/6oks69(对不起我的英语不好)
  • @GINCHER 我认为这看起来比以前更干净,效果更好
猜你喜欢
  • 2018-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-26
  • 2021-09-15
  • 1970-01-01
相关资源
最近更新 更多