ColorPicker

ColorPicker

new ColorPicker(optionsopt)

Source:
Properties:
Name Type Attributes Default Description
hsl object <optional>
{h:0, s:0.5, l:0}

An object containing members hue, saturation and lightness as numerical values.

rgb object <optional>
{r:0, r:0, b:0}

An object containing members red, green and blue as numerical values.

hex string <optional>
000000

A HEX color value, either with or without leading #.

hue number <optional>
0

A numerical value 0..1 for the hue.

saturation number <optional>
0

A numerical value 0..1 for the saturation.

lightness number <optional>
0

A numerical value 0..1 for the lightness.

red number <optional>
0

A numerical value 0..255 for the amount of red.

green number <optional>
0

A numerical value 0..255 for the amount of green.

blue number <optional>
0

A numerical value 0..255 for the amount of blue.

show_hue boolean <optional>
true

Set to false to hide the ValueKnob for hue.

show_saturation boolean <optional>
true

Set to false to hide the ValueKnob for saturation.

show_lightness boolean <optional>
true

Set to false to hide the ValueKnob for lightness.

show_red boolean <optional>
true

Set to false to hide the ValueKnob for red.

show_green boolean <optional>
true

Set to false to hide the ValueKnob for green.

show_blue boolean <optional>
true

Set to false to hide the ValueKnob for blue.

show_hex boolean <optional>
true

Set to false to hide the Value for the HEX color.

show_apply boolean <optional>
true

Set to false to hide the Button to apply.

show_cancel boolean <optional>
true

Set to false to hide the Button to cancel.

show_canvas boolean <optional>
true

Set to false to hide the color canvas.

show_grayscale boolean <optional>
true

Set to false to hide the grayscale.

show_indicator boolean <optional>
true

Set to false to hide the color indicator.

options.content String | HTMLElement <optional>

The content of the container. It can either be a string which is interpreted as HTML or a DOM node. Note that this option will remove all child nodes from the container element including those added via append_child. (Defined in Container)

options.hiding_duration Number <optional>
0

The duration in ms of the hiding CSS transition/animation of this container. If this option is set to -1, the transition duration will be determined by the computed style, which can be rather expensive. Setting this option explicitly can therefore be an optimization. (Defined in Container)

options.showing_duration Number <optional>
0

The duration in ms of the showing CSS transition/animation of this container. If this option is set to -1, the transition duration will be determined by the computed style, which can be rather expensive. Setting this option explicitly can therefore be an optimization. (Defined in Container)

options.title String <optional>
""

A string to be set as title attribute on the main element to be displayed as tooltip. (Defined in Widget)

options.disabled Boolean <optional>
false

Toggles the class .aux-disabled. By default it disables all pointer events on the widget via CSS to make it unusable to the user. (Defined in Widget)

options.active Boolean <optional>

Toggles the class .aux-inactive. (Defined in Widget)

options.visible Boolean <optional>

Toggles the class .aux-hide and .aux-show. This option also enables and disabled rendering by calling Widget#hide and Widget#show. (Defined in Widget)

options.needs_resize Boolean <optional>
true

Set to true if the resize function shall be called before the next redraw. (Defined in Widget)

options.dblclick Boolean <optional>
400

Set a time in milliseconds for triggering double click event. If 0, no double click events are fired. (Defined in Widget)

options.preset String <optional>

Set a preset. This string gets set as class attribute aux-preset-[preset]. If options.presets has a member of this name, all options of its option object are set on the Widget. Non-existent options are reset to the default. Defaults are updated on initialization and runtime. (Defined in Widget)

options.presets Object <optional>
{}

An object with available preset specific options. Refer to options.preset for more information. (Defined in Widget)

ColorPicker provides a collection of widgets to select a color in RGB or HSL color space.

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

An object containing initial options.

Extends

Members

apply :Button

Source:

The Button to apply. Has class .aux-apply`,

Type:

blue :ValueKnob

Source:

The ValueKnob for the blue color. Has class .aux-blue`,

Type:

cancel :Button

Source:

The Button to cancel. Has class .aux-cancel`,

Type:

canvas :HTMLDivElement

Source:

The color background. Has class .aux-canvas`,

Type:
  • HTMLDivElement

drag_x :Range

Source:

The DragValue for the x axis.

Type:

drag_y :Range

Source:

The DragValue for the y axis.

Type:

element :HTMLDivElement

Source:
Overrides:

The main DIV container. Has class .aux-colorpicker.

Type:
  • HTMLDivElement

grayscale :HTMLDivElement

Source:

The grayscale background. Has class .aux-grayscale`,

Type:
  • HTMLDivElement

green :ValueKnob

Source:

The ValueKnob for the green color. Has class .aux-green`,

Type:

hex :Value

Source:

The Value for the HEX color. Has class .aux-hex`,

Type:

hue :ValueKnob

Source:

The ValueKnob for the hue. Has class .aux-hue`,

Type:

indicator :HTMLDivElement

Source:

The indicator element. Has class .aux-indicator`,

Type:
  • HTMLDivElement

lightness :ValueKnob

Source:

The ValueKnob for the lightness. Has class .aux-lightness`,

Type:

range_x :Range

Source:

The Range for the x axis.

Type:

range_y :Range

Source:

The Range for the y axis.

Type:

red :ValueKnob

Source:

The ValueKnob for the red color. Has class .aux-red`,

Type:

saturation :ValueKnob

Source:

The ValueKnob for the saturation. Has class .aux-saturation`,

Type:

Methods

add_child(child)

Source:
Inherited From:
See:

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 Widget

