Skip to content

Widget

Widget is a part of the user interface that has its own structure and behavior. Widget is the base class for all CallGear widgets.

Methods

show()

Shows the widget. By default, this method removes the callgear-widget--hidden class. You can override it when creating a widget.

hide()

Hides the widget. By default, this method adds the callgear-widget--hidden class. You can override it when creating a widget.

render()

Inserts the widget and creates its DOM element on the page.

destroy()

Removes the widget DOM element from the page.

getEl(selector?: String)

Returns a reference to a DOM element.

selector is an optional parameter used to find an element with a specific selector inside the widget element. If it is not passed, the whole widget element is returned.

on(eventName: string, callback: Function)

Subscribes to widget events.

eventName is the name of the event.

callback is the function that will be called when the event occurs.

un(eventName: string, callback: Function)

Unsubscribes from widget events.

eventName is the name of the event.

callback is the function that was passed when subscribing to the event.

Events

beforeshow

Triggered before the show method runs.

show

Triggered after the show method runs.

beforehide

Triggered before the hide method runs.

hide

Triggered after the hide method runs.

beforerender

Triggered before the render method runs.

render

Triggered after the render method runs.

beforedestroy

Triggered before the destroy method runs.

Creating widgets

Widgets are created by calling CallGear.UI.createWidget().

The first parameter is the widget name. The second parameter is the configuration object.

Widgets share a common base class and can also have child classes derived from it.

Widget names:

  1. personal_form
  2. call_generator
  3. offline_message_generator
  4. sitephone

If the widget name is not in this list, the created object will be an instance of the base class.

CallGear.UI.createWidget('sitephone_label', {
    settings: settings,
    template: tpls['sitephone_label']
})

Otherwise, an object of the corresponding child class will be returned.

CallGear.UI.createWidget('sitephone', {
    settings: settings,
    template: tpls['sitephone']
})

The createWidget method is intended to be called inside a ViewController.