Difference between revisions of "Gadgets.Prefs (v0.9)"
From VZ Developer Wiki
(→gadgets.Prefs.setArray) |
|||
Line 9: | Line 9: | ||
Currently we do not supper the datatype=”list” (array). | Currently we do not supper the datatype=”list” (array). | ||
− | Example: < | + | Example: |
+ | |||
+ | <source lang="javascript"> | ||
+ | var prefs = new gadgets.Prefs(); | ||
+ | var name = prefs.getString("name"); | ||
+ | var lang = prefs.getLang(); | ||
+ | </source> | ||
== Methods == | == Methods == |
Revision as of 11:14, 2 August 2010
This documentation is not completed yet and will be extended by more examples in future.
Contents
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.
You should only save a maximum of 2kB per User as Preferences data. Currently we do not supper the datatype=”list” (array).
Example:
var prefs = new gadgets.Prefs();
var name = prefs.getString("name");
var lang = prefs.getLang();
Methods
gadgets.Prefs.getArray
Array.<String> getArray(key)
- Parameters
Name Type Description key String The preference to fetch
- Returns
Type Description Array.<String> The preference; if not set, an empty array
- Description
Retrieves a preference as an array. UserPref values that were not declared as lists are treated as one-element arrays.
gadgets.Prefs.getBool
Boolean getBool(key)
- Parameters
Name Type Description key String The preference to fetch
- Returns
Type Description Boolean The preference; if not set, false
- Description
Retrieves a preference as a boolean.
gadgets.Prefs.getCountry
String getCountry()
- Returns
Type Description String The country for this module instance
- Description
Gets the current country, returned as ISO 3166-1 alpha-2 code.
gadgets.Prefs.getFloat
Number getFloat(key)
- Parameters
Name Type Description key String The preference to fetch
- Returns
Type Description Number The preference; if not set, 0
- Description
Retrieves a preference as a floating-point value.
gadgets.Prefs.getInt
Number getInt(key)
- Parameters
Name Type Description key String The preference to fetch
- Returns
Type Description Number The preference; if not set, 0
- Description
Retrieves a preference as an integer.
gadgets.Prefs.getLang
String getLang()
- Returns
Type Description String The language for this module instance
- Description
Gets the current language the gadget should use when rendering, returned as a ISO 639-1 language code.
gadgets.Prefs.getModuleId
String | Number getModuleId()
- Returns
Type Description String | Number The module ID for this module instance
- Description
Gets the module ID for the current instance.
gadgets.Prefs.getMsg
String getMsg(key)
- Parameters
Name Type Description key String The message to fetch
- Returns
Type Description String The message
- Description
Fetches an unformatted message.
gadgets.Prefs.getString
String getString(key)
- Parameters
Name Type Description key String The preference to fetch
- Returns
Type Description String The preference; if not set, an empty string
- Description
Retrieves a preference as a string.
gadgets.Prefs.set
set(key, val)
- Parameters
Name Type Description key String The pref to store val Object The values to store
- Description
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.
gadgets.Prefs.setArray
setArray(key, val)
- Parameters
Name Type Description key String The pref to store val Array The values to store
- Description
Stores an array preference of custom essay writing services. To use this call, the gadget must require the feature setprefs.
Examples
var prefs = new gadgets.Prefs();
var name = prefs.getString("name");
var lang = prefs.getLang();
OpenSocial (v0.9) | |||
gadgets.Prefs |