CKEDITOR.plugins.notificationAggregator
An aggregator of multiple tasks (progresses) which should be displayed using one notification.
Once all the tasks are done, it means that the whole process is finished and the finished event will be fired.
New tasks can be created after the previous set of tasks is finished. This will continue the process and fire the finished event again when it is done.
Simple usage example:
// Declare one aggregator that will be used for all tasks.
var aggregator;
// ...
// Create a new aggregator if the previous one finished all tasks.
if ( !aggregator || aggregator.isFinished() ) {
// Create a new notification aggregator instance.
aggregator = new CKEDITOR.plugins.notificationAggregator( editor, 'Loading process, step {current} of {max}...' );
// Change the notification type to 'success' on finish.
aggregator.on( 'finished', function() {
aggregator.notification.update( { message: 'Done', type: 'success' } );
} );
}
// Create 3 tasks.
var taskA = aggregator.createTask(),
taskB = aggregator.createTask(),
taskC = aggregator.createTask();
// At this point the notification contains a message: "Loading process, step 0 of 3...".
// Let's close the first one immediately.
taskA.done(); // "Loading process, step 1 of 3...".
// One second later the message will be: "Loading process, step 2 of 3...".
setTimeout( function() {
taskB.done();
}, 1000 );
// Two seconds after the previous message the last task will be completed, meaning that
// the notification will be closed.
setTimeout( function() {
taskC.done();
}, 3000 );
Filtering
Properties
-
Notification created by the aggregator.
The notification object is modified as aggregator tasks are being closed.
-
Stores the count of tasks done.
-
Stores the sum of done weights for all contained tasks.
-
A template for the notification message.
The template can use the following variables:
{current}
– The number of completed tasks.{max}
– The number of tasks.{percentage}
– The progress (number 0-100).
-
A template for the notification message used when only one task is loading.
Sometimes there might be a need to specify a special message when there is only one task loading, and to display standard messages in other cases.
For example, you might want to show a message "Translating a widget" rather than "Translating widgets (1 of 1)", but still you would want to have a message "Translating widgets (2 of 3)" if more widgets are being translated at the same time.
Template variables are the same as in _message.
-
Array of tasks tracked by the aggregator.
-
Stores the sum of declared weights for all contained tasks.
Static properties
Methods
-
constructor( editor, message, [ singularMessage ] ) → notificationAggregator
CKEDITOR.plugins.notificationAggregator#constructor
Creates a notification aggregator instance.
Parameters
editor : editor
message : String
The template for the message to be displayed in the notification. The template can use the following variables:
{current}
– The number of completed tasks.{max}
– The number of tasks.{percentage}
– The progress (number 0-100).
[ singularMessage ] : String | null
An optional template for the message to be displayed in the notification when there is only one task remaining. This template can use the same variables as the
message
template. Ifnull
, then themessage
template will be used.Defaults to
null
Returns
notificationAggregator
-
capture()
CKEDITOR.plugins.notificationAggregator#capture
Register event handler under the capturing stage on supported target.
-
createTask( [ options ] ) → task
CKEDITOR.plugins.notificationAggregator#createTask
Creates a new task that can be updated to indicate the progress.
Parameters
[ options ] : Object
Options object for the task creation.
Returns
task
An object that represents the task state, and allows for its manipulation.
-
define( name, meta )
CKEDITOR.plugins.notificationAggregator#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.notificationAggregator#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.notificationAggregator#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.
-
getDoneTaskCount() → Number
CKEDITOR.plugins.notificationAggregator#getDoneTaskCount
-
getPercentage() → Number
CKEDITOR.plugins.notificationAggregator#getPercentage
Returns a number from
0
to1
representing the done weights to total weights ratio (showing how many of the tasks are done).Note: For an empty aggregator (without any tasks created) it will return
1
.Returns
Number
Returns the percentage of tasks done as a number ranging from
0
to1
.
-
getTaskCount() → Number
CKEDITOR.plugins.notificationAggregator#getTaskCount
-
hasListeners( eventName ) → Boolean
CKEDITOR.plugins.notificationAggregator#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
-
isFinished() → Boolean
CKEDITOR.plugins.notificationAggregator#isFinished
Returns
Boolean
Returns
true
if all notification tasks are done (or there are no tasks at all).
-
on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → Object
CKEDITOR.plugins.notificationAggregator#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.notificationAggregator#once
Similiar with on but the listener will be called only once upon the next event firing.
-
removeAllListeners()
CKEDITOR.plugins.notificationAggregator#removeAllListeners
Remove all existing listeners on this object, for cleanup purpose.
-
removeListener( eventName, listenerFunction )
CKEDITOR.plugins.notificationAggregator#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.
-
update()
CKEDITOR.plugins.notificationAggregator#update
Triggers an update on the aggregator, meaning that its UI will be refreshed.
When all the tasks are done, the finished event is fired.
-
Creates a CKEDITOR.plugins.notificationAggregator.task instance based on
options
, and adds it to the task list.Parameters
options : Object
Options object coming from the createTask method.
Returns
task
-
private
_createNotification() → notification
CKEDITOR.plugins.notificationAggregator#_createNotification
-
private
_getNotificationMessage() → String
CKEDITOR.plugins.notificationAggregator#_getNotificationMessage
-
A listener called on the CKEDITOR.plugins.notificationAggregator.task.done event.
Parameters
evt : eventInfo
Event object of the CKEDITOR.plugins.notificationAggregator.task.done event.
-
A listener called on the CKEDITOR.plugins.notificationAggregator.task.update event.
Parameters
evt : eventInfo
Event object of the CKEDITOR.plugins.notificationAggregator.task.update event.
-
Removes a given task from the _tasks array and updates the UI.
Parameters
task : task
Task to be removed.
-
Updates the notification content.
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
-
finished( evt )
CKEDITOR.plugins.notificationAggregator#finished
Fired when all tasks are done. When this event occurs, the notification may change its type to
success
or be hidden:aggregator.on( 'finished', function() { if ( aggregator.getTaskCount() == 0 ) { aggregator.notification.hide(); } else { aggregator.notification.update( { message: 'Done', type: 'success' } ); } } );
Parameters
evt : eventInfo