ckeditor4.5以上使用行间距插件lineheight扩充

①从百度上下载一个 ckeditor 行距包,解压放到ckeditor/plugins目录下。

②在config.js 中添加

config.extraPlugins += (config.extraPlugins ? ‘,lineheight’ : ‘lineheight’);//行距

③(转载)

config.allowedContent = true; //加这个是为了不让span标签被ckeditor过滤掉,如果加了的话就不需要再加

  1. lineheight插件源码修改:
    1.原先的插件依赖于ckeditor/plugins/sytles插件,而ckeditor4.0是没有这个插件,所以如果直接使用该插件,会报错:
    Uncaught [CKEDITOR.resourceManager.load] Resource name “styles” was not found

因此,要修改插件中对styles的引用:

a.在lineheight目录下的plugin.js中:

CKEDITOR.plugins.add('lineheight', 
                   { 
                       lang: ['zh-cn'], 
   
   
                       requires : [ 'richcombo', 'styles'], 
   
   
   
                      init : function( editor ) 
   
                              ....... 
  中的requires: ['rechcombo', 'styles']            改为: requires: ['rechcombo']
  2.改完后使用,仍然会报错:
        Uncaught TypeError: Cannot read property 'editor' of undefined
       定位代码,在lineheight/plugin.js中:
editor.ui.addRichCombo( comboName,  
{label : lang.label,title: lang.panelTitle,className: 'cke_' + (styleType == 'size' ? 'fontSize' : 'font'),panel :{css : editor.skin.editor.css.concat( config.contentsCss ),multiSelect : false,attributes: { 'aria-label': lang.panelTitle }},  
  
init : function(){  
  
                           .......

报错地方: css : editor.skin.editor.css.concat( config.contentsCss )
这是最新的ckeditor获得css配置的方式与原先不同引起的,那么对应的改为:

css:  [CKEDITOR.skin.getPath("editor")].concat( config.contentsCss ), 

3.上述改动完成后就可以使用行距这个功能了,但是发现下拉框没有标题,但是lineheight/lang/zh-cn.js中配置了标题呀。。。原因是新的ckeditor调用标签的方式变了:
将/lineheight/plugin.js中下部分代码:

editor.ui.addRichCombo( comboName,{label : lang.label,title: lang.panelTitle,className: 'cke_' + (styleType == 'size' ? 'fontSize' : 'font'),panel :{css : [CKEDITOR.skin.getPath("editor")].concat( config.contentsCss ),multiSelect : false,attributes: { 'aria-label': lang.panelTitle }},  
  
init : function(){this.startGroup( lang.panelTitle );  

改为:

editor.ui.addRichCombo( comboName,{label : lang.lineheight.label,title: lang.lineheight.panelTitle,className: 'cke_' + (styleType == 'size' ? 'fontSize' : 'font'),panel :{css : [CKEDITOR.skin.getPath("editor")].concat( config.contentsCss ),multiSelect : false,attributes: { 'aria-label': lang.lineheight.panelTitle }},  
  
init : function(){this.startGroup( lang.lineheight.panelTitle );  

4.这样就完成了所有的配置了,当然如果想额外添加一些行距设置项,可以在/lineheight/plugin.js中添加,具体位置:

CKEDITOR.config.lineheight_sizes =                  'normal;1.5em;1.75em;2em;3em;4em;5em;100%;120%;130%;150%;170%;180%;190%;200%;220%;250%;300%;400%;500%';  

看到这个配置,你就会发现,这只是这个行距插件的默认配置值 ,那么如果要添加一些行距元素的话,可以在ckeditor的config.js中添加:

CKEDITOR.config.lineheight_sizes = CKEDITOR.config.lineheight_sizes +   ’你添加的行距元素‘;  

文章转载自https://www.cnblogs.com/zhb7769/p/10722376.html
怕以后设置的时候忘记,故做个记录,希望能帮助到网友

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值