$

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

Name Type Description
url string No 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

Name Type Description
event number No description provided.

See also

CompressString

$.CompressString(str: string): string

Compresses the given string, and encodes result in base64.

Parameter

Name Type Description
str string No 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

Name Type Description
type T No description provided.
parent GenericPanel No description provided.
id string No description provided.
properties Record<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

Name Type Description
...args any[] No description provided.

DecompressString

$.DecompressString(str: string): string

Decompresses the given base64 encoded input into a string.

Parameter

Name Type Description
str string No 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

Name Type Description
event string The event name.
argscount number The number of arguments that this event takes.
argsdesc string (optional) An optional description for the event arguments.
desc string (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

Name Type Description
event string The event name.
argscount number The number of arguments that this event takes.
argsdesc string (optional) An optional description for the event arguments.
desc string (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

Name Type Description
event T No description provided.
...args T 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

Name Type Description
...args any[] 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

Name Type Description
items T[] 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

Name Type Description
...args any[] 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

Name Type Description
str string No description provided.
truncate boolean (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

Name Type Description
url string The 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

Name Type Description
url string The 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

Name Type Description
str string No description provided.

See also

LocalizeSafe

$.LocalizeSafe(str: string): string

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

Parameter

Name Type Description
str string No description provided.

Msg

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

Log a message

Parameter

Name Type Description
...messages any[] No description provided.

PlaySoundEvent

$.PlaySoundEvent(sound: string): uuid

Plays the specified soundscript.

Parameter

Name Type Description
sound string No description provided.

RegisterConVarChangeListener

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

Register a handler for whenever a convar changes

Parameters

Name Type Description
convar string No 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

Name Type Description
event T No description provided.
context string | GenericPanel No description provided.
callback T extends keyof PanelEventNameMap ? PanelEventNameMap[T<T>] : T extends keyof GlobalEventNameMap ? GlobalEventNameMap[T<T>] : never No 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

Name Type Description
event T No description provided.
callback GlobalEventNameMap[T] No description provided.

See also

RegisterKeyBind

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

Register a key binding

Parameters

Name Type Description
panel GenericPanel No description provided.
key string No description provided.
event string | Func<any[], void> No description provided.

Schedule

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

Schedule a function to be called later

Parameters

Name Type Description
time number No description provided.
callback Func<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

Name Type Description
guid number No description provided.
fadetime number (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

Name Type Description
id number No description provided.

UnregisterEventHandler

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

Remove an event handler

Parameters

Name Type Description
event T No description provided.
context GenericPanel No description provided.
eventHandler number No description provided.

UnregisterForUnhandledEvent

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

Remove an unhandled event handler

Parameters

Name Type Description
event T No description provided.
eventHandler number No description provided.

UrlDecode

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

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

Parameter

Name Type Description
...args any[] No description provided.

UrlEncode

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

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

Parameter

Name Type Description
...args any[] No description provided.

Warning

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

Log a warning

Parameter

Name Type Description
...args any[] No description provided.