LoginSignup
0

More than 5 years have passed since last update.

CKeditor: Richcomboプラグイン

Last updated at Posted at 2016-04-02

例:見出しプラグインの作成
Screen Shot 2016-04-03 at 00.07.04.png

コード:

CKEDITOR.plugins.add(PLUGIN_NAME,
{
  requires : ['richcombo'],
  init : function( editor )
  {
    var header_strings = [];
    header_strings.push(['0', 'なし', 'なし']);
    for(var i=2; i<=5 ; i++){
      header_strings.push(['h'+i, '<h'+i+'>見出し'+i+'</h'+i+'>', '<h'+i+'>見出し'+i+'</h'+i+'>']);
    }

    editor.ui.addRichCombo('header',
    {
      label:    '見出し',
      title:    '見出し',
      voiceLabel: '見出し',
      className:  'cke_format',
      multiSelect:false,
      panel:
      {
        css: [ editor.config.contentsCss, CKEDITOR.skin.getPath('editor') ],
        voiceLabel: editor.lang.panelVoiceLabel
      },

      init: function()
      {
        this.startGroup( "見出し" );
        for (var i in header_strings)
        {
          this.add(header_strings[i][0], header_strings[i][1], header_strings[i][2]);
        }
      },

      onClick: function( value )
      {
          // your code: process data
          editor.focus();
          editor.fire( 'saveSnapshot' );
          // your code: save data
          editor.fire( 'saveSnapshot' );
      }
    });
  }
});

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0