About

TextExtPlugin is a base class for all plugins. It provides common methods which are reused by majority of plugins.

All plugins must register themselves by calling the $.fn.textext.addPlugin(name, constructor) function while providing plugin name and constructor. The plugin name is the same name that user will identify the plugin in the plugins option when initializing TextExt component and constructor function will create a new instance of the plugin. Without registering, the core won’t be able to see the plugin.

new in 1.2.0 You can get instance of each plugin from the core via associated function with the same name as the plugin. For example:

$('#input').textext()[0].tags()
$('#input').textext()[0].autocomplete()
...

Methods

TextExtPlugin.baseInit(core, defaults)

  • core {TextExt} Instance of the TextExt core class.

  • defaults {Object} Default plugin options. These will be checked if desired value wasn’t found in the options supplied by the user.

Initialization method wich should be called by the plugin during the init() call.

TextExtPlugin.bind(event, handler)

  • event {String} Event name.

  • handler {Function} Event handler.

Shortcut to the core’s bind() method. Binds specified handler to the event.

TextExtPlugin.core()

Returns instance of the TextExt to which current instance of the plugin is attached to.

TextExtPlugin.formDataObject(input, form)

  • input {String} Value that will go into the text input that user is interacting with.

  • form {Object} Value that will be serialized and put into the hidden that will be submitted with the HTML form.

Returns the hash object that getFormData triggered by the core expects.

TextExtPlugin.init(core)

  • core {TextExt} Instance of the TextExt core class.

Initialization method called by the core during plugin instantiation. This method must be implemented by each plugin individually.

TextExtPlugin.initPriority()

Returns initialization priority for this plugin. If current plugin depends upon some other plugin to be initialized before or after, priority needs to be adjusted accordingly. Plugins with higher priority initialize before plugins with lower priority.

Default initialization priority is 0.

TextExtPlugin.input()

Shortcut to the core’s input() method. Returns instance of the HTML element that represents current text input.

TextExtPlugin.itemManager()

Shortcut to the core’s itemManager() method. Returns instance of the ItemManger that is currently in use.

TextExt.on([target], handlers)

  • target {Object} Optional. Target object which has traditional bind(event, handler) method. Handler function will still be executed in the current object’s scope.

  • handlers {Object} Key/value pairs of event names and handlers, eg { event: handler }.

Allows to add multiple event handlers which will be execued in the scope of the current object.

TextExtPlugin.opts(name)

  • name {String} Option name as described in the options.

Shortcut to the core’s opts() method. Returns option value.

TextExtPlugin.startTimer(name, delay, callback)

  • name {String} Timer name.

  • delay {Number} Delay in seconds.

  • callback {Function} Callback function.

Allows starting of multiple timeout calls. Each time this method is called with the same timer name, the timer is reset. This functionality is useful in cases where an action needs to occur only after a certain period of inactivity. For example, making an AJAX call after user stoped typing for 1 second.

TextExtPlugin.stopTimer(name)

  • name {String} Timer name.

Stops the timer by name without resetting it.

TextExtPlugin.trigger(event, ...args)

  • event {String} Name of the event to trigger.

  • …args All remaining arguments will be passed to the event handler.

Shortcut to the core’s trigger() method. Triggers specified event with arguments on the component core.

TextExtPlugin.val(value)

  • value {String} Optional value. If specified, the value will be set, otherwise it will be returned.

Shortcut to the commonly used this.input().val() call to get or set value of the text input.

Fork me on GitHub