Report an issue
Class

CKEDITOR.plugins.notificationAggregator

class since 4.5.0

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

  • readonly

    editor : editor

  • readonly

    notification : notification | null

    Notification created by the aggregator.

    The notification object is modified as aggregator tasks are being closed.

  • private

    _doneTasks : Number

    Stores the count of tasks done.

  • private

    _doneWeights : Number

    Stores the sum of done weights for all contained tasks.

  • private

    _message : template

    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).
  • private

    _singularMessage : template | null

    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.

  • private

    _tasks : task[]

    Array of tasks tracked by the aggregator.

  • private

    _totalWeights : Number

    Stores the sum of declared weights for all contained tasks.

Static properties

Methods

  • constructor( editor, message, [ singularMessage ] ) → notificationAggregator

    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. If null, then the message template will be used.

    Defaults to null

    Returns

    notificationAggregator
  • capture()

    Register event handler under the capturing stage on supported target.

  • createTask( [ options ] ) → task

    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 )

    Predefine some intrinsic properties on a specific event name.

    Parameters

    name : String

    The event name

    meta : Object
  • fire( eventName, [ data ], [ editor ] ) → Boolean | Object

    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

    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

    Returns

    Number

    Returns the number of tasks done.

  • getPercentage() → Number

    Returns a number from 0 to 1 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 to 1.

  • getTaskCount() → Number

    Returns

    Number

    Returns a total tasks count.

  • hasListeners( eventName ) → Boolean

    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

    Returns

    Boolean

    Returns true if all notification tasks are done (or there are no tasks at all).

  • on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → Object

    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()

    Similiar with on but the listener will be called only once upon the next event firing.

    CKEDITOR.event.on

  • removeAllListeners()

    Remove all existing listeners on this object, for cleanup purpose.

  • removeListener( eventName, listenerFunction )

    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()

    Triggers an update on the aggregator, meaning that its UI will be refreshed.

    When all the tasks are done, the finished event is fired.

  • private

    _addTask( options ) → task

    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

    Creates a notification object.

    Returns

    notification
  • private

    _getNotificationMessage() → String

    Returns a message used in the notification.

    Returns

    String
  • private

    _onTaskDone( evt )

    A listener called on the CKEDITOR.plugins.notificationAggregator.task.done event.

    Parameters

    evt : eventInfo

    Event object of the CKEDITOR.plugins.notificationAggregator.task.done event.

  • private

    _onTaskUpdate( evt )

    A listener called on the CKEDITOR.plugins.notificationAggregator.task.update event.

    Parameters

    evt : eventInfo

    Event object of the CKEDITOR.plugins.notificationAggregator.task.update event.

  • private

    _removeTask( task )

    Removes a given task from the _tasks array and updates the UI.

    Parameters

    task : task

    Task to be removed.

  • private

    _updateNotification()

    Updates the notification content.

Static methods

  • mixed static

    implementOn( targetObject )

    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 )

    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