Version 3.18.1
Show:

Intl Class

Defined in: yui/js/intl-base.js:1
Module: features

The Intl utility provides a central location for managing sets of localized resources (strings and formatting patterns).

Methods

_getFullType

(
  • type
)
String private

Returns the fully qualified type, given a short type string. That is, returns "foo:bar" when given "bar" if "foo" is the configured prefix.

NOTE: This method, unlike _getType, does no checking of the value passed in, and is designed to be used with the low level _publish() method, for critical path implementations which need to fast-track publish for performance reasons.

Parameters:

  • type String

    The short type to prefix

Returns:

String:

The prefixed type, if a prefix is set, otherwise the type passed in

_getType

() private

If the instance has a prefix attribute and the event type is not prefixed, the instance prefix is applied to the supplied type.

_hasPotentialSubscribers

(
  • fullType
)
Boolean private

Parameters:

  • fullType String

    The fully prefixed type name

Returns:

Boolean:

Whether the event has potential subscribers or not

_mod

(
  • module
)
Object private

Provided by the intl module.

Defined in intl/js/Intl.js:22

Private method to retrieve the language hash for a given module.

Parameters:

  • module String

    The name of the module

Returns:

Object:

The hash of localized resources for the module, keyed by BCP language tag

_monitor

(
  • what
  • eventType
  • o
)
private

This is the entry point for the event monitoring system. You can monitor 'attach', 'detach', 'fire', and 'publish'. When configured, these events generate an event. click -> click_attach, click_detach, click_publish -- these can be subscribed to like other events to monitor the event system. Inividual published events can have monitoring turned on or off (publish can't be turned off before it it published) by setting the events 'monitor' config.

Parameters:

  • what String

    'attach', 'detach', 'fire', or 'publish'

  • eventType String | CustomEvent

    The prefixed name of the event being monitored, or the CustomEvent object.

  • o Object

    Information about the event interaction, such as fire() args, subscription category, publish config

_parseType

() private

Returns an array with the detach key (if provided), and the prefixed event name from _getType Y.on('detachcategory| menu:click', fn)

_publish

(
  • fullType
  • etOpts
  • ceOpts
)
CustomEvent private

The low level event publish implementation. It expects all the massaging to have been done outside of this method. e.g. the type to fullType conversion. It's designed to be a fast path publish, which can be used by critical code paths to improve performance.

Parameters:

  • fullType String

    The prefixed type of the event to publish.

  • etOpts Object

    The EventTarget specific configuration to mix into the published event.

  • ceOpts Object

    The publish specific configuration to mix into the published event.

Returns:

CustomEvent:

The published event. If called without etOpts or ceOpts, this will be the default CustomEvent instance, and can be configured independently.

add

(
  • module
  • lang
  • strings
)

Provided by the intl module.

Defined in intl/js/Intl.js:75

Register a hash of localized resources for the given module and language

Parameters:

  • module String

    The module name.

  • lang String

    The BCP 47 language tag.

  • strings Object

    The hash of localized values, keyed by the string name.

addTarget

(
  • o
)
chainable

Registers another EventTarget as a bubble target. Bubble order is determined by the order registered. Multiple targets can be specified.

Events can only bubble if emitFacade is true.

Included in the event-custom-complex submodule.

Parameters:

after

(
  • type
  • fn
  • [context]
  • [arg*]
)
EventHandle

Subscribe to a custom event hosted by this object. The supplied callback will execute after any listeners add via the subscribe method, and after the default function, if configured for the event, has executed.

Parameters:

  • type String

    The name of the event

  • fn Function

    The callback to execute in response to the event

  • [context] Object optional

    Override this object in callback

  • [arg*] Any optional

    0..n additional arguments to supply to the subscriber

Returns:

EventHandle:

A subscription handle capable of detaching the subscription

before

()

Executes the callback before a DOM event, custom event or method. If the first argument is a function, it is assumed the target is a method. For DOM and custom events, this is an alias for Y.on.

For DOM and custom events: type, callback, context, 0-n arguments

For methods: callback, object (method host), methodName, context, 0-n arguments

Returns:

detach handle

bubble

(
  • evt
)
Boolean

Propagate an event. Requires the event-custom-complex module.

Parameters:

Returns:

Boolean:

the aggregated return value from Event.Custom.fire

detach

(
  • type
  • fn
  • context
)
EventTarget

Detach one or more listeners the from the specified event

Parameters:

  • type String | Object

    Either the handle to the subscriber or the type of event. If the type is not specified, it will attempt to remove the listener from all hosted events.

  • fn Function

    The subscribed function to unsubscribe, if not supplied, all subscribers will be removed.

  • context Object

    The custom object passed to subscribe. This is optional, but if supplied will be used to disambiguate multiple listeners that are the same (e.g., you subscribe many object using a function that lives on the prototype)

Returns:

EventTarget:

the host

detachAll

(
  • type
)

Removes all listeners from the specified event. If the event type is not specified, all listeners from all hosted custom events will be removed.

Parameters:

  • type String

    The type, or name of the event

fire

(
  • type
  • arguments
)
Boolean

Fire a custom event by name. The callback functions will be executed from the context specified when the event was created, and with the following parameters.

The first argument is the event type, and any additional arguments are passed to the listeners as parameters. If the first of these is an object literal, and the event is configured to emit an event facade, that object is mixed into the event facade and the facade is provided in place of the original object.

If the custom event object hasn't been created, then the event hasn't been published and it has no subscribers. For performance sake, we immediate exit in this case. This means the event won't bubble, so if the intention is that a bubble target be notified, the event must be published on this object first.

Parameters:

  • type String | Object

    The type of the event, or an object that contains a 'type' property.

  • arguments Object*

    an arbitrary set of parameters to pass to the handler. If the first of these is an object literal and the event is configured to emit an event facade, the event facade will replace that parameter after the properties the object literal contains are copied to the event facade.

Returns:

Boolean:

True if the whole lifecycle of the event went through, false if at any point the event propagation was halted.

get

(
  • module
  • key
  • lang
)

Provided by the intl module.

Defined in intl/js/Intl.js:90

Gets the module's localized resources for the currently active language (as provided by the getLang method).

Optionally, the localized resources for alternate languages which have been added to Intl (see the add method) can be retrieved by providing the BCP 47 language tag as the lang parameter.

Parameters:

  • module String

    The module name.

  • key String

    Optional. A single resource key. If not provided, returns a copy (shallow clone) of all resources.

  • lang String

    Optional. The BCP 47 language tag. If not provided, the module's currently active language is used.

Returns:

String | Object A copy of the module's localized resources, or a single value if key is provided.

getAvailableLangs

(
  • module
)
Array

Provided by the intl module.

Defined in intl/js/Intl.js:113

Gets the list of languages for which localized resources are available for a given module, based on the module meta-data (part of loader). If loader is not on the page, returns an empty array.

Parameters:

  • module String

    The name of the module

Returns:

Array:

The array of languages available.

getEvent

(
  • type
  • prefixed
)
CustomEvent

Returns the custom event of the provided type has been created, a falsy value otherwise

Parameters:

  • type String

    the type, or name of the event

  • prefixed String

    if true, the type is prefixed already

Returns:

CustomEvent:

the custom event or null

getLang

(
  • module
)
String

Provided by the intl module.

Defined in intl/js/Intl.js:62

Get the currently active language for the given module.

Parameters:

  • module String

    The module name.

Returns:

String:

The BCP 47 language tag.

getTargets

()

Returns an array of bubble targets for this object.

Returns:

EventTarget[]

lookupBestLang

(
  • preferredLanguages
  • availableLanguages
)
String

Defined in yui/js/intl-base.js:14

Available since 3.1.0

Returns the language among those available that best matches the preferred language list, using the Lookup algorithm of BCP 47. If none of the available languages meets the user's preferences, then "" is returned. Extended language ranges are not supported.

Parameters:

  • preferredLanguages String[] | String

    The list of preferred languages in descending preference order, represented as BCP 47 language tags. A string array or a comma-separated list.

  • availableLanguages String[]

    The list of languages that the application supports, represented as BCP 47 language tags.

Returns:

String:

The available language that best matches the preferred language list, or "".

on

(
  • type
  • fn
  • [context]
  • [arg*]
)
EventHandle

Subscribe a callback function to a custom event fired by this object or from an object that bubbles its events to this object.

 this.on("change", this._onChange, this);

Callback functions for events published with emitFacade = true will receive an EventFacade as the first argument (typically named "e"). These callbacks can then call e.preventDefault() to disable the behavior published to that event's defaultFn. See the EventFacade API for all available properties and methods. Subscribers to non-emitFacade events will receive the arguments passed to fire() after the event name.

To subscribe to multiple events at once, pass an object as the first argument, where the key:value pairs correspond to the eventName:callback.

 this.on({
                 "attrChange" : this._onAttrChange,
                 "change"     : this._onChange
             });

You can also pass an array of event names as the first argument to subscribe to all listed events with the same callback.

 this.on([ "change", "attrChange" ], this._onChange);

Returning false from a callback is supported as an alternative to calling e.preventDefault(); e.stopPropagation();. However, it is recommended to use the event methods whenever possible.

Parameters:

  • type String

    The name of the event

  • fn Function

    The callback to execute in response to the event

  • [context] Object optional

    Override this object in callback

  • [arg*] Any optional

    0..n additional arguments to supply to the subscriber

Returns:

EventHandle:

A subscription handle capable of detaching that subscription

once

(
  • type
  • fn
  • [context]
  • [arg*]
)
EventHandle

Listen to a custom event hosted by this object one time. This is the equivalent to on except the listener is immediatelly detached when it is executed.

Parameters:

  • type String

    The name of the event

  • fn Function

    The callback to execute in response to the event

  • [context] Object optional

    Override this object in callback

  • [arg*] Any optional

    0..n additional arguments to supply to the subscriber

Returns:

EventHandle:

A subscription handle capable of detaching the subscription

onceAfter

(
  • type
  • fn
  • [context]
  • [arg*]
)
EventHandle

Listen to a custom event hosted by this object one time. This is the equivalent to after except the listener is immediatelly detached when it is executed.

Parameters:

  • type String

    The name of the event

  • fn Function

    The callback to execute in response to the event

  • [context] Object optional

    Override this object in callback

  • [arg*] Any optional

    0..n additional arguments to supply to the subscriber

Returns:

EventHandle:

A subscription handle capable of detaching that subscription

parseType

(
  • type
  • [pre]
)
Array

Inherited from EventTarget: event-custom/js/event-target.js:168

Available since 3.3.0

Takes the type parameter passed to 'on' and parses out the various pieces that could be included in the type. If the event type is passed without a prefix, it will be expanded to include the prefix one is supplied or the event target is configured with a default prefix.

Parameters:

  • type String

    the type

  • [pre] String optional

    The prefix. Defaults to this._yuievt.config.prefix

Returns:

Array:

an array containing:

  • the detach category, if supplied,
  • the prefixed event type,
  • whether or not this is an after listener,
  • the supplied event type

publish

(
  • type
  • opts
)
CustomEvent

Creates a new custom event of the specified type. If a custom event by that name already exists, it will not be re-created. In either case the custom event is returned.

Parameters:

  • type String

    the type, or name of the event

  • opts Object

    optional config params. Valid properties are:

    • [broadcast=false] Boolean optional

      whether or not the YUI instance and YUI global are notified when the event is fired.

    • [bubbles=true] Boolean optional

      Whether or not this event bubbles. Events can only bubble if emitFacade is true.

    • [context=this] Object optional

      the default execution context for the listeners.

    • [defaultFn] Function optional

      the default function to execute when this event fires if preventDefault was not called.

    • [emitFacade=false] Boolean optional

      whether or not this event emits a facade.

    • [prefix] String optional

      the prefix for this targets events, e.g., 'menu' in 'menu:click'.

    • [fireOnce=false] Boolean optional

      if an event is configured to fire once, new subscribers after the fire will be notified immediately.

    • [async=false] Boolean optional

      fireOnce event listeners will fire synchronously if the event has already fired unless async is true.

    • [preventable=true] Boolean optional

      whether or not preventDefault() has an effect.

    • [preventedFn] Function optional

      a function that is executed when preventDefault() is called.

    • [queuable=false] Boolean optional

      whether or not this event can be queued during bubbling.

    • [silent] Boolean optional

      if silent is true, debug messages are not provided for this event.

    • [stoppedFn] Function optional

      a function that is executed when stopPropagation is called.

    • [monitored] Boolean optional

      specifies whether or not this event should send notifications about when the event has been attached, detached, or published.

    • [type] String optional

      the event type (valid option if not provided as the first parameter to publish).

Returns:

CustomEvent:

the custom event

removeTarget

(
  • o
)
chainable

Removes a bubble target

Parameters:

setLang

(
  • module
  • lang
)

Provided by the intl module.

Defined in intl/js/Intl.js:38

Sets the active language for the given module.

Returns false on failure, which would happen if the language had not been registered through the add() method.

Parameters:

  • module String

    The module name.

  • lang String

    The BCP 47 language tag.

Returns:

boolean true if successful, false if not.

subscribe

() deprecated

Inherited from EventTarget: event-custom/js/event-target.js:346

Deprecated: use on

subscribe to an event

unsubscribe

() deprecated

Inherited from EventTarget: event-custom/js/event-target.js:469

Deprecated: use detach

detach a listener

unsubscribeAll

(
  • type
)
deprecated

Inherited from EventTarget: event-custom/js/event-target.js:490

Deprecated: use detachAll

Removes all listeners from the specified event. If the event type is not specified, all listeners from all hosted custom events will be removed.

Parameters:

  • type String

    The type, or name of the event

Events

intl:langChange

Provided by the intl module.

Defined in intl/js/Intl.js:132

Notification event to indicate when the lang for a module has changed. There is no default behavior associated with this event, so the on and after moments are equivalent.

Event Payload:

  • e EventFacade

    The event facade

    The event facade contains:

    module
    The name of the module for which the language changed
    newVal
    The new language tag
    prevVal
    The current language tag