$

Namespace for common DOM manipulation operations. For the query selector function, see {@link $(...)}

Functions

AsyncWebRequest

$.AsyncWebRequest(url: string, options?: { complete: { (data: { responseText: string; statusText: string; }): void; }; type: DELETE | GET | HEAD | OPTIONS | POST | PUT; }): void

Make a web request.

Example

$.AsyncWebRequest(DATA_URL, { type: 'GET', complete: (data) => data.statusText === 'success' ? resolve(data.responseText) : reject(data.statusText) });

Parameters

NameTypeDescription
urlstringNo description provided.
options{ complete: { (data: { responseText: string; statusText: string; }): void; }; type: DELETE | GET | HEAD | OPTIONS | POST | PUT; } (optional)No description provided.

See also

CancelScheduled

$.CancelScheduled(event: number): void

Cancel a scheduled function.

Example

const scheduleOpacity = $.Schedule(5, () => { ... }); ... $.CancelScheduled(scheduleOpacity);

Parameter

NameTypeDescription
eventnumberNo description provided.

See also

CompressString

$.CompressString(str: string): string

Compresses the given string, and encodes result in base64.

Parameter

NameTypeDescription
strstringNo description provided.

CreatePanel

$.CreatePanel(type: T, parent: GenericPanel, id: string, properties?: Record<string, unknown>): PanelTagNameMap[T]

Create a new panel.

Example

$.CreatePanel('Split', wrapper, '', { class: 'split--hud split--latest' });

Parameters

NameTypeDescription
typeTNo description provided.
parentGenericPanel No description provided.
idstringNo description provided.
propertiesRecord<string, unknown> (optional)No description provided.

See also

DbgIsReloadingScript

$.DbgIsReloadingScript(...args: any[]): void

Call during JS startup code to check if script is being reloaded

Parameter

NameTypeDescription
...argsany[]No description provided.

DecompressString

$.DecompressString(str: string): string

Decompresses the given base64 encoded input into a string.

Parameter

NameTypeDescription
strstringNo description provided.

DefineEvent

$.DefineEvent(event: string, argscount: number, argsdesc?: string, desc?: string): void

Define an event.

Examples

$.DefineEvent(eventName, NumArguments, [optional] ArgumentsDescription, [optional] Description)
$.DefineEvent('SettingsNavigateToPanel', 2, 'category, settingPanel', 'Navigates to a setting by panel handle');

Parameters

NameTypeDescription
eventstringThe event name.
argscountnumberThe number of arguments that this event takes.
argsdescstring (optional)An optional description for the event arguments.
descstring (optional)An option description for the event.

See also

DefinePanelEvent

$.DefinePanelEvent(event: string, argscount: number, argsdesc?: string, desc?: string): void

Appears to be identical to $.DefineEvent(...). This function is not used anywhere in Momentum UI.

Examples

$.DefinePanelEvent(eventName, NumArguments, [optional] ArgumentsDescription, [optional] Description)
$.DefinePanelEvent('SettingsNavigateToPanel', 2, 'category, settingPanel', 'Navigates to a setting by panel handle');

Parameters

NameTypeDescription
eventstringThe event name.
argscountnumberThe number of arguments that this event takes.
argsdescstring (optional)An optional description for the event arguments.
descstring (optional)An option description for the event.

See also

DispatchEvent

$.DispatchEvent(event: T, ...args: T extends keyof GlobalEventNameMap ? Parameters<GlobalEventNameMap[T<T>]> : any[]): void

Dispatch an event.

Example

$.DispatchEvent('SettingsNavigateToPanel', matches.tabID, matches.panel);

Parameters

NameTypeDescription
eventTNo description provided.
...argsT extends keyof GlobalEventNameMap ? Parameters<GlobalEventNameMap[T<T>]> : any[]No description provided.

See also

DispatchEventAsync

$.DispatchEventAsync(...args: any[]): void

Dispatch an event to occur later.

Parameter

NameTypeDescription
...argsany[]No description provided.

Each

Caution:

DEPRECATED: This was probably added by Valve before .forEach was added to JavaScript. There's no benefit to this over .forEach.

$.Each(items: T[], callback: { (item: T, index: number): void; }): void

Call a function on each given item. Functionally identical to (...).forEach(...).

Parameters

NameTypeDescription
itemsT[]No description provided.
callback{ (item: T, index: number): void; }No description provided.

FindChildInContext

$.FindChildInContext(...args: any[]): T | undefined

Find an element within the current panel context.

This function first calls FindChildInLayoutFile, and if that fails, search other panels in the current context.

Parameter

NameTypeDescription
...argsany[]No description provided.

GetContextObject

$.GetContextObject(): typescript.Record<string, any>

Get the current Javascript context object.

Scripts (non-modules) run in this context directly. Any variables defined in the outermost scope of those scripts are accessible by one-another and are effectively properties of that context object, as well as event handlers and <script> blocks in XML.

Modules run in an encapsulated context, and have no access to the outside context without use of this function. To expose values from a module, call this function and set properties on the returned object.

GetContextPanel

$.GetContextPanel(): T

Gets the root panel of the current Javascript context.

Example

$.GetContextPanel().color = color;

See also

HTMLEscape

$.HTMLEscape(str: string, truncate?: boolean): string

Converts str, which must be 2048 utf-8 bytes or shorter, into an HTML-safe version.

If truncate=true, too long strings will be truncated instead of throwing an exception.

Parameters

NameTypeDescription
strstringNo description provided.
truncateboolean (optional)No description provided.

Language

$.Language(): string

Get the current language

LoadKeyValues3File

$.LoadKeyValues3File(url: string): typescript.Record<string, unknown>

Load a named key values file and return as JS object.

Parameter

NameTypeDescription
urlstringThe path to the file, including the extension, relative to the content folder root.

LoadKeyValuesFile

$.LoadKeyValuesFile(url: string): typescript.Record<string, unknown>

Load a named key values file and return as JS object.

Example

$.LoadKeyValuesFile('panorama/data/changelog.vdf');

Parameter

NameTypeDescription
urlstringThe path to the file, including the extension, relative to the content folder root.

See also

Localize

$.Localize(str: string): string | null

Localizes a string.

Example

$.Localize('#HudStatus_Spawn');

Parameter

NameTypeDescription
strstringNo description provided.

See also

LocalizeSafe

$.LocalizeSafe(str: string): string

Localize a string, but return empty string if the localization token is not found

Parameter

NameTypeDescription
strstringNo description provided.

Msg

$.Msg(...messages: any[]): void

Log a message

Parameter

NameTypeDescription
...messagesany[]No description provided.

PlaySoundEvent

$.PlaySoundEvent(sound: string): uuid

Plays the specified soundscript.

Parameter

NameTypeDescription
soundstringNo description provided.

RegisterConVarChangeListener

$.RegisterConVarChangeListener(convar: string, callback: { (value: string): void; }): uuid

Register a handler for whenever a convar changes

Parameters

NameTypeDescription
convarstringNo description provided.
callback{ (value: string): void; }No description provided.

RegisterEventHandler

$.RegisterEventHandler(event: T, context: string | GenericPanel, callback: T extends keyof PanelEventNameMap ? PanelEventNameMap[T<T>] : T extends keyof GlobalEventNameMap ? GlobalEventNameMap[T<T>] : never): uuid

Register an event handler for an existing event.

Example

$.RegisterEventHandler('OnNewChatEntry', $.GetContextPanel(), this.onNewChatEntry.bind(this));

Parameters

NameTypeDescription
eventTNo description provided.
contextstring | GenericPanelNo description provided.
callbackT extends keyof PanelEventNameMap ? PanelEventNameMap[T<T>] : T extends keyof GlobalEventNameMap ? GlobalEventNameMap[T<T>] : neverNo description provided.

See also

RegisterForUnhandledEvent

$.RegisterForUnhandledEvent(event: T, callback: GlobalEventNameMap[T]): uuid

Register a handler for an event that is not otherwise handled.

Example

$.RegisterForUnhandledEvent('OnMomentumTimerStateChange', this.onTimerEvent.bind(this));]

Parameters

NameTypeDescription
eventTNo description provided.
callbackGlobalEventNameMap[T]No description provided.

See also

RegisterKeyBind

$.RegisterKeyBind(panel: GenericPanel, key: string, event: string | Func<any[], void>): void

Register a key binding

Parameters

NameTypeDescription
panelGenericPanel No description provided.
keystringNo description provided.
eventstring | Func<any[], void>No description provided.

Schedule

$.Schedule(time: number, callback: Func<any[], void>): uuid

Schedule a function to be called later

Parameters

NameTypeDescription
timenumberNo description provided.
callbackFunc<any[], void>No description provided.

StopSoundEvent

$.StopSoundEvent(guid: number, fadetime?: number): void

Stops a sound event by the specified uuid returned from a previous call to PlaySoundEvent. fadetime is optional.

Parameters

NameTypeDescription
guidnumberNo description provided.
fadetimenumber (optional)No description provided.

SystemInDarkMode

$.SystemInDarkMode(): boolean

Returns whether the OS's theme is in dark mode

UnregisterConVarChangeListener

$.UnregisterConVarChangeListener(id: number): void

Unregister a handler for a convar change

Parameter

NameTypeDescription
idnumberNo description provided.

UnregisterEventHandler

$.UnregisterEventHandler(event: T, context: GenericPanel, eventHandler: number): void

Remove an event handler

Parameters

NameTypeDescription
eventTNo description provided.
contextGenericPanel No description provided.
eventHandlernumberNo description provided.

UnregisterForUnhandledEvent

$.UnregisterForUnhandledEvent(event: T, eventHandler: number): void

Remove an unhandled event handler

Parameters

NameTypeDescription
eventTNo description provided.
eventHandlernumberNo description provided.

UrlDecode

$.UrlDecode(...args: any[]): void

Decodes str, which must be 2048 utf-8 bytes or shorter, from URL-encoded form.

Parameter

NameTypeDescription
...argsany[]No description provided.

UrlEncode

$.UrlEncode(...args: any[]): void

Encodes str, which must be 2048 utf-8 bytes or shorter, into URL-encoded form.

Parameter

NameTypeDescription
...argsany[]No description provided.

Warning

$.Warning(...args: any[]): void

Log a warning

Parameter

NameTypeDescription
...argsany[]No description provided.