CKEDITOR.plugins.copyformatting.state
Copy Formatting state object created for each CKEditor instance.
Filtering
Properties
-
editor : editor
CKEDITOR.plugins.copyformatting.state#editor
Editor reference.
-
filter : filter
CKEDITOR.plugins.copyformatting.state#filter
Filter used by the current Copy Formatting instance.
-
sticky : Boolean
CKEDITOR.plugins.copyformatting.state#sticky
-
styles : style[] | null
CKEDITOR.plugins.copyformatting.state#styles
Currently copied styles.
Static properties
Methods
-
constructor( editor ) → state
CKEDITOR.plugins.copyformatting.state#constructor
-
capture()
CKEDITOR.plugins.copyformatting.state#capture
Register event handler under the capturing stage on supported target.
-
define( name, meta )
CKEDITOR.plugins.copyformatting.state#define
Predefine some intrinsic properties on a specific event name.
Parameters
name : String
The event name
meta : Object
-
fire( eventName, [ data ], [ editor ] ) → Boolean | Object
CKEDITOR.plugins.copyformatting.state#fire
Fires 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 : String
The event name to fire.
[ data ] : Object
Data to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editor
The editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | Object
A boolean indicating that the event is to be canceled, or data returned by one of the listeners.
-
fireOnce( eventName, [ data ], [ editor ] ) → Boolean | Object
CKEDITOR.plugins.copyformatting.state#fireOnce
Fires 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 : String
The event name to fire.
[ data ] : Object
Data to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editor
The editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | Object
A booloan indicating that the event is to be canceled, or data returned by one of the listeners.
-
hasListeners( eventName ) → Boolean
CKEDITOR.plugins.copyformatting.state#hasListeners
Checks 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' ) ); // false
Parameters
eventName : String
The event name.
Returns
Boolean
-
on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → Object
CKEDITOR.plugins.copyformatting.state#on
Registers 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 called
Note: 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 : String
The event name to which listen.
listenerFunction : Function
The function listening to the event. A single CKEDITOR.eventInfo object instanced is passed to this function containing all the event data.
[ scopeObj ] : Object
The object used to scope the listener call (the
this
object). If omitted, the current object is used.[ listenerData ] : Object
Data to be sent as the CKEDITOR.eventInfo.listenerData when calling the listener.
[ priority ] : Number
The listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.
Defaults to
10
Returns
Object
An object containing the
removeListener
function, which can be used to remove the listener at any time.
-
once()
CKEDITOR.plugins.copyformatting.state#once
Similiar with on but the listener will be called only once upon the next event firing.
-
removeAllListeners()
CKEDITOR.plugins.copyformatting.state#removeAllListeners
Remove all existing listeners on this object, for cleanup purpose.
-
removeListener( eventName, listenerFunction )
CKEDITOR.plugins.copyformatting.state#removeListener
Unregisters 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 : String
The event name.
listenerFunction : Function
The listener function to unregister.
-
private
_isContextAllowed( testedContext ) → Boolean
CKEDITOR.plugins.copyformatting.state#_isContextAllowed
Checks if copying and applying styles in the current context is possible. See CKEDITOR.config.copyFormatting_allowedContexts for the list of possible context values.
Parameters
testedContext : String
Context name.
Returns
Boolean
true
if a given context is allowed in the current Copy Formatting instance.
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 : Object
The object into which implement the features.
Events
-
applyFormatting( evt )
CKEDITOR.plugins.copyformatting.state#applyFormatting
Fired when the copied styles are applied to the current selection position. This event listener job is to apply new styles.
editor.copyFormatting.on( 'applyFormatting', function( evt ) { for ( var i = 0; i < evt.data.styles.length; i++ ) { evt.data.styles[ i ].apply( evt.editor ); } }, null, null, 999 );
By default this event has two listeners: the first one with a default priority of
10
and the second with a priority of999
. The first one removes all preexisting styles from the Copy Formatting destination. The second one applies all new styles to the current selection.Parameters
evt : eventInfo
-
extractFormatting( evt )
CKEDITOR.plugins.copyformatting.state#extractFormatting
Fired when the styles are being extracted from the element. This event is fired for each element separately. This event listener job is to extract inline styles from the element and modify them if needed.
editor.copyFormatting.on( 'extractFormatting', function( evt ) { evt.data.styleDef.attributes.class = 'important'; } );
This event can also be canceled to indicate that styles from the current element should not be extracted.
editor.copyFormatting.on( 'extractFormatting', function( evt ) { if ( evt.data.element === 'div' ) { evt.cancel(); } } );
This event has a default listener with a default priority of
10
. It extracts all styles from the element (from some of the attributes and from the element name) and puts them as an object intoevt.data.styleDef
.Parameters
evt : eventInfo