My favorites | English | Sign in

gadgets.Prefs

 SUMMARY     DETAIL

Class gadgets.Prefs

Provides access to user preferences, module dimensions, and messages. Clients can access their preferences by constructing an instance of gadgets.Prefs and passing in their module id. Example:

var prefs = new gadgets.Prefs();
var name = prefs.getString("name");
var lang = prefs.getLang();

Constructor Summary

gadgets.Prefs(opt_moduleId)
Creates a new Prefs object.
 

Method Summary

 Array.<String> getArray(key)
Retrieves an array preference.
 Boolean getBool(key)
Retrieves a boolean preference.
 String getCountry()
Gets the current country, returned as ISO 3166-1 alpha-2 code.
 Number getFloat(key)
Retrieves a floating-point preference.
 Number getInt(key)
Retrieves an integer preference.
 String getLang()
Gets the current language the gadget should use when rendering, returned as a ISO 639-1 language code.
 String, Number getModuleId()
Gets the module id for the current instance.
 String getMsg(key)
Fetches an unformatted message.
 String getMsgFormatted(key, opt_subst)
Returns a message value with the positional argument opt_subst in place if it is provided or the provided example value if it is not, or the empty string if the message is not found.
 String getString(key)
Retrieves a string preference.
set(key, val)
Stores a preference.
setArray(key, val)
Stores an array preference.
 

Constructor Detail

gadgets.Prefs

gadgets.Prefs(opt_moduleId)
    Creates a new Prefs object.
    Parameters:
      String, Number opt_moduleId - An optional parameter specifying the module id to create prefs for; if not provided, the default module id is used

Method Detail

getArray

Array.<String> getArray(key)
    Retrieves an array preference. UserPref values that were not declared as lists are treated as one-element arrays.
    Parameters:
      String key - The preference to fetch
    Returns:
      Array.<String> The preference; if not set, an empty array

getBool

Boolean getBool(key)
    Retrieves a boolean preference.
    Parameters:
      String key - The preference to fetch
    Returns:
      Boolean The preference; if not set, false

getCountry

String getCountry()
    Gets the current country, returned as ISO 3166-1 alpha-2 code.
    Returns:
      String The country for this module instance

getFloat

Number getFloat(key)
    Retrieves a floating-point preference.
    Parameters:
      String key - The preference to fetch
    Returns:
      Number The preference; if not set, 0

getInt

Number getInt(key)
    Retrieves an integer preference.
    Parameters:
      String key - The preference to fetch
    Returns:
      Number The preference; if not set, 0

getLang

String getLang()
    Gets the current language the gadget should use when rendering, returned as a ISO 639-1 language code.
    Returns:
      String The language for this module instance

getModuleId

String, Number getModuleId()
    Gets the module id for the current instance.
    Returns:
      String, Number The module id for this module instance

getMsg

String getMsg(key)
    Fetches an unformatted message.
    Parameters:
      String key - The message to fetch
    Returns:
      String The message

getMsgFormatted

String getMsgFormatted(key, opt_subst)
    Returns a message value with the positional argument opt_subst in place if it is provided or the provided example value if it is not, or the empty string if the message is not found.
    Parameters:
      String key - The message to fetch
      String opt_subst - An optional string to substitute into the message
    Returns:
      String The formatted string

getString

String getString(key)
    Retrieves a string preference.
    Parameters:
      String key - The preference to fetch
    Returns:
      String The preference; if not set, an empty string

set

set(key, val)
    Stores a preference. To use this call, the gadget must require the feature setprefs.

    Note: If the gadget needs to store an Array it should use setArray instead of this call.

    Parameters:
      String key - The pref to store
      Object val - The values to store

setArray

setArray(key, val)
    Stores an array preference. To use this call, the gadget must require the feature setprefs.
    Parameters:
      String key - The pref to store
      Array val - The values to store

Documentation generated by JsDoc Toolkit 1.3.3