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 ] ) → notificationAggregatorCKEDITOR.plugins.notificationAggregator#constructorCreates a notification aggregator instance.
Parameters
editor : editormessage : StringThe 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 | nullAn 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
messagetemplate. Ifnull, then themessagetemplate will be used.Defaults to
nullReturns
notificationAggregator
capture()CKEDITOR.plugins.notificationAggregator#captureRegister event handler under the capturing stage on supported target.
createTask( [ options ] ) → taskCKEDITOR.plugins.notificationAggregator#createTaskCreates a new task that can be updated to indicate the progress.
Parameters
[ options ] : ObjectOptions object for the task creation.
Returns
taskAn object that represents the task state, and allows for its manipulation.
define( name, meta )CKEDITOR.plugins.notificationAggregator#definePredefine some intrinsic properties on a specific event name.
Parameters
name : StringThe event name
meta : Objectfire( eventName, [ data ], [ editor ] ) → Boolean | ObjectCKEDITOR.plugins.notificationAggregator#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.notificationAggregator#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.
getDoneTaskCount() → NumberCKEDITOR.plugins.notificationAggregator#getDoneTaskCountReturns
NumberReturns the number of tasks done.
getPercentage() → NumberCKEDITOR.plugins.notificationAggregator#getPercentageReturns a number from
0to1representing 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
NumberReturns the percentage of tasks done as a number ranging from
0to1.getTaskCount() → NumberCKEDITOR.plugins.notificationAggregator#getTaskCountReturns
NumberReturns a total tasks count.
hasListeners( eventName ) → BooleanCKEDITOR.plugins.notificationAggregator#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
isFinished() → BooleanCKEDITOR.plugins.notificationAggregator#isFinishedReturns
BooleanReturns
trueif all notification tasks are done (or there are no tasks at all).on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → ObjectCKEDITOR.plugins.notificationAggregator#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
10Returns
ObjectAn object containing the
removeListenerfunction, which can be used to remove the listener at any time.once()CKEDITOR.plugins.notificationAggregator#onceSimiliar with on but the listener will be called only once upon the next event firing.
removeAllListeners()CKEDITOR.plugins.notificationAggregator#removeAllListenersRemove all existing listeners on this object, for cleanup purpose.
removeListener( eventName, listenerFunction )CKEDITOR.plugins.notificationAggregator#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.
update()CKEDITOR.plugins.notificationAggregator#updateTriggers 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 : ObjectOptions object coming from the createTask method.
Returns
task
private
_createNotification() → notificationCKEDITOR.plugins.notificationAggregator#_createNotificationprivate
_getNotificationMessage() → StringCKEDITOR.plugins.notificationAggregator#_getNotificationMessageA listener called on the CKEDITOR.plugins.notificationAggregator.task.done event.
Parameters
evt : eventInfoEvent object of the CKEDITOR.plugins.notificationAggregator.task.done event.
A listener called on the CKEDITOR.plugins.notificationAggregator.task.update event.
Parameters
evt : eventInfoEvent object of the CKEDITOR.plugins.notificationAggregator.task.update event.
Removes a given task from the _tasks array and updates the UI.
Parameters
task : taskTask 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 : ObjectThe object into which implement the features.
Events
finished( evt )CKEDITOR.plugins.notificationAggregator#finishedFired when all tasks are done. When this event occurs, the notification may change its type to
successor be hidden:aggregator.on( 'finished', function() { if ( aggregator.getTaskCount() == 0 ) { aggregator.notification.hide(); } else { aggregator.notification.update( { message: 'Done', type: 'success' } ); } } );Parameters
evt : eventInfo