Initializer

<abstract> .dvtBaseGauge()

Options

contextMenu :Element|Array.<Element>|string|jQuery|NodeList

Identifies the JET Menu that the component should launch as a context menu on right-click, Shift-F10, Press & Hold,
or component-specific gesture. If specified, the browser's native context menu will be replaced by the specified JET Menu.

The value can be an HTML element, JQ selector, JQ object, NodeList, or array of elements. In all cases, the first indicated element is used.

To specify a JET context menu on a DOM element that is not a JET component, see the ojContextMenu binding.

To make the page semantically accurate from the outset, applications are encouraged to specify the context menu via the standard
HTML5 syntax shown in the below example. When the component is initialized, the context menu thus specified will be set on the component.

There is no restriction on the order in which the JET Menu and the referencing component are initialized. However, when specifying
the Menu via the HTML attribute, the referenced DOM element must be in the document at the time that the referencing component is
initialized.

After create time, the contextMenu option should be set via this API, not by setting the DOM attribute.

The application can register a listener for the Menu's beforeOpen event. The listener can cancel the
launch via event.preventDefault(), or it can customize the menu contents by editing the menu DOM directly,
and then calling refresh() on the Menu.

To help determine whether it's appropriate to cancel the launch or customize the menu, the beforeOpen
listener can use component API's to determine which table cell, chart item, etc., is the target of the context menu. See the JSDoc and
demos of the individual components for details. Keep in mind that any such logic must work whether the context menu was launched via right-click,
Shift-F10, Press & Hold, or component-specific touch gesture.

rootAttributes :Object

Attributes specified here will be set on the component's root DOM element at creation time.
This is particularly useful for components like Dialog that wrap themselves in a new root element
at creation time.

The supported attributes are id, which overwrites any existing value,
and class and style, which are appended
to the current class and style, if any.

Setting this option after component creation has no effect. At that time, the root element already
exists, and can be accessed directly via the widget method, per the second example below.

Supported Values:

translations :Object

A collection of translated resources from the translation bundle, or null if this
component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.

If this component has (or inherits) translations, their documentation immediately follows this doc entry.

Default Value:

an object containing all resources relevant to the component and all its superclasses, or null if none

optionChange

Fired whenever a supported component option changes, whether due to user interaction or programmatic
intervention. If the new value is the same as the previous value, no event will be fired. The event
listener will receive two parameters described below:

Properties:

Name

Type

Description

event

Event

jQuery event object

ui

Object

event payload

Properties

Name

Type

Argument

Description

option

string

the name of the option that changed.

previousValue

Object

an Object holding the previous value of the option.
When previousValue is not a primitive type, i.e., is an Object, it may hold the same value as
the value property.

value

Object

an Object holding the current value of the option.

subproperty

Object

<nullable>

an Object holding information about the subproperty that changed.

Properties

Name

Type

Description

path

string

the subproperty path that changed.

previousValue

Object

an Object holding the previous value of the subproperty.

value

Object

an Object holding the current value of the subproperty.

optionMetadata

Object

information about the option that changed

Properties

Name

Type

Description

writeback

string

"shouldWrite" or
"shouldNotWrite". For use by the JET writeback mechanism;
'shouldWrite' indicates that the value should be written to the observable.

Returns:

The getter overloads return the retrieved value(s). When called via the public jQuery syntax, the setter overloads
return the object on which they were called, to facilitate method chaining.

Type

Object
|
undefined

Examples

First overload: get one option:

This overload accepts a (possibly dot-separated) optionName param as a string, and returns
the current value of that option.

var isDisabled = $( ".selector" ).ojFoo( "option", "disabled" ); // Foo is Button, Menu, etc.
// For object-valued options, dot notation can be used to get the value of a field or nested field.
var startIcon = $( ".selector" ).ojButton( "option", "icons.start" ); // icons is object with "start" field

Second overload: set one option:

This overload accepts two params: a (possibly dot-separated) optionName string, and a new value to
which that option will be set.

$( ".selector" ).ojFoo( "option", "disabled", true ); // Foo is Button, Menu, etc.
// For object-valued options, dot notation can be used to set the value
// of a field or nested field, without altering the rest of the object.
$( ".selector" ).ojButton( "option", "icons.start", myStartIcon ); // icons is object with "start" field

Third overload: get all options:

This overload accepts no params, and returns a map of key/value pairs representing all the component
options and their values.

Returns:

Non-public Methods

Note: Extending JET components
is not currently supported. Thus, non-public methods are for internal use only.

<protected> _AddActiveable(options)

