|
256 | 256 | /**
|
257 | 257 | * Checks if all widget instances are still present in the DOM.
|
258 | 258 | * Destroys those instances that are not present.
|
| 259 | + * Reinitializes widgets on widget wrappers for which widget instances |
| 260 | + * cannot be found. |
259 | 261 | *
|
260 | 262 | * This method is triggered by the {@link #event-checkWidgets} event.
|
261 | 263 | */
|
262 | 264 | checkWidgets: function() {
|
263 | 265 | if ( this.editor.mode != 'wysiwyg' )
|
264 | 266 | return;
|
265 | 267 |
|
266 |
| - var toBeDestroyed = [], |
267 |
| - editable = this.editor.editable(), |
| 268 | + var editable = this.editor.editable(), |
268 | 269 | instances = this.instances,
|
269 |
| - id; |
| 270 | + i, count, wrapper; |
270 | 271 |
|
271 | 272 | if ( !editable )
|
272 | 273 | return;
|
273 | 274 |
|
274 |
| - for ( id in instances ) { |
275 |
| - if ( !editable.contains( instances[ id ].wrapper ) ) |
276 |
| - this.destroy( instances[ id ], true ); |
| 275 | + // Remove widgets which have no corresponding elements in DOM. |
| 276 | + for ( i in instances ) { |
| 277 | + if ( !editable.contains( instances[ i ].wrapper ) ) |
| 278 | + this.destroy( instances[ i ], true ); |
| 279 | + } |
| 280 | + |
| 281 | + var wrappers = editable.find( '.cke_widget_wrapper' ); |
| 282 | + |
| 283 | + // Create widgets on existing wrappers if they do not exists. |
| 284 | + for ( i = 0, count = wrappers.count(); i < count; i++ ) { |
| 285 | + wrapper = wrappers.getItem( i ); |
| 286 | + |
| 287 | + if ( !this.getByElement( wrapper, true ) ) { |
| 288 | + // Add cke_widget_new class because otherwise |
| 289 | + // widget will not be created on such wrapper. |
| 290 | + wrapper.addClass( 'cke_widget_new' ); |
| 291 | + this.initOn( wrapper.getFirst( isWidgetElement2 ) ); |
| 292 | + } |
277 | 293 | }
|
278 | 294 | },
|
279 | 295 |
|
|
416 | 432 | * Initializes a widget on a given element if the widget has not been initialized on it yet.
|
417 | 433 | *
|
418 | 434 | * @param {CKEDITOR.dom.element} element The future widget element.
|
419 |
| - * @param {String/CKEDITOR.plugins.widget.definition} widgetDef Name of a widget or a widget definition. |
| 435 | + * @param {String/CKEDITOR.plugins.widget.definition} [widgetDef] Name of a widget or a widget definition. |
420 | 436 | * The widget definition should be previously registered by using the
|
421 | 437 | * {@link CKEDITOR.plugins.widget.repository#add} method.
|
422 | 438 | * @param [startupData] Widget startup data (has precedence over default one).
|
|
2154 | 2170 | // * keyup.
|
2155 | 2171 | function setupWidgetsObserver( widgetsRepo ) {
|
2156 | 2172 | var editor = widgetsRepo.editor,
|
2157 |
| - buffer = CKEDITOR.tools.eventsBuffer( widgetsRepo.MIN_WIDGETS_CHECK_INTERVAL, function() { |
2158 |
| - widgetsRepo.fire( 'checkWidgets' ); |
2159 |
| - } ), |
| 2173 | + buffer = CKEDITOR.tools.eventsBuffer( widgetsRepo.MIN_WIDGETS_CHECK_INTERVAL, checkWidgets ), |
2160 | 2174 | ignoredKeys = { 16:1,17:1,18:1,37:1,38:1,39:1,40:1,225:1 }; // SHIFT,CTRL,ALT,LEFT,UP,RIGHT,DOWN,RIGHT ALT(FF)
|
2161 | 2175 |
|
2162 | 2176 | editor.on( 'contentDom', function() {
|
|
2172 | 2186 | editor.on( 'contentDomUnload', buffer.reset );
|
2173 | 2187 |
|
2174 | 2188 | widgetsRepo.on( 'checkWidgets', widgetsRepo.checkWidgets, widgetsRepo );
|
| 2189 | + |
| 2190 | + editor.on( 'contentDomInvalidated', checkWidgets ); |
| 2191 | + |
| 2192 | + function checkWidgets() { |
| 2193 | + widgetsRepo.fire( 'checkWidgets' ); |
| 2194 | + } |
2175 | 2195 | }
|
2176 | 2196 |
|
2177 | 2197 | // Helper for coordinating which widgets should be
|
|
0 commit comments