TK.Widget

new Widget(options)

TK.Widget is the base class for all widgets drawing DOM elements. It provides basic functionality like delegating events, setting options and firing some events.Widget implements AudioMath, Options and Events.

Parameters:
Name Type Description
options Object
Properties:
Name Type Attributes Default Description
options.class String <optional>
""

A class to add to the class attribute of the main element.

options.container Object <optional>

A container the main element shall be added to.

options.id String <optional>
""

A string to be set as id attribute on the main element.

options.styles Object <optional>
""

An object containing CSS declarations to be added directly to the main element.

options.disabled Boolean <optional>
false

Toggles the class toolkit-disabled.

options.element Object <optional>

An element to be used as the main element.

options.active Boolean <optional>

Toggles the class toolkit-inactive.

options.needs_resize Boolean <optional>
true

Set to true if the resize function shall be called before the next redraw.

Source:

Extends

Methods

add_child(child)

Registers a widget as a child widget. This method is used to build up the widget tree. It does not modify the DOM tree.

Parameters:
Name Type Description
child TK.Widget

The child to add.

Source:
See:

add_children(a)

Registers an array of widgets as children.

Parameters:
Name Type Description
a Array.<TK.Widget>

An array of Widgets.

Source:

all_children()

Returns an array of all children.

Source:

enable_draw()

Schedules this widget for drawing.

Source:
Fires:

enable_draw()

Stop drawing this widget.

Source:
Fires:

force_hide()

This is an alias for hide, which may be overloaded. See TK.Container for an example.

Source:

force_show()

This is an alias for hide, which may be overloaded. See TK.Container for an example.

Source:

get_style()

Returns the computed style of this widgets DOM element.

Source:

hidden()

Returns the current hidden status.

Source:

hide()

Make the widget hidden. This does not modify the DOM, instead it will stop rendering this widget. Options changed after calling hide will only be rendered (i.e. applied to the DOM) when the widget is made visible again using TK.Widget#show.

Source:

remove_child(child)

Removes a child widget. Note that this method only modifies the widget tree and does not change the DOM.

Parameters:
Name Type Description
child TK.Widget

The child to remove.

Source:

remove_children(a)

Removes an array of children.

Parameters:
Name Type Description
a Array.<TK.Widget>

An array of Widgets.

Source:

set(key, value)

Sets an option.

Parameters:
Name Type Description
key string

The option name.

value

The option value.

Overrides:
Source:

set_style()

Sets a CSS style property in this widgets DOM element.

Source:

show()

Make the widget visible. This does not modify the DOM, instead it will only schedule the widget for rendering.

Source:

toggle_hidden()

TK.Toggle the hidden status. This is equivalent to calling hide() or show(), depending on the current hidden status of this widget.

Source:

visible_children()

Returns an array of all visible children.

Source:

widgetize()

Set the DOM elements of this widgets. This method is usually only used internally. Basically it means to add the id from options and set a basic CSS class. If delegate is true, basic events will be delegated from the element to the widget instance if classify is true, CSS functions will be bound to the widget instance.

Source:
Fires:

Methods inherited from TK.Base

add_event(event, func, prevent, stop)

Register an event handler.

add_events(events, func)

Add multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

delegate_events(element) → {HTMLElement}

Delegates all occuring DOM events of a specific DOM node to the widget. This way the widget fires e.g. a click event if someone clicks on the given DOM node.

destroy()

Destroys all event handlers and the options object.

fire_event(event, …args)

Fires an event.

fire_events(events)

Fires several events.

get(key)

Get the value of an option.

has_event_listeners(event) → {boolean}

Test if the event descriptor has some handler functions in the queue.

remove_event(event, fun)

Removes the given function from the event queue. If it is a native DOM event, it removes the DOM event listener as well.

remove_events(events, func)

Remove multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

set_options(optionsopt)

Merges a new options object into the existing one including deep copies of objects. If an option key begins with the string "on" it is considered as event handler. In this case the value should be the handler function for the event with the corresponding name without the first "on" characters.

userset(key, value)

Sets an option by user interaction. Emits the userset event. The userset event can be cancelled (if an event handler returns false), in which case the option is not set. Returns true if the option was set, false otherwise. If the option was set, it will emit a useraction event.

Events

classified

Is fired when a widget is classified.

Parameters:
Name Type Description
element HTMLElement

The element which receives all further class changes.

Source:

destroy

Is fired when a widget is destroyed.

Source:

hide

Is fired when a widget is hidden and not rendered anymore.

Source:

hide

The hide event is emitted when a widget is hidden and is not rendered anymore. This happens both with browser visibility changes and also internally when using layout widgets such as TK.Pager.

Source:

initialized

Is fired when a widget gets delegated.

Parameters:
Name Type Description
element HTMLElement

The element all native DOM events are delegated to.

Overrides:
Source:

initialized

Is fired when a widget is initialized.

Overrides:
Source:

redraw

The redraw event is emitted when a widget is redrawn. This can be used to do additional DOM modifications to a Widget.

Source:

redraw

Is fired when a redraw is executed.

Source:

resize

Is fired when a resize is requested.

Source:

resize

The resize event is emitted whenever a widget is being resized. This event can be used to e.g. measure its new size. Note that some widgets do internal adjustments after the resize event. If that is relevant, the TK.Widget#resized event can be used, instead.

Source:

resized

Is fired after the resize was executed and the DOM is updated.

Source:

resized

The resized event is emitted after each rendering frame, which was triggered by a resize event.

Source:

set

The set event is emitted when an option was set using the TK.Widget#set method. The arguments are the option name and its new value.

Note that this happens both for user interaction and programmatical option changes.

Overrides:
Source:

show

Is fired when a widget gets enabled for drawing.

Source:

show

The show event is emitted when a widget is shown and is being rendered. This is the counterpart to TK.Widget#hide.

Source:

stylized

Is fired when a widget is stylized.

Parameters:
Name Type Description
element HTMLElement

The element which receives all further style changes.

Source:

visibility

Is fired when the visibility state changes. The first argument is the visibility state, which is either true or false.

Source:

widgetize

Is fired when a widget is widgetized.

Parameters:
Name Type Description
element HTMLElement

The element which got widgetized.

Source:

Events inherited from TK.Base

delegated

Is fired when an element is delegated.

set_[option]

Is fired when an option is set.