dqwh0108 2012-02-18 10: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 15: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()

    展开全部

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部