简体   繁体   English

在ckeditor中切换实时预览

[英]Toggle live preview in ckeditor

I am using jquery adapter for ckeditor, I am able to add custom css files in editor preview using CKEDITOR.config.contentsCss Below is embedded javascript code to create ckeditor for textarea with #editor2 ID. 我正在使用jquery适配器用于ckeditor,我可以使用CKEDITOR.config.contentsCss在编辑器预览中添加自定义css文件。下面是嵌入式javascript代码,用#editor2 ID为textarea创建ckeditor。

jQuery(function()
{
  var config = {
  contentsCss :['css/bootsrap/bootstrap.css', 'contents-custom.css'],
}
jQuery('#editor2').ckeditor(config);

I want to create a plugin which may be call "live preview" on click of this button these CSS files will be added. 我想创建一个插件,可以在点击此按钮时调用“实时预览”,这些CSS文件将被添加。 This button should be like toggle. 这个按钮应该像切换一样。

My question is, How can I control the config from adding and deleting contentCss configuration? 我的问题是,如何通过添加和删除contentCss配置来控制配置?

With jQuery, you'll be able to trick the page. 使用jQuery,您将能够欺骗页面。 I don't think there's a known way for doing that with CKEditor's API. 我不认为使用CKEditor的API可以做到这一点。 But, you can delete the <link> your files. 但是,您可以删除<link>您的文件。

//to remove styling:
$('#cke_ckeditor iframe').contents().find('html head link').remove();
//to reload CSS:
$('#cke_ckeditor iframe').contents().find('html head').append('<link href="customContents.css" rel="stylesheet" type="text/css" />');

If you want, you can control which file will be removed by removing only the first() or the last() link, as well in the reloading snippet. 如果需要,您可以通过仅删除第first()last()链接以及重新加载代码段来控制将删除哪个文件。

Good luck! 祝好运!

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

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