The child to add.

Fires:
  • Widget#event:child_added

add_children(a)

Source:
Inherited From:

Registers an array of widgets as children.

Parameters:
Name Type Description
a Array.<Widget>

An array of Widgets.

addEventListener(event, func)

Source:
Inherited From:

Register an event handler.

Parameters:
Name Type Description
event string

The event descriptor.

func function

The function to call when the event happens.

all_children()

Source:
Inherited From:

Returns an array of all children.

append_child(child)

Source:
Inherited From:

Appends child.element to the widget element and registers child as a child widget.

Parameters:
Name Type Description
child Widget

The child widget to append.

append_children(children)

Source:
Inherited From:

Calls Widget#append_child for an array of widgets.

Parameters:
Name Type Description
children Array.<Widget>

The child widgets to append.

delegate_events(element) → {HTMLElement}

Source:
Inherited From:

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.

Fires:
Returns:

The element

Type
HTMLElement

destroy()

Source:
Inherited From:

Destroys all event handlers and the options object.

dispatchEvent(event, …args)

Source:
Inherited From:

Fires an event.

Parameters:
Name Type Attributes Description
event string

The event descriptor.

args * <repeatable>

Event arguments.

enable_draw()

Source:
Inherited From:

Schedules this widget for drawing.

Fires:

enable_draw_children()

Source:
Inherited From:

Enables rendering for all children of this widget.

force_hide()

Source:
Inherited From:

Hide the widget immediately by applying the class aux-hide. Does not call disable_draw().

force_show()

Source:
Inherited From:

Show the widget immediately by applying the class aux-show. Does not call enable_draw().

get(key)

Source:
Inherited From:

Get the value of an option.

Parameters:
Name Type Description
key string

The option name.

get_default()

Source:
Inherited From:

Returns the default value of a given option. If the option does not exist, an exception is thrown.

get_option_type()

Source:
Inherited From:

Returns the type of an option. If the given option does not exist, 'undefined' is returned.

get_style()

Source:
Inherited From:

Returns the computed style of this widget's DOM element.

has_event_listeners(event) → {boolean}

Source:
Inherited From:

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

Parameters:
Name Type Description
event string

The event desriptor.

Returns:

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

Type
boolean

hidden()

Source:
Inherited From:

Returns the current hidden status.

hide()

Source:
Inherited From:

Starts the transition of the visible to false.

hide_child(child)

Source:
Inherited From:

Switches the hidden state of a child to hidden. The argument is either the child index or the child itself.

Parameters:
Name Type Description
child Object | integer

Child or its index.

off(event, fun)

Source:
Inherited From:

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.

remove_child(child)

Source:
Inherited From:

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

Parameters:
Name Type Description
child Widget

The child to remove.

Fires:
  • Widget#event:child_removed

remove_children(a)

Source:
Inherited From:

Removes an array of children.

Parameters:
Name Type Description
a Array.<Widget>

An array of Widgets.

reset(key)

Source:
Inherited From:

Resets an option to its default value.

Parameters:
Name Type Description
key string

The option name.

set(key, value)

Source:
Inherited From:

Sets an option.

Parameters:
Name Type Description
key string

The option name.

value

The option value.

set_options(optionsopt)

Source:
Inherited From:

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 an 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.

set_style()

Source:
Inherited From:

Sets a CSS style property in this widget's DOM element.

show()

Source:
Inherited From:

Starts the transition of the visible to true.

show_child(child)

Source:
Inherited From:

Switches the hidden state of a child to shown. The argument is either the child index or the child itself.

Parameters:
Name Type Description
child Object | integer

Child or its index.

toggle_child(child)

Source:
Inherited From:

Toggles the hidden state of a child. The argument is either the child index or the child itself.

Parameters:
Name Type Description
child Object | integer

Child or its index.

toggle_hidden()

Source:
Inherited From:

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

update(key, value)

Source:
Inherited From:

Conditionally sets an option unless it already has the requested value.

Parameters:
Name Type Description
key string

The name of the option.

value mixed

The value of the option.

Fires:

userset(key, value)

Source:
Inherited From:

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.

Fires:
  • Base#event:userset
  • Base#event:useraction

visible_children()

Source:
Inherited From:

Returns an array of all visible children.

Events

apply

Source:

Is fired whenever the apply button gets clicked or return is hit on input.

Parameters:
Name Type Description
colors object

Object containing all color objects: rgb, hsl, hex, hue, saturation, lightness, red, green, blue

cancel

Source:

Is fired whenever the cancel button gets clicked or ESC is hit on input.

delegated

Source:
Inherited From:

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.

destroy

Source:
Inherited From:

Is fired when a widget is destroyed.

doubleclick

Source:
Inherited From:

Is fired after a double click appeared. Set dblclick to 0 to disable click event handling.

Parameters:
Name Type Description
event string

The browsers MouseEvent.

GenericDOMEvents

Source:
Inherited From:

Generic DOM events. Please refer to W3Schools for further details.

hide

Source:
Inherited From:

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 Pager.

initialized

Source:
Inherited From:

Is fired when a widget is initialized.

redraw

Source:
Inherited From:

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

resize

Source:
Inherited From:

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 Widget#resized event can be used instead.

resized

Source:
Inherited From:

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

set

Source:
Inherited From:

The set event is emitted when an option was set using the 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.

set_[option]

Source:
Inherited From:

Is fired when an option is set.

Parameters:
Name Type Description
value mixed

The value of the option.

show

Source:
Inherited From:

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

visibility

Source:
Inherited From:

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