Opened 13 years ago
Last modified 13 years ago
#8574 confirmed New Feature
Change contents of richcombo after init
Reported by: | Amund | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | General | Version: | 3.6.2 |
Keywords: | HasPatch | Cc: |
Description
I think richcombo plugin needs to be extended to support changing its contents after init has been run. This will enable developers to clientside refresh the list without loading the entire page where the editor is.
I have successfully done this with a bit of a hack in my own plugin that uses richcombo. In my code, I have a plugin that adds other plugins in the richcombo - e.g. insert link, insert image etc. This list may change due to userinput and it happens clientside.
How I solved it: (see http://stackoverflow.com/questions/7762810/is-it-possible-to-reinitialize-a-ckeditor-combobox-drop-down-menu/8397198#8397198
Some code: in the init function in ui.addRichCombo:
init: function () { var rebuildList = CKEDITOR.tools.bind(buildList, this); // bind the buildList function with this scope rebuildList(); // call once to do first build of list $(editor).bind('rebuildList', rebuildList); // bind with jquery so we can call it later },
then outside scope, define the buildList function:
var buildListHasRunOnce = 0; var buildList = function () { if (buildListHasRunOnce) { // Remove the old unordered list from the dom. // This is just to cleanup the old list within the iframe // Note that this removes all uls... if there are more than one editor on page, we have to be more specific on what to remove. In my production ready code, I target one of the lis, and find its ul parent and remove that instead of shotgunning all uls like in this example $(this._.panel._.iframe.$).contents().find("ul").remove(); // reset list this._.items = {}; this._.list._.items = {}; } for (var i in yourListOfItems) { var item = yourListOfItems[i]; // do your add calls this.add(item.id, 'something here as html', item.text); } if (buildListHasRunOnce) { // Force CKEditor to commit the html it generates through this.add this._.committed = 0; // We have to set to false in order to trigger a complete commit() this.commit(); } buildListHasRunOnce = 1; };
I´m thinking that it should be at least possible to
- Get a handle on the richCombo object when you add it with editor.ui.addRichCombo
- Be possible to call clearRichCombo
Alternatively:
- Add function remove
- Make it possible to call add after init. Currently you can, but it crashes the richCombos mark/unmarkall functions
Kind regards, Amund
Change History (3)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Keywords: | HasPatch added; richcombo removed |
---|---|
Status: | new → confirmed |
comment:3 Changed 13 years ago by
My code is not a patch, its just sample code to show how I was able to reinit the richcombo after init and supplied to give ckeditor developers some idea on how I had to hack my way around it. Maybe also give them ideas on what needs to be done.
By the way, you may also have to reset the pendingHtml array, I dont quite remember, but that´s details anyway.