Add touch and mouse listeners to toggle oj-active class

Parameters:

Name

Type

Description

options

!Object
|
!jQuery

This parameter can either be the element
(convenience syntax for callers needing to
specify only the element(s) that would
otherwise have been passed as options.element)
or an object supporting the following fields:

Properties

Name

Type

Argument

Description

element

jQuery

The element(s) to receive the
oj-active class on active
Required if afterToggle is specified.

afterToggle

function(string)

<nullable>

Optional callback function called each time
the active classes have been toggled, after the toggle. The event.type string is passed
and indicates whether the classes were added or removed. The active classes are added on
"touchstart" or "mousedown" or "mouseenter" and the active classes are removed on
"touchend" or "touchcancel" or "mouseup" or "mouseleave".
Components with consistency requirements, such as
"oj-default must be applied iff no state classes
such as oj-active are applied,"
can enforce those rules in this callback.

<protected> _AddHoverable(options)

Add mouse listners to toggle oj-hover class

Parameters:

Name

Type

Description

options

!Object
|
!jQuery

This param can either be the element
(convenience syntax for callers needing to
specify only the element(s) that would
otherwise have been passed as options.element)
or an object supporting the following fields:

Properties

Name

Type

Argument

Description

element

jQuery

The element(s) to receive the oj-hover class on hover
Required if afterToggle is specified.

afterToggle

function(string)

<nullable>

Optional callback function called each time the hover classes have been toggled,
after the toggle. The string "mouseenter" or "mouseleave" is passed, indicating whether the classes were added or removed.
Components with consistency requirements, such as "oj-default must be applied iff no state classes
such as oj-hover are applied," can enforce those rules in this callback.

<protected> _AfterCreate()

This method is called after _ComponentCreate, but before the
create event is fired. The JET base component does
tasks here that must happen after the component (subclass) has created itself in its override of
_ComponentCreate. Notably, the base component handles the
rootAttributes and contextMenu options here,
since those options operate on the component root node, which for some components is created in their override
of _ComponentCreate.

Subclasses should override this method only if they have tasks that must happen after a superclass's
implementation of this method, e.g. tasks that must happen after the context menu is set on the component.

Only behaviors (like Dialog auto-open behavior) should occur in this method. Component initialization
must occur earlier, before the create event is fired, so that
create listeners see a fully inited component.

Overrides of this method should call this._super first.

Do not confuse this method with the _AfterCreate method, which is more commonly used.

Returns:

Type

boolean

<protected> _ComponentCreate()

All component create-time initialization lives in this method, except the logic that specifically
needs to live in _InitOptions, _AfterCreate,
or _AfterCreateEvent,
per the documentation for those methods. All DOM creation must happen here, since the intent of
_AfterCreate, which is called next, is to contain superclass logic that must
run after that DOM is created.

Overrides of this method should call this._super first.

Summary of create-time methods that components can override, in the order that they are called:

For all of these methods, the contract is that overrides must call this._superfirst, so e.g., the
_ComponentCreate entry means baseComponent._ComponentCreate,
then _ComponentCreate in any intermediate subclasses, then
_ComponentCreate in the leaf subclass.

Returns:

<protected> _focusable(options)

Sets JET's "focus" CSS classes when the element is focused and removes them when focus is lost.

The oj-focus class is set on all focuses.

Some components additionally have an oj-focus-highlight class, which applies a focus
indicator that is appropriate on a subset of the occasions that oj-focus is appropriate.
Those components should pass true for the applyHighlight
param, in which case the oj-focus-highlight class is set if appropriate given the
current focus highlight policy.

Focus highlight policy

The focus highlight policy supports the 3 values listed below. By default, it is retrieved from the
$focusHighlightPolicy SASS variable, shared by many components and patterns. Components
with different needs, including those exposing a component-specific SASS variable or other API for this, should see the
getFocusHighlightPolicy parameter below.
Valid focus highlight policies:

Policy

Description

"nonPointer"

Indicates that the component should apply the oj-focus-highlight
class only for focuses not resulting from pointer (touch or mouse) interaction. (In the built-in themes, the
SASS variable defaults to this value.)

"all"

Indicates that the component should apply the class for all focuses.

"none"

Indicates that the component should never apply the class, because the application has taken responsibility
for applying the class when needed for accessibility.

Toggling the classes

Components that toggle these focus classes outside of this API must maintain the invariant that
oj-focus-highlight is applied to a given element in a (not necessarily strict) subset
of cases that oj-focus is applied to that element.

