Log in or register to post comments
Last post
Custom drop down
Hi, I'd like to add a drop down that inserts some set text at the cursor location. Any pointers in how I could do that?

Thanks!

Kuba
Re: Custom drop down
OK, it took a little while but I worked something out. I've pasted it in below in case anyone needs something like it.

To make it work create a tokens folder in plugins, then save this in plugin.js.
Plugin.js:
CKEDITOR.plugins.add( 'tokens',
{   
   requires : ['richcombo'], //, 'styles' ],
   init : function( editor )
   {
      var config = editor.config,
         lang = editor.lang.format;

      // Gets the list of tags from the settings.
      var tags = []; //new Array();
      //this.add('value', 'drop_text', 'drop_label');
      tags[0]=["[contact_name]", "Name", "Name"];
      tags[1]=["[contact_email]", "email", "email"];
      tags[2]=["[contact_user_name]", "User name", "User name"];
      
      // Create style objects for all defined styles.

      editor.ui.addRichCombo( 'tokens',
         {
            label : "Insert tokens",
            title :"Insert tokens",
            voiceLabel : "Insert tokens",
            className : 'cke_format',
            multiSelect : false,

            panel :
            {
               css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
               voiceLabel : lang.panelVoiceLabel
            },

            init : function()
            {
               this.startGroup( "Tokens" );
               //this.add('value', 'drop_text', 'drop_label');
               for (var this_tag in tags){
                  this.add(tags[this_tag][0], tags[this_tag][1], tags[this_tag][2]);
               }
            },

            onClick : function( value )
            {         
               editor.focus();
               editor.fire( 'saveSnapshot' );
               editor.insertHtml(value);
               editor.fire( 'saveSnapshot' );
            }
         });
   }
});

Then to make the drop down appear you need to use the extraPugins option:
CKEDITOR.replace( 'editor_id',{
      toolbar :
      [
         ['tokens','Styles', 'Format', 'Bold', 'Italic'],['Undo','Redo']
      ],
      extraPlugins: 'tokens'
   }   
);
Re: Custom drop down
Hi Kuba,

could you post a screenshot? i followed the steps you described below, but no success...
Re: Custom drop down
Hi - sure, can do - what do you want a screen shot of specifically?

are you getting any errors?
Re: Custom drop down
I tried it, but it didn't work for me...so I was wondering how it is supposed to look

maybe i am missing something, so any additional info you can provide would be helpful.
Re: Custom drop down
Here's a screen shot :


Just realised slight problem with it if you put quotes in the html you want to paste - will have a think about that one.

Also if you are using a config file you need to do this:

config.extraPlugins = 'tokens';

Attachments: 

AttachmentSize
Screen shot13.43 KB
Re: Custom drop down
bingo! I got it to work...thanks :D
Re: Custom drop down
Thank you! Have been looking for a plugin like this for a long time!
Re: Custom drop down
Plug in works like a charm! Thank you Kuba!!!!
Re: Custom drop down
hi,
and did you need for example to reset it? i mean assign different tokens or even clear that list?
Re: Custom drop down
Hi

i'm trying to install this extra plugin but i'm having some trouble.

i have made the folder "tokens" and uploaded it to plugins. pasted the code into the plugins.js.

My "config.js" file looks like this
CKEDITOR.editorConfig = function( config )
{

   config.toolbar = 'MyToolbar';

   config.toolbar_MyToolbar =
   [
       ['Source','-','NewPage','Preview'],
       ['Cut','Copy','Paste','PasteText','PasteFromWord'],
       ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
       ['Link','Unlink','Anchor'],
       ['Image','Flash','Table','HorizontalRule','SpecialChar'],
          '/',
       ['NumberedList','BulletedList'],
       ['Subscript','Superscript'],
       ['Bold','Italic','Underline','Strike','-','Format','FontSize','-','TextColor','BGColor'],
       ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','Outdent','Indent','tokens']
   ];
      
   config.contentsCss = '/admin/styles/editor.css';
   
   config.enterMode = CKEDITOR.ENTER_BR;
   
   config.extraPlugins = 'tokens';
   
   config.width = '99%';
   config.height = '400px';
   config.resize_enabled = true;
   config.toolbarCanCollapse = false;
   config.undoStackSize = 50;
};


And my editor looks like this
<textarea name="Brev"></textarea>
   
<script type="text/javascript">
   CKEDITOR.replace( 'Brev',
       {
           toolbar : 'MyToolbar',           
           extraPlugins : 'tokens',
       }
    );
</script>


I get an error that looks like this:
Message: 'onLoad' is null or not an object
Line: 20
Sign: 1557
Kode: 0
URI: admin/ckeditor/ckeditor.js

What am i doing wrong?
Re: Custom drop down
I'm trying to get this to work with VALUES that contain single quotes.

It fails at insertHtml, which ends up trying to send something containing a single quote in the middle:
javascript:void('[hot dog's buns]')
I end up with a syntax error in CKEDITOR.tools.callFunction(187).


I've tried to replace any single quotes with escaped single quotes in various spots, without success.
var badstring = "'";
var goodstring = "\'";
tags[i]=["[" + sample[i].replace(badstring,goodstring) + "]", sample[i], sample[i];


I tried to do the replace inside the insertHtml() call:
editor.insertHtml(value.replace(/'/g,"\'"));
no luck.


If I try to double-escape the single quote...
var badstring = "'";
var goodstring = "\\'";
tags[i]=["[" + sample[i].replace(badstring,goodstring) + "]", sample[i], sample[i];
it looks promising...
javascript:void('[hot dog/'s buns]')
but just fails and throws this error:
TypeError: o is null
ckeditor.js, line 149



Any suggestions?