Add placeholders after editor is initialized
Closed this issue · 7 comments
Hi
Is it possible to add/replace placeholders to the dropdown after the editor has been initialized?
If so, could you provide an example on how to do this?
Thanks,
Frank
There is no such functionality yet, no. I looked into this intially, but since I didn't needed it, I ditched it pretty fast when adding items to the button menu turned out to be overly complicated. Unfortunately CKEditor is lacking a clean, consistent, properly documented API for manipulations like that.
I am also interested in this feature: adding/removing placeholders in the list (or a way to hide/disable some of them).
Any hint on how to achieve this ?
Regards,
Ronan
Ok, I gave it another try, and I might have found something that would at least work for the combo
variant - it's kinda hackish however.
For reference, in case the dropdown wasn opened at least once, the panel must be created manually like
// cb is a RichCombo instance
cb.createPanel(editor);
then a new item can be added
cb.add('value', 'html', 'text');
and with a little more magic of commiting eiter on the hidden list object
cb._.list.commit();
or on the combobox instance itself, which however requires changing a hidden property
cb._.committed = false;
cb.commit();
it seems to be possible to add items to the box.
Once I have some more free time I'll check for a way to integrate this into the plugin, and make it recognize newly added items properly.
Hello ndm,
First of all, thank you for looking at it again.
That looks very promising !
I have to admit that I am a little lost now, and I would need further explanations to make it run. If you can improve the plugin, that would be really helpful.
Regards,
Ronan
Le 4 mars 2015 à 21:39, ndm2 notifications@github.com a écrit :
Ok, I gave it another try, and I might have found something that would at least work for the combo variant - it's kinda hackish however.
For reference, in case the dropdown wasn opened at least once, the panel must be created manually like
// cb is a RichCombo instance
cb.createPanel(editor);
then a new item can be addedcb.add('value', 'html', 'text');
and with a little more magic of commiting eiter on the hidden list objectcb._.list.commit();
or on the combobox instance itself, which however requires changing a hidden propertycb._.committed = false;
cb.commit();
it seems to be possible to add items to the box.Once I have some more free time I'll check for a way to integrate this into the plugin, and make it recognize newly added items properly.
—
Reply to this email directly or view it on GitHub #1 (comment).
You can find a first implementation in the dynamic-placeholders
branch, it will most probably be a little buggy, and there's still stuff subject to change, I'm especially not overly happy with the whole group handling stuff.
Anyways, so how does this work, well, the plugin exposes a property named placeholders
, holding an instance of PlaceholdersCollection
, which can be used to manage the placeholders. Changes made to this collection are automatically being applied to the editor/UI.
Here's an example:
var editorIdentifier = 'editor1'; // in most cases this is the ID or
// name of the DOM element replaced
// by the editor
var plugin = CKEDITOR.instances[editorIdentifier].plugins.placeholder_elements;
/** @type {PlaceholdersCollection} */
var placeholders = plugin.placeholders;
Add a new placeholder
var placeholder = {label: 'Foo', value: 'FOO'};
placeholders.add(placeholder);
Add a new placeholder to an existing group
var placeholder = {label: 'Foo', value: 'FOO', group: 'Bar'};
placeholders.addToGroup(placeholder);
Remove the third placeholder
placeholders.removeAt(2);
For more check out the source of the PlaceholdersCollection
class.
And please let me know in case you find any problems.
That looks perfect, I am going to test it and provide some feedback here.
Thanks again for taking this into account
Ronan
Closing as the dynamic placeholders functionality has been merged into master.