Typically the specified element should be within the component subtree, in which case the classes will
automatically be removed from the element when the component is destroyed, when its disabled
option is set to true, and when _NotifyDetached() is called.

As a minor exception, for components that wrap themselves in a new root node at create time, if the specified
element is within the root node's subtree but not within the init node's subtree, then at destroy time only, the
classes will not be removed, since destroy() is expected to remove such nodes.

If the element is NOT in the component subtree, then the caller is responsible for removing the classes at the
times listed above.

Listeners

If setupHandlers is not passed, or if setupHandlers
is passed and uses _on to register its listeners as seen in the example, then
the listeners are not invoked when the component is disabled, and the listeners are automatically cleaned up when the
component is destroyed. Otherwise, the caller is responsible for ensuring that the disabled state is handled correctly,
and removing the listeners at destroy time.

Related API's

Non-component internal callers should see oj.DomUtils.makeFocusable(). Per its JSDoc (unpublished; see the source), it
has a couple of additional usage considerations.

Parameters:

Name

Type

Description

options

!Object
|
!jQuery

This param can either be the element (convenience syntax for callers needing to
specify only the element(s) that would otherwise have been passed as options.element)
or an object supporting the following fields:

Properties

Name

Type

Argument

Description

element

jQuery

The element(s) to receive the oj-focus classes on focus.
Required if setupHandlers not passed; ignored otherwise.

applyHighlight

boolean

true if the oj-focus-highlight
class should be applied when appropriate. false or omitted if that class should never be applied.

afterToggle

function(string)

<nullable>

Optional callback function called each time the focus classes have been toggled,
after the toggle. The
string "focusin" or "focusout" is passed, indicating whether the classes were added or removed. Components
with consistency requirements, such as "oj-default must be applied iff no state classes such
as oj-focus are applied," can enforce those rules in this callback.

getFocusHighlightPolicy

function()

<nullable>

Optional if applyHighlight is
true; ignored otherwise. Components with a component-specific focus policy
mechanism should pass a function that always returns one of the three valid values listed above, keeping in mind
that this method can be called on every focus. See the example.

recentPointer

function()

<nullable>

Relevant iff applyHighlight is
true and the focus highlight policy is "nonPointer";
ignored otherwise. Recent pointer activity is considered to have occurred if (a) a mouse button or finger has
recently been down or up, or (b) this optional callback function returns true. Components wishing to additionally take into
account (say) recent pointer movements can supply a function returning true if those movements have been detected,
keeping in mind that this method can be called on every focus. See the example.

setupHandlers

function(function(!jQuery),function(!jQuery))

<nullable>

Can be omitted by components whose focus
classes need to be added and removed on focusin and focusout, respectively. Components needing to add/remove those
classes in response to other events should specify this parameter, which is called once, immediately. See the examples.

Returns:

Type

Object

<protected> _GetComponentDeferredDataPaths() → {Object}

