new util()
Utility function for the structured language overlay
Members
Promise
Wrapper class for Promises
- Source:
Methods
all(promises) → {jQuery.Promise}
Wrapper class for the $.when that is compatible with Promise.all
Parameters:
Name | Type | Description |
---|---|---|
promises |
Array.<jQuery.Promise> |
- Source:
Returns:
- Type
- jQuery.Promise
Deferred() → {jQuery.Deferred}
Wrapper class for the Deferred method
- Source:
Returns:
- Type
- jQuery.Deferred
docReady(fn) → {jQuery.Object}
Run method when document is ready.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
- Source:
Returns:
- Type
- jQuery.Object
escapeSelector(selector) → {string}
Escape a string for use as a css selector
Parameters:
Name | Type | Description |
---|---|---|
selector |
string |
- Source:
Returns:
- Type
- string
extend() → {Object}
Wrapper for jQuery.extend method. In future this can be bound to Object.assign when support allows.
Warning: if only one argument is supplied to util.extend(), this means the target argument was omitted. In this case, the jQuery object itself is assumed to be the target.
- Source:
Returns:
- Type
- Object
getDir(language) → {Object}
Determine whether a language is LTR or RTL This works around T74153 and T189036
Parameters:
Name | Type | Description |
---|---|---|
language |
Object | with 'lang' key. |
Returns:
language with 'lang' key and new 'dir' key.
- Type
- Object
getDocument() → {jQuery.Object}
Adds a class to the document
- Source:
Returns:
element representing the documentElement
- Type
- jQuery.Object
getFrequentlyUsedLanguages() → {Object}
Return a map of frequently used languages on the current device.
Returns:
- Type
- Object
getStructuredLanguages(languages, variants, frequentlyUsedLanguages, showSuggestedLanguages, deviceLanguageopt) → {StructuredLanguages}
Return two sets of languages: suggested and all (everything else)
Suggested languages are the ones that the user has used before. This also includes the user device's primary language. Suggested languages are ordered by frequency in descending order. The device's language is always at the top. This group also includes the variants.
All languages are the languages that are not suggested. Languages in this list are ordered in the lexicographical order of their language names.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
languages |
Array.<Object> | list of language objects as returned by the API |
|
variants |
Array | boolean | language variant objects or false if no variants exist |
|
frequentlyUsedLanguages |
Object | list of the frequently used languages |
|
showSuggestedLanguages |
boolean | ||
deviceLanguage |
string |
<optional> |
the device's primary language |
Returns:
- Type
- StructuredLanguages
getWindow() → {jQuery.Object}
Get the window object
- Source:
Returns:
- Type
- jQuery.Object
parseHTML(html, ctxopt) → {jQuery.Object}
Given some html, create new element(s). Unlike jQuery.parseHTML this will return a jQuery object not an array.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
html |
string | ||
ctx |
Element |
<optional> |
Document element to serve as the context in which the HTML fragment will be created |
- Source:
Returns:
- Type
- jQuery.Object
saveFrequentlyUsedLanguages(languageMap)
Save the frequently used languages to the user's device
Parameters:
Name | Type | Description |
---|---|---|
languageMap |
Object |
saveLanguageUsageCount(languageCode, frequentlyUsedLanguages)
Increment the current language usage by one and save it to the device. Cap the result at 100.
Parameters:
Name | Type | Description |
---|---|---|
languageCode |
string | |
frequentlyUsedLanguages |
Object | list of the frequently used languages |