简体   繁体   English

预加载CKEditor资产

[英]Pre-load CKEditor assets

I'm using CKEditor inline feature. 我正在使用CKEditor内联功能。 I initiate a new editor instance every time the user hovers over a text area. 每次用户将鼠标悬停在文本区域上时,我都会启动一个新的编辑器实例。 The problem is that when the user hovers and focuses on a textarea for the first time, the editor toolbar takes a couple of seconds to appear because the editor is loading all the necessary assets. 问题是,当用户第一次悬停并专注于textarea时,编辑器工具栏需要几秒钟才能显示,因为编辑器正在加载所有必需的资源。

My question is: How can I pre-load all the necessary CKEditor assets during an onclick event instead of when the user hovers a text area? 我的问题是:如何在onclick事件期间预加载所有必需的CKEditor资产,而不是在用户悬停文本区域时?

I tried adding all the assets in the HTML file and the editor appears instantly, however when I look at the DOM, the file assets are sourced twice. 我尝试在HTML文件中添加所有资源,然后编辑器立即出现,但是当我查看DOM时,文件资产的来源是两次。 Meaning even when the files are already present, CKEditor still loads them. 即使文件已经存在,CKEditor仍会加载它们。

You could go ahead and initialize the instances of the editor normally, but set visibility of the toolbar header and footer to hidden and reduce their height to 0. Then on hover you'll set the height to auto, and visibility to visible. 您可以继续正常初始化编辑器的实例,但将工具栏页眉和页脚的visibility设置为隐藏,并将其height降低为0.然后在悬停时,您将height设置为auto,并将visibility为可见。

CKE Editor Javascript adds inline styles for height on the toolbar, so you'll need the !important declaration on the height. CKE编辑器Javascript在工具栏上添加了高度的内联样式,因此您需要在高度上使用!important声明。

https://jsfiddle.net/ucytmjj5/4/ https://jsfiddle.net/ucytmjj5/4/

span.cke_top,
span.cke_bottom {
  visibility: hidden;
  height: 0px !important;
}

div.cke:hover span.cke_top,
div.cke:hover span.cke_bottom {
  visibility: visible;
  height: auto !important;
}

You can instantiate a dummy editor on page onload or onclick . 您可以在页面onloadonclick上实例化一个虚拟编辑器。 Keep dummy editor hidden using display: none . 使用display: none保持虚拟编辑器隐藏。 When your dummy editor is loaded, it will load all the assets and next time when you display the editor it won't reload the assets. 加载虚拟编辑器后,它将加载所有资源,下次显示编辑器时,它将不会重新加载资源。 Simple! 简单!

You could try showing the text area after CKEDITOR instance has been created. 您可以在创建CKEDITOR实例后尝试显示文本区域。 For example. 例如。

 CKEDITOR.on('instanceCreated', function(evt) { evt.editor.element.setStyle("display", "block"); }); CKEDITOR.replace('editor1'); 
 #editor1 { display: none; } 
 <script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script> <textarea id="editor1"></textarea> 

You could reuse the same instance of the editor every time, but replace the editor's text with the value of textarea that the user hovers over. 您可以每次都重复使用相同的编辑器实例,但将编辑器的文本替换为用户悬停的textarea值。 That way the editor will only load once and be reused. 这样编辑器只会加载一次并重复使用。

Try using CDN versions of the assets, if it fixes your problem then it may be a server issue. 尝试使用CDN版本的资产,如果它修复了您的问题,那么它可能是服务器问题。

If you are using assets from a server that doesn't have cache policies or policies that don't let the browser cache, the browser may be downloading these files more than once. 如果您使用的服务器中的资产没有缓存策略或不允许浏览器缓存的策略,则浏览器可能会多次下载这些文件。

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

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