Returns an object containing the top level options key and subkeys for
deferred data options. 'root' is used for top level keys. For example,
{'areaLayers': ['areaDataLayer/areas', 'areaDataLayer/markers'] indicates
that we should check this.options['areaLayers'][i]['areaDataLayer']['areas']
and this.options['areaLayers'][i]['areaDataLayer']['markers']. To indicate
a top level option, use the options key 'root', i.e. {'root': ['items']}.

Returns:

Type

Object

<protected> _GetComponentNoClonePaths() → {Object}

Returns an object containing the no clone paths for a component. For example,
{'areaLayers': {'areaDataLayer': {'areas': true, 'markers': true}}} indicates
that we should check this.options['areaLayers'][i]['areaDataLayer']['areas']
and this.options['areaLayers'][i]['areaDataLayer']['markers']. The base implementation
will handle the basic case where the deferred data path contains only top level data options.

Returns:

<protected> _GetReadingDirection() → {string}

All components must determine directionality exclusively by calling this protected superclass method.
(So that any future updates to the logic can be made in this one place.)

Components that need to know the directionality must call this method at create-time
and from refresh(), and cache the value.

Components should not call this at other times, and should instead use the cached value. (This avoids constant DOM
queries, and avoids any future issues with component reparenting (i.e. popups) if support for directional islands is added.)

App responsibilities:

The app specifies directionality by setting the HTML "dir" attribute on the
<html> node. When omitted, the default is "ltr".
(Per-component directionality / directional islands are not currently supported due to inadequate CSS support.)

As with any DOM change, the app must refresh() the component if the directionality changes dynamically.
(This provides a hook for component housekeeping, and allows caching.)

<protected> _GetSavedAttributes(element) → {Object|null}

If you override _SaveAttributes to call _SaveAllAttributes,
then this will return all the attributes.
If you override _SaveAttributes/_RestoreAttributes to do your own thing, then you may also have
to override _GetSavedAttributes to return whatever you saved if you need access to the saved
attributes.

Parameters:

Returns:

The resulting string.

Type

string

<protected> _GetTranslationMap() → {Object}

Returns a map containing keys corresponding to the string ids in ojtranslations.js and values corresponding to the
toolkit constants for the DvtBundle objects. This map must be guaranteed to be a new instance so that subclasses can
add their translations to it.

Parameters:

<protected> _init()

JET components should almost never implement this JQUI method. Please consult an architect if you believe you have an exception. Reasons:

This method is called at create time, after the create event is fired. It is rare
for that to be the appropriate time to perform a create-time task. For those rare cases, we have the
_AfterCreateEvent method, which is preferred over this method since it is called only
at that time, not also at re-init time (see next).

This method is also called at "re-init" time, i.e. when the initializer is called after the component has already been created.
JET has not yet identified any desired semantics for re-initing a component.

<protected> _InitOptions(originalDefaults, constructorOptions)

This method is called before _ComponentCreate, at which point
the component has not yet been rendered. Component options should be initialized in this method,
so that their final values are in place when _ComponentCreate is called.

This includes getting option values from the DOM, where applicable, and coercing option
values (however derived) to their appropriate data type if needed.

No work other than setting options should be done in this method. In particular, nothing should be
set on the DOM until _ComponentCreate, e.g. setting the disabled
DOM attribute from the disabled option.

A given option (like disabled) appears in the constructorOptions
param iff the app set it in the constructor:

If it appears in constructorOptions, it should win over what's in the DOM
(e.g. disabled DOM attribute). If for some reason you need to tweak the value
that the app set, then enable writeback when doing so:
this.option('foo', bar, {'_context': {writeback: true, internalSet: true}}).

If it doesn't appear in constructorOptions, then that option definitely is not bound,
so writeback is not needed. So if you need to set the option (e.g. from a DOM attribute), use
this.option('foo', bar, {'_context': {internalSet: true}}).

Returns:

true if the component has been effectively disabled, false otherwise

Type

boolean

<protected> _IsFlowingLayoutSupported() → {boolean}

Returns whether flowing layout is supported for the component.
If this returns true, the component will render at the preferred size of
the component if the user doesn't specify the width and height in the div.
If this returns false, the component will always render at the browser-
computed width and height.

<protected> _LoadResources()

<protected> _MakeReady()

Called by component to declare rendering is finished. This method currently handles the ready state
for the component whenReady API, the page level BusyContext, and the static whenReady API for the custom element
version of this component.

<protected> _NotifyContextMenuGesture(menu, event, eventType)

When the contextMenu option is set, this method is called when the user invokes the context menu via
the default gestures: right-click, Press & Hold, and Shift-F10. Components should not call this method directly.

Customize the menu contents. E.g. some components need to enable/disable built-in commands like Cut and Paste,
based on state at launch time.

Bail out in some cases. E.g. components with UX approval to use PressHoldRelease rather than Press & Hold can override this method
to say if (eventType !== "touch") this._OpenContextMenu(event, eventType);. When those components
detect the alternate context menu gesture (e.g. PressHoldRelease), that separate listener should call this._OpenContextMenu(),
not this method (_NotifyContextMenuGesture()), and not menu.open().

Components needing to do per-launch setup like the above tasks should do so in an override of this method, not in
a beforeOpen listener or an _OpenContextMenu() override.
This is discussed more fully here.

<protected> _NotReady()

Called by component to declare rendering is not finished. This method currently handles the ready state
for the component whenReady API, the page level BusyContext, and the static whenReady API for the custom element
version of this component.

The only correct way for a component to open its context menu is by calling this method, not by calling Menu.open() or
_NotifyContextMenuGesture(). This method should be called in two cases:

This method is called by _NotifyContextMenuGesture() and its overrides. That method is
called when the baseComponent detects the default context menu gestures: right-click, Press & Hold, and Shift-F10.

Components with UX-approved support for alternate context menu gestures like PressHoldRelease should call this method directly
when those gestures are detected.

Components needing to customize how the context menu is launched, or do any per-launch setup, should do so in the caller of this method,
(which is one of the two callers listed above), often by customizing the params passed to this method
(_OpenContextMenu) per the guidance below. This setup should not be done in the following ways:

Components should not perform setup in a beforeOpen listener, as this can cause a race
condition where behavior depends on who got their listener registered first: the component or the app. The only correct component use
of a beforeOpen listener is when there's a need to detect whether something else launched the menu.

Components should not override this method (_OpenContextMenu), as this method is final. Instead, customize
the params that are passed to it.

Guidance on setting OpenOptions fields:

Launcher:

Depending on individual component needs, any focusable element within the component can be the appropriate
launcher for this launch.

Browser focus returns to the launcher on menu dismissal, so the launcher must at least be focusable. Typically a tabbable (not just
focusable) element is safer, since it just focuses something the user could have focused on their own.

By default (i.e. if openOptions is not passed, or if it lacks a launcher
field), the component init node is used as the launcher for this launch. If that is not focusable or is suboptimal for a given
component, that component should pass something else. E.g. components with a "roving tabstop" (like Toolbar) should typically choose the
current tabstop as their launcher.

The :focusable and :tabbable selectors
may come in handy for choosing a launcher, e.g. something like this.widget().find(".my-class:tabbable").first().

Position:

By default, this method applies positioning that differs from Menu's default in the following ways:
(The specific settings are subject to change.)

For mouse and touch events, the menu is positioned relative to the event, not the launcher.

For touch events, "my" is set to "start>40 center",
to avoid having the context menu obscured by the user's finger.

Usually, if position needs to be customized at all, the only thing that needs changing is its
"of" field, and only for keyboard launches (since mouse/touch launches should almost certainly keep
the default "event" positioning). This situation arises anytime the element relative to which the menu
should be positioned for keyboard launches is different than the launcher element (the element to which
focus should be returned upon dismissal). For this case, { "position": {"of": eventType==="keyboard" ? someElement : "event"} }
can be passed as the openOptions param.

Be careful not to clobber useful defaults by specifying too much. E.g. if you only want to customize "of",
don't pass other fields like "my", since your value will be used for all modalities (mouse, touch, keyboard),
replacing the modality-specific defaults that are usually correct. Likewise, don't forget the
eventType==="keyboard" check if you only want to customize "of" for keyboard launches.

InitialFocus:

This method forces initialFocus to "menu" for this
launch, so the caller needn't specify it.

Parameters:

Name

Type

Argument

Description

event

Event

What triggered the context menu launch. Must be non-null.

eventType

string

"mouse", "touch", or "keyboard". Must be non-null. Passed explicitly since caller
knows what it's listening for, and since events like contextmenu and
click can be generated by various input modalities, making it potentially error-prone for
this method to determine how they were generated.

openOptions

Object

<optional>

Options to merge with this method's defaults, which are discussed above. The result will be passed to
Menu.open(). May be null or omitted. See also the
shallow param.

Whether to perform a deep or shallow merge of openOptions with this method's default
value. The default and most commonly correct / useful value is false.

If true, a shallow merge is performed, meaning that the caller's position
object, if passed, will completely replace this method's default position object.

If false or omitted, a deep merge is performed. For example, if the caller wishes to tweak
position.of while keeping this method's defaults for position.my,
position.at, etc., it can pass {"of": anOfValue} as the
position value.

The shallow param is n/a for submenuOpenOptions, since this method doesn't
apply any defaults to that. (It's a direct pass-through.)

<protected> _RestoreAttributes()

_SaveAttributes is called during _create. And _RestoreAttributes is called during _destroy.

This base class default implementation does nothing.

We also have _SaveAllAttributes and
_RestoreAllAttributes methods
that save and restore all the attributes on an element.
Component subclasses can opt into these _SaveAllAttributes/_RestoreAllAttributes
implementations by overriding _SaveAttributes and _RestoreAttributes to call
_SaveAllAttributes/_RestoreAllAttributes. If the subclass wants a different implementation
(like save only the 'class' attribute), it can provide the implementation itself in
_SaveAttributes/_GetSavedAttributes/_RestoreAttributes.

<protected> _SaveAttributes(element)

Saves the element's attributes. This is called during _create.
_RestoreAttributes will restore all these attributes
and is called during _destroy.

This base class default implementation does nothing.

We also have _SaveAllAttributes and
_RestoreAllAttributes methods
that save and restore all the attributes on an element.
Component subclasses can opt into these _SaveAllAttributes/_RestoreAllAttributes
implementations by overriding _SaveAttributes and _RestoreAttributes to call
_SaveAllAttributes/_RestoreAllAttributes. If the subclass wants a different implementation
(like save only the 'class' attribute), it can provide the implementation itself in
_SaveAttributes/_RestoreAttributes.