CKEDITOR.plugins.autocomplete.model
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
-
The query results — the items to be displayed in the autocomplete panel.
-
The callback executed by the model when requesting data. See CKEDITOR.plugins.autocomplete arguments.
-
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 : NumberCKEDITOR.plugins.autocomplete.model#itemsLimitIndicates the limit of items rendered in the dropdown.
For falsy values like
0ornullall items will be rendered.Defaults to
0-
The ID of the item currently selected in the panel.
-
The ID of the last request for data. Used by the setQuery method.
Static properties
Methods
constructor( dataCallback ) → modelCKEDITOR.plugins.autocomplete.model#constructorCreates the autocomplete model instance.
Parameters
dataCallback : FunctionSee CKEDITOR.plugins.autocomplete arguments.
Returns
model
capture()CKEDITOR.plugins.autocomplete.model#captureRegister event handler under the capturing stage on supported target.
define( name, meta )CKEDITOR.plugins.autocomplete.model#definePredefine some intrinsic properties on a specific event name.
Parameters
name : StringThe event name
meta : Object
fire( eventName, [ data ], [ editor ] ) → Boolean | ObjectCKEDITOR.plugins.autocomplete.model#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.autocomplete.model#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.
getIndexById( itemId ) → NumberCKEDITOR.plugins.autocomplete.model#getIndexByIdGets an index from the data array of the item by its ID.
Parameters
itemId : Number | String
Returns
Number
getItemById( itemId ) → itemCKEDITOR.plugins.autocomplete.model#getItemByIdhasData() → BooleanCKEDITOR.plugins.autocomplete.model#hasDatahasListeners( eventName ) → BooleanCKEDITOR.plugins.autocomplete.model#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
on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → ObjectCKEDITOR.plugins.autocomplete.model#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
10
Returns
ObjectAn object containing the
removeListenerfunction, which can be used to remove the listener at any time.
once()CKEDITOR.plugins.autocomplete.model#onceSimiliar with on but the listener will be called only once upon the next event firing.
removeAllListeners()CKEDITOR.plugins.autocomplete.model#removeAllListenersRemove all existing listeners on this object, for cleanup purpose.
removeListener( eventName, listenerFunction )CKEDITOR.plugins.autocomplete.model#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.
select( itemId )CKEDITOR.plugins.autocomplete.model#selectselectFirst()CKEDITOR.plugins.autocomplete.model#selectFirstSelects the first item. See also the select method.
selectLast()CKEDITOR.plugins.autocomplete.model#selectLastSelects the last item. See also the select method.
selectNext()CKEDITOR.plugins.autocomplete.model#selectNextselectPrevious()CKEDITOR.plugins.autocomplete.model#selectPrevioussetActive( isActive )CKEDITOR.plugins.autocomplete.model#setActivesetItem( itemId )CKEDITOR.plugins.autocomplete.model#setItemsetQuery( query, range )CKEDITOR.plugins.autocomplete.model#setQuerySets 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 : Stringrange : range
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
change-data( evt )CKEDITOR.plugins.autocomplete.model#change-datachange-isActive( evt )CKEDITOR.plugins.autocomplete.model#change-isActivechange-selectedItemId( evt )CKEDITOR.plugins.autocomplete.model#change-selectedItemId