TK.Base

new Base()

This is the base class for all widgets in toolkit. It provides an API for event handling and other basic implementations.

Source:

Methods

add_event(event, func, prevent, stop)

Register an event handler.

Parameters:
Name Type Description
event string

The event descriptor.

func function

The function to call when the event happens.

prevent boolean

Set to true if the event should prevent the default behavior.

stop boolean

Set to true if the event should stop bubbling up the tree.

Source:

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.

Parameters:
Name Type Description
events Object | Array

Object with event descriptors as keys and functions as values or Array of event descriptors. The latter requires a handler function as the second argument.

func function

A function to add as event handler if the first argument is an array of event desriptors.

Source:

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.

Parameters:
Name Type Description
element HTMLElement

The element all native events of the widget should be bound to.

Source:
Fires:
Returns:

The element

Type
HTMLElement

destroy()

Destroys all event handlers and the options object.

Source:

fire_event(event, …args)

Fires an event.

Parameters:
Name Type Attributes Description
event string

The event descriptor.

args * <repeatable>

Event arguments.

Source:

fire_events(events)

Fires several events.

Parameters:
Name Type Description
events Array.<string>

A list of event names to fire.

Source:

get(key)

Get the value of an option.

Parameters:
Name Type Description
key string

The option name.

Source:

has_event_listeners(event) → {boolean}

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

Parameters:
Name Type Description
event string

The event desriptor.

Source:
Returns:

True if the event has some handler functions in the queue, false if not.

Type
boolean

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.

Parameters:
Name Type Description
event string

The event descriptor.

fun function

The function to remove.

Source:

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.

Parameters:
Name Type Description
events Object | Array

Object with event descriptors as keys and functions as values or Array of event descriptors. The latter requires the handler function as the second argument.

func function

A function to remove from event handler queue if the first argument is an array of event desriptors.

Source:

set(key, value)

Sets an option. Fires both the events set with arguments key and value; and the event 'set_'+key with arguments value and key.

Parameters:
Name Type Description
key string

The name of the option.

value mixed

The value of the option.

Source:
Fires:

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.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{ }

An object containing initial options.

Source:

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.

Parameters:
Name Type Description
key string

The name of the option.

value mixed

The value of the option.

Source:
Fires:
  • TK.Base#event:userset
  • TK.Base#event:useraction

Events

delegated

Is fired when an element is delegated.

Parameters:
Name Type Description
element HTMLElement | Array

The element which receives all native DOM events.

old_element HTMLElement | Array

The element which previously received all native DOM events.

Source:

initialized

Is fired when an instance is initialized.

Source:

set

Is fired when an option is set.

Parameters:
Name Type Description
name string

The name of the option.

value mixed

The value of the option.

Source:

set_[option]

Is fired when an option is set.

Parameters:
Name Type Description
value mixed

The value of the option.

Source: