简体   繁体   English

CKEditor:如何在自定义插件中为iframe对话框添加图形预加载器?

[英]CKEditor: How do I add a graphic preloader for an iframe dialog in a custom plugin?

I have created a CKEditor (4.4.4) plugin that utilizes an iframedialog element. 我创建了一个使用iframedialog元素的CKEditor(4.4.4)插件。 The issue I'm having is that the contents of the iframe in the dialog (properties) editor can take several seconds to load. 我遇到的问题是,对话框(属性)编辑器中iframe的内容可能需要花费几秒钟来加载。 In the meantime, the user is just sitting there wondering where the UI is until it magically appears. 同时,用户只是坐在那里想知道UI的位置,直到它神奇地出现为止。

Ideally, I would like to hide the iframe while it loads, display a preloader graphic, and hide the graphic and display the iframe after it loads. 理想情况下,我想在加载iframe时隐藏iframe,显示预加载器图形,并在加载后隐藏图形并显示iframe。

I've looked into using the "setup" and "onContentLoad" functions of the element definition to handle this, I can't seem to find a way to get it working. 我已经研究过使用元素定义的“ setup”和“ onContentLoad”函数来处理此问题,我似乎找不到找到使它起作用的方法。 I also (unsuccessfully) looked into making changes to plugins/iframedialog/plugin.js directly, but I would like to avoid doing that if possible. 我也(未成功)研究了直接更改plugins / iframedialog / plugin.js的方法,但我想避免这样做。

Turns out " setup " was the wrong thing to use. 原来“ 设置 ”是使用错误的东西。 " onShow " was what I was looking for. onShow ”是我想要的。

Here's how I accomplished this: 这是我的完成方式:

onShow: function (e) {
    var iframeId = this._.frameId;
    loader = setTimeout(function () {
        $("#" + iframeId).hide();
        $("#" + iframeId).after("<div id='" + iframeId + "-loader' class='preloader-small'></div>");
    }, 250);
},

onContentLoad: function () {
    clearTimeout(loader);
    $("#" + this._.frameId + "-loader").hide();
    $("#" + this._.frameId).show();
}

I had to use setTimeout or else it didn't work at all. 我必须使用setTimeout,否则它根本不起作用。 I could set it as low as "1" and it would still work, but I opted for a higher number so a speedy/cached load wouldn't display the graphic. 我可以将其设置为“ 1”,它仍然可以工作,但是我选择了更大的数字,因此快速/缓存的加载不会显示图形。

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

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