Report an issue
Class

CKEDITOR.plugins.autocomplete.model

class since 4.10.0 private

Class representing the autocomplete model.

In case you want to modify the model behavior, check out the CKEDITOR.plugins.autocomplete.view documentation. It contains examples of how to easily override the default behavior.

A model instance is created by the CKEDITOR.plugins.autocomplete.getModel method.

Note: This class is marked as private, which means that its API might be subject to change in order to provide further enhancements.

Filtering

Properties

  • data : item[]

    readonly

    The query results — the items to be displayed in the autocomplete panel.

  • dataCallback : Function

    readonly

    The callback executed by the model when requesting data. See CKEDITOR.plugins.autocomplete arguments.

  • isActive : Boolean

    readonly

    Whether the autocomplete is active (i.e. can receive user input like click, key press). Should be modified by the setActive method which fires the change-isActive event.

    Defaults to false

  • itemsLimit : Number

    Indicates the limit of items rendered in the dropdown.

    For falsy values like 0 or null all items will be rendered.

    Defaults to 0

  • query : String

    readonly

    The query string set by the setQuery method.

    The query string always has a corresponding range.

  • range : range

    readonly

    The range in the DOM where the query text is.

    The range always has a corresponding query. Both can be set by the setQuery method.

  • selectedItemId : Number | String

    readonly

    The ID of the item currently selected in the panel.

  • lastRequestId : Number

    private readonly

    The ID of the last request for data. Used by the setQuery method.

Static properties

Methods

  • constructor( dataCallback ) → model

    Creates the autocomplete model instance.

    Parameters

    dataCallback : Function

    See CKEDITOR.plugins.autocomplete arguments.

    Returns

    model
  • capture()

    Register event handler under the capturing stage on supported target.

  • define( name, meta )

    Predefine some intrinsic properties on a specific event name.

    Parameters

    name : String

    The event name

    meta : Object
    Properties
    [ errorProof ]

    Whether the event firing should catch error thrown from a per listener call.

    Defaults to false

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

  • getIndexById( itemId ) → Number

    Gets an index from the data array of the item by its ID.

    Parameters

    itemId : Number | String

    Returns

    Number
  • getItemById( itemId ) → item

    Gets the item from the data array by its ID.

    Parameters

    itemId : Number | String

    Returns

    item
  • hasData() → Boolean

    Whether the model contains non-empty data.

    Returns

    Boolean
  • 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
  • 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
    

    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.

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

  • select( itemId )

    Parameters

    itemId : Number | String
  • selectFirst()

    Selects the first item. See also the select method.

  • selectLast()

    Selects the last item. See also the select method.

  • selectNext()

    Selects the next item in the data array. If no item is selected, it selects the first one. If the last one is selected, it selects the first one.

    See also the select method.

  • selectPrevious()

    Selects the previous item in the data array. If no item is selected, it selects the last one. If the first one is selected, it selects the last one.

    See also the select method.

  • setActive( isActive )

    Sets the isActive property and fires the change-isActive event.

    Parameters

    isActive : Boolean
  • setItem( itemId )

    Sets the selectedItemId property.

    Parameters

    itemId : Number | String
  • setQuery( query, range )

    Sets the query and range and makes a request for the query results by executing the dataCallback function. When the data is returned (synchronously or asynchronously, because dataCallback exposes a callback function), the data property is set and the change-data event is fired.

    This method controls that only the response for the current query is handled.

    Parameters

    query : String
    range : range

Events