1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!-- contributed by Erik Vold [erikvvold@gmail.com] -->
#### *Experimental*
The `simple-prefs` module lets you easily and persistently store preferences
across application restarts, which can be configured by users in the
Add-ons Manager.
Introduction
------------
With the simple preferences module you can store booleans, integers, and string
values.
Inline Options & Default Values
-------------------------------
In order to have a `options.xul` (for inline options) generated, or a
`defaults/preferences/prefs.js` for default preferences, you will need to
define the preferences in your `package.json`, like so:
{
"fullName": "Example Add-on",
...
"preferences": [{
"name": "somePreference",
"title": "Some preference title",
"type": "string",
"value": "this is the default string value"
}]
}
<api name="prefs">
@property {object}
*experimental* A persistent object private to your add-on. Properties with boolean,
number, and string values will be persisted in the Mozilla preferences system.
</api>
<api name="on">
@function
*experimental* Registers an event `listener` that will be called when a preference is changed.
**Example:**
function onPrefChange(prefName) {
console.log("The " + prefName + " preference changed.");
}
require("simple-prefs").on("somePreference", onPrefChange);
require("simple-prefs").on("someOtherPreference", onPrefChange);
@param prefName {String}
The name of the preference to watch for changes.
@param listener {Function}
The listener function that processes the event.
</api>
<api name="removeListener">
@function
*experimental* Unregisters an event `listener` for the specified preference.
@param prefName {String}
The name of the preference to watch for changes.
@param listener {Function}
The listener function that processes the event.
</api>
|