CKEDITOR.plugins.widget.repository
Widget repository. It keeps track of all registered widget definitions and initialized instances. An instance of the repository is available under the CKEDITOR.editor.widgets property.
Filtering
Properties
-
The editor instance for which this repository was created.
-
The focused widget instance. See also CKEDITOR.plugins.widget.focus and CKEDITOR.plugins.widget.blur events.
editor.on( 'selectionChange', function() { if ( editor.widgets.focused ) { // Do something when a widget is focused... } } ); -
An object containing initialized widget instances (widget id => CKEDITOR.plugins.widget).
Defaults to
{} -
A hash of registered widget definitions (definition name => CKEDITOR.plugins.widget.definition).
To register a definition use the add method.
Defaults to
{} -
-
readonly
widgetHoldingFocusedEditable : widgetCKEDITOR.plugins.widget.repository#widgetHoldingFocusedEditableThe widget instance that contains the nested editable which is currently focused.
-
private
MIN_SELECTION_CHECK_INTERVAL : NumberCKEDITOR.plugins.widget.repository#MIN_SELECTION_CHECK_INTERVAL
Static properties
Methods
-
constructor( editor ) → repositoryCKEDITOR.plugins.widget.repository#constructorCreates a widget repository instance. Note that the widget plugin automatically creates a repository instance which is available under the CKEDITOR.editor.widgets property.
Parameters
editor : editorThe editor instance for which the repository will be created.
Returns
repository
-
add( name, widgetDef ) → definitionCKEDITOR.plugins.widget.repository#addAdds a widget definition to the repository. Fires the CKEDITOR.editor.widgetDefinition event which allows to modify the widget definition which is going to be registered.
Parameters
name : StringThe name of the widget definition.
widgetDef : definitionWidget definition.
Returns
definition
-
addUpcastCallback( callback )CKEDITOR.plugins.widget.repository#addUpcastCallbackAdds a callback for element upcasting. Each callback will be executed for every element which is later tested by upcast methods. If a callback returns
false, the element will not be upcasted.// Images with the "banner" class will not be upcasted (e.g. to the image widget). editor.widgets.addUpcastCallback( function( element ) { if ( element.name == 'img' && element.hasClass( 'banner' ) ) return false; } );Parameters
callback : Function
-
capture()CKEDITOR.plugins.widget.repository#captureRegister event handler under the capturing stage on supported target.
-
checkSelection()CKEDITOR.plugins.widget.repository#checkSelectionChecks the selection to update widget states (selection and focus).
This method is triggered by the checkSelection event.
-
checkWidgets( [ options ] )CKEDITOR.plugins.widget.repository#checkWidgetsChecks if all widget instances are still present in the DOM. Destroys those instances that are not present. Reinitializes widgets on widget wrappers for which widget instances cannot be found. Takes nested widgets into account, too.
This method triggers the checkWidgets event whose listeners can cancel the method's execution or modify its options.
Parameters
[ options ] : ObjectThe options object.
-
define( name, meta )CKEDITOR.plugins.widget.repository#definePredefine some intrinsic properties on a specific event name.
Parameters
name : StringThe event name
meta : Object
-
del( widget )CKEDITOR.plugins.widget.repository#delRemoves the widget from the editor and moves the selection to the closest editable position if the widget was focused before.
Parameters
widget : widgetThe widget instance to be deleted.
-
destroy( widget, [ offline ] )CKEDITOR.plugins.widget.repository#destroyDestroys the widget instance and all its nested widgets (widgets inside its nested editables).
Parameters
widget : widgetThe widget instance to be destroyed.
[ offline ] : BooleanWhether the widget is offline (detached from the DOM tree) — in this case the DOM (attributes, classes, etc.) will not be cleaned up.
-
destroyAll( [ offline ], [ container ] )CKEDITOR.plugins.widget.repository#destroyAllDestroys all widget instances.
Parameters
[ offline ] : BooleanWhether the widgets are offline (detached from the DOM tree) — in this case the DOM (attributes, classes, etc.) will not be cleaned up.
[ container ] : elementThe container within widgets will be destroyed. This option will be ignored if the
offlineflag was set totrue, because in such case it is not possible to find widgets within the passed block.
-
finalizeCreation( container )CKEDITOR.plugins.widget.repository#finalizeCreationFinalizes a process of widget creation. This includes:
- inserting widget element into editor,
- marking widget instance as ready (see CKEDITOR.plugins.widget.ready),
- focusing widget instance.
This method is used by the default widget's command and is called after widget's dialog (if set) is closed. It may also be used in a customized process of widget creation and insertion.
widget.once( 'edit', function() { // Finalize creation only of not ready widgets. if ( widget.isReady() ) return; // Cancel edit event to prevent automatic widget insertion. evt.cancel(); CustomDialog.open( widget.data, function saveCallback( savedData ) { // Cache the container, because widget may be destroyed while saving data, // if this process will require some deep transformations. var container = widget.wrapper.getParent(); widget.setData( savedData ); // Widget will be retrieved from container and inserted into editor. editor.widgets.finalizeCreation( container ); } ); } );Parameters
container : element | documentFragmentThe element or document fragment which contains widget wrapper. The container is used, so before finalizing creation the widget can be freely transformed (even destroyed and reinitialized).
-
fire( eventName, [ data ], [ editor ] ) → Boolean | ObjectCKEDITOR.plugins.widget.repository#fireFires an specific event in the object. All registered listeners are called at this point.
someObject.on( 'someEvent', function() { ... } ); someObject.on( 'someEvent', function() { ... } ); someObject.fire( 'someEvent' ); // Both listeners are called. someObject.on( 'someEvent', function( event ) { alert( event.data ); // 'Example' } ); someObject.fire( 'someEvent', 'Example' );Parameters
eventName : StringThe event name to fire.
[ data ] : ObjectData to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editorThe editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | ObjectA boolean indicating that the event is to be canceled, or data returned by one of the listeners.
-
fireOnce( eventName, [ data ], [ editor ] ) → Boolean | ObjectCKEDITOR.plugins.widget.repository#fireOnceFires an specific event in the object, releasing all listeners registered to that event. The same listeners are not called again on successive calls of it or of fire.
someObject.on( 'someEvent', function() { ... } ); someObject.fire( 'someEvent' ); // Above listener called. someObject.fireOnce( 'someEvent' ); // Above listener called. someObject.fire( 'someEvent' ); // No listeners called.Parameters
eventName : StringThe event name to fire.
[ data ] : ObjectData to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editorThe editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | ObjectA booloan indicating that the event is to be canceled, or data returned by one of the listeners.
-
getByElement( element, [ checkWrapperOnly ] ) → widgetCKEDITOR.plugins.widget.repository#getByElementFinds a widget instance which contains a given element. The element will be the wrapper of the returned widget or a descendant of this wrapper.
editor.widgets.getByElement( someWidget.wrapper ); // -> someWidget editor.widgets.getByElement( someWidget.parts.caption ); // -> someWidget // Check wrapper only: editor.widgets.getByElement( someWidget.wrapper, true ); // -> someWidget editor.widgets.getByElement( someWidget.parts.caption, true ); // -> nullParameters
element : elementThe element to be checked.
[ checkWrapperOnly ] : BooleanIf set to
true, the method will not check wrappers' descendants.
Returns
widgetThe widget instance or
null.
-
hasListeners( eventName ) → BooleanCKEDITOR.plugins.widget.repository#hasListenersChecks if there is any listener registered to a given event.
var myListener = function() { ... }; someObject.on( 'someEvent', myListener ); alert( someObject.hasListeners( 'someEvent' ) ); // true alert( someObject.hasListeners( 'noEvent' ) ); // falseParameters
eventName : StringThe event name.
Returns
Boolean
-
initOn( element, [ widgetDef ], [ startupData ] ) → widgetCKEDITOR.plugins.widget.repository#initOnInitializes a widget on a given element if the widget has not been initialized on it yet.
Parameters
element : elementThe future widget element.
[ widgetDef ] : String | definitionName of a widget or a widget definition. The widget definition should be previously registered by using the add method.
[ startupData ] : ObjectWidget startup data (has precedence over default one).
Returns
widgetThe widget instance or
nullif a widget could not be initialized on a given element.
-
initOnAll( [ container ] ) → widget[]CKEDITOR.plugins.widget.repository#initOnAllInitializes widgets on all elements which were wrapped by wrapElement and have not been initialized yet.
Parameters
[ container ] : elementThe container which will be checked for not initialized widgets. Defaults to editor's editable element.
Defaults to
editor.editable()
Returns
widget[]Array of widget instances which have been initialized. Note: Only first-level widgets are returned — without nested widgets.
-
on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → ObjectCKEDITOR.plugins.widget.repository#onRegisters a listener to a specific event in the current object.
someObject.on( 'someEvent', function() { alert( this == someObject ); // true } ); someObject.on( 'someEvent', function() { alert( this == anotherObject ); // true }, anotherObject ); someObject.on( 'someEvent', function( event ) { alert( event.listenerData ); // 'Example' }, null, 'Example' ); someObject.on( 'someEvent', function() { ... } ); // 2nd called someObject.on( 'someEvent', function() { ... }, null, null, 100 ); // 3rd called someObject.on( 'someEvent', function() { ... }, null, null, 1 ); // 1st calledNote: CKEditor's event system has a limitation that one function cannot be used as a listener for the same event more than once. Hence, to reuse it with multiple listeners, it should be wrapped into additional wrapper function:
function listener( evt ) { ... }; someObject.on( 'someEvent', function() { listener(); } ); someObject.on( 'someEvent', function( evt ) { listener( evt ); } );Parameters
eventName : StringThe event name to which listen.
listenerFunction : FunctionThe function listening to the event. A single CKEDITOR.eventInfo object instanced is passed to this function containing all the event data.
[ scopeObj ] : ObjectThe object used to scope the listener call (the
thisobject). If omitted, the current object is used.[ listenerData ] : ObjectData to be sent as the CKEDITOR.eventInfo.listenerData when calling the listener.
[ priority ] : NumberThe listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.
Defaults to
10
Returns
ObjectAn object containing the
removeListenerfunction, which can be used to remove the listener at any time.
-
since 4.5.0
onWidget( widgetName, eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] )CKEDITOR.plugins.widget.repository#onWidgetAllows to listen to events on specific types of widgets, even if they are not created yet.
Please note that this method inherits parameters from the CKEDITOR.event.on method with one extra parameter at the beginning which is the widget name.
editor.widgets.onWidget( 'image', 'action', function( evt ) { // Event `action` occurs on `image` widget. } );Parameters
widgetName : StringeventName : StringlistenerFunction : Function[ scopeObj ] : Object[ listenerData ] : Object[ priority ] : Number-
Defaults to
10
-
once()CKEDITOR.plugins.widget.repository#onceSimiliar with on but the listener will be called only once upon the next event firing.
-
since 4.4.0
parseElementClasses( classes ) → ObjectCKEDITOR.plugins.widget.repository#parseElementClassesParses element classes string and returns an object whose keys contain class names. Skips all
cke_*classes.This method is used by the CKEDITOR.plugins.widget.getClasses method and may be used when overriding that method.
Parameters
classes : StringString (value of
classattribute).
Returns
ObjectObject containing classes or
nullif no classes found.
-
removeAllListeners()CKEDITOR.plugins.widget.repository#removeAllListenersRemove all existing listeners on this object, for cleanup purpose.
-
removeListener( eventName, listenerFunction )CKEDITOR.plugins.widget.repository#removeListenerUnregisters a listener function from being called at the specified event. No errors are thrown if the listener has not been registered previously.
var myListener = function() { ... }; someObject.on( 'someEvent', myListener ); someObject.fire( 'someEvent' ); // myListener called. someObject.removeListener( 'someEvent', myListener ); someObject.fire( 'someEvent' ); // myListener not called.Parameters
eventName : StringThe event name.
listenerFunction : FunctionThe listener function to unregister.
-
wrapElement( element, [ widgetName ] ) → element | elementCKEDITOR.plugins.widget.repository#wrapElementWraps an element with a widget's non-editable container.
If this method is called on an CKEDITOR.htmlParser.element, then it will also take care of fixing the DOM after wrapping (the wrapper may not be allowed in element's parent).
Parameters
element : element | elementThe widget element to be wrapped.
[ widgetName ] : StringThe name of the widget definition. Defaults to element's
data-widgetattribute value.
Returns
element | elementThe wrapper element or
nullif the widget definition of this name is not registered.
Static methods
-
Implements the CKEDITOR.event features in an object.
var myObject = { message: 'Example' }; CKEDITOR.event.implementOn( myObject ); myObject.on( 'testEvent', function() { alert( this.message ); } ); myObject.fire( 'testEvent' ); // 'Example'Parameters
targetObject : ObjectThe object into which implement the features.
Events
-
checkSelection( evt )CKEDITOR.plugins.widget.repository#checkSelectionAn event fired to trigger the selection check.
See the checkSelection method.
Parameters
evt : eventInfo
-
checkWidgets( evt )CKEDITOR.plugins.widget.repository#checkWidgetsAn event fired by the the checkWidgets method.
It can be canceled in order to stop the checkWidgets method execution or the event listener can modify the method's options.
Parameters
evt : eventInfo
-
instanceCreated( evt )CKEDITOR.plugins.widget.repository#instanceCreatedAn event fired when a widget instance is created, but before it is fully initialized.
Parameters
evt : eventInfo
-
instanceDestroyed( evt )CKEDITOR.plugins.widget.repository#instanceDestroyedAn event fired when a widget instance was destroyed.
See also CKEDITOR.plugins.widget.destroy.
Parameters
evt : eventInfo