dqwh0108 2012-02-18 18:41
浏览 48
已采纳

ckeditor插件的代码片段?

Using CKeditor I want to provide an easy way to insert small amounts of html-code, from a combobox or similar. Is this possible w/o plugin or is there an existing plugin for this?

example:

Toolbar:[ ][ ] [comboBox] 
               |article image         | => (inserts <img src="aimage/{{id}}"/>
               |full-width-2col-table | => (inserts <table width="100%"><tr>..

( {{id}} will be replaced by ajax but that's another story...)

regards,

  • 写回答

1条回答 默认 最新

  • duanpo6079 2012-02-18 23:50
    关注

    I was working on a similar problem just a few days ago, so I stripped out a plugin I made.

    Create a folder in the CK plugins directory called "myinsert". Create a file called plugin.js and paste the following into it:

    CKEDITOR.plugins.add( 'myinsert',
    {
    init: function( editor )
    {
        editor.addCommand( 'insertMycode',
            {
                exec : function( editor )
                {    
                    var timestamp = new Date();
                    editor.insertHtml( 'Some Code Here.' );
                }
            });
    
    
        editor.ui.addButton( 'Mycode',
        {
            label: 'Insert Timestamp',
            command: 'insertMycode',
            icon: this.path + 'tag.gif'
        } );
    }
    } );
    

    You will have to include an icon in that directory, otherwise the button won't show up properly.

    Next, in your script to call your editor, place this: extraPlugins : 'myinsert', For example:

    <script type="text/javascript">
    CKEDITOR.replace( 'editor1', {
        extraPlugins : 'myinsert',
        toolbar : 'EditPost',
        uiColor : '#BBB',   
    }); 
    </script>
    

    Then just add the function name to your toolbar settings, wherever that may be.

        { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About', 'Mycode' ] }
    

    If you rename the function or folder, just make sure that they have to be the same name. Also, the name you put on the toolbar, has to match the name in editor.ui.addButton()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?