I have some widgets created, they on initial startup they load fine, but i add more of this type of widget to the editor through:
ckeditorInstance.insertElement(
CKEDITOR.dom.element.createFromHtml('<html></html>'));
It inserts just fine, but the ckeditor does not recognize the element inserted as a widget, so the widget editable fields are not getting enabled like they should.
Is there any way to make ckeditor do a rescan of its content to initialize any new widgets that it has not already initialized?
First of all - there's a separation for data format of a widget (how widget is represented in data) and internal format (how it is represented in editor). You may be familiar with the upcast and downcast functions - they make the transition between those formats (upcasting means transforming data format to internal format).
Upcasting and downcasting work only if data string is processed, but if you insert content using editor#insertElement
there's no processing, so there's no upcasting.
You've got two solutions:
Use editor#insertHtml
instead of editor#insertElement
. Your widget will be upcasted before insertion, so it will be inserted in a good format.
Take care of upcasting (if needed) yourself and use editor#insertElement
.
This was a first step of widget's life - it has to be inserted. Second is to be initialized.
There's a bug currently (it will be fixed in two weeks), that widgets inserted by the insertHtml
method are not initialized. So, at this moment, after inserting widget with editor#insertHtml
you need to call:
editor.widgets.checkWidgets()
If you use editor#insertElement
you need to take care of initializing widget. To do that call:
editor.widgets.initOn( element, 'widgetName' )
In both scenarios initialize widget after inserting it.
Check out the Widgets API for more details.
See also my answer explaining how to know if an element is a widget and how to insert them into editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With