-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTips.js
120 lines (115 loc) · 4.96 KB
/
Tips.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Data of the random tips.
*
* @public
* @module data/Tips
*/
/**
* The settings/constraints for a tip, represented in an object.
*
* @public
* @typedef {Object} TipObject
* @property {string} id just some ID
* @property {integer|null} requiredShowCount Shows the message x times; set
* to `null` to show infinitively. This is the maximum value.
* @property {bool} [allowDismiss=true] set to false to disallow dismissing
* the message. This likely makes no sense for any tip, so the default is true.
* @property {bool|integer} [requireDismiss=false] show the message, if it is
* not, at least, dismissed for x times. Alternatively set to true to require
* that message is dismissed the exact same number as requiredShowCount states,
* i.e. only dismissed count as "tip shown".
* @property {integer|null} [maximumDismiss=null] hides the message, if it
* has been dismissed x times.
* @property {integer} [requiredTriggers=10] require some displays ("triggers")
* of (any) add-on page before showing tip. This is effectively just a minimum
* limit, so it is not shown too "early".
* @property {Object.<string, integer>} [showInContext] a key-value object with
* context -> num to require the tip to be shown in a specific context for the
* given number of times. See {@link RandomTips.setContext}.
* @property {Object.<string, integer>} [maximumInContest] a key-value object with
* context -> num to only show the tip in a specific context at most for the
* given number of times. See {@link RandomTips.setContext}.
* @property {bool|integer} [randomizeDisplay=false] Randomizes the display with a
* chance of 50% by default (when set to `true`). You can override that percentage
* by specifying an integer < 1 (e.g. 0.2 for a 20% chance) as a propability.
* The chance is the chance that the tip *is shown*, i.e. the tip is shown for
* <= p and not shown for > p if p is the propbability you pass.
* Note that the tip message display in general is already randomized
* with a chance of 20%, see {@link RandomTips.GLOBAL_RANDOMIZE}.
* @property {string} text The text to actually show. It is passed to the
* {@link MessageHandler}, so you can (& should) use a translatable string here.
* @property {Object} [actionButton] adds an action button to the message, is
* passed as-is to the {@link MessageHandler} module.
* @property {string} actionButton.text the text to use for the button
* @property {string|function} actionButton.action the link or function to
* execute on click
* @property {callbackShowTip} [showTip] evaluate via a custom function
* whether to show or not to show the tip
*/
/**
* Custom function to check whether a tip shall be shown or not.
*
* **Attention:** This is evaluated before all other constraints were evaluated.
* Be careful before returning `true`, you may actually want to return `null`.
*
* * If you return `true`, it means you **force**(!) the tip to be shown. This
* overrides the usual conditions and shows the tip immediately.
* * If you return `false`, it means you disallow the tip to be shown.
* * If `null` is returned, the usual (other) conditions that determinate whether
* to show the tip are evaluated.
* If you throw something, this cancels the whole tip selection process.
*
* Note that you can actually _modify_ the values of the first two parameters, i.e.
* `tipSpec` and `thisTipConfig`. If you modify the config, it will be saved
* automatically.
* The difference between `tipSpec` and `tipSpecOrig` is, that in `tipSpec` the
* default values of the tips have been added/modified, if needed and that
* `tipSpecOrig` is the original as you have specified it in {@link TipObject}.
*
* For stylistic reasons, it is recommend to not hardcode the function into the
* this file, but use a separate file/module.
*
* @public
* @callback callbackShowTip
* @param {TipObject} tipSpec the TipObject, merged with default values
* @param {module:RandomTips~TipConfigObject} thisTipConfig the settings of the tip
* @param {TipObject} tipSpecOrig the original, unmodified (frozen) TipObject
* of the tip
* @param {module:RandomTips~ModuleConfig} moduleConfig the whole config of this module
* @return {boolean|null}
*/
/**
* An array of all tips.
*
* @private
* @const
* @type {Array.<TipObject>}
*/
const tipArray = [
{
id: "likeAddon",
requiredShowCount: 3,
requireDismiss: 1,
maximumDismiss: 2,
requiredTriggers: 10,
showInContext: {
"popup": 1
},
randomizeDisplay: false,
text: "tipYouLikeAddon",
actionButton: {
text: "tipYouLikeAddonButton",
action: "https://addons.mozilla.org/firefox/addon/.../reviews/"
}
}
];
// freeze the inner tip objects, this is strongly recommend
tipArray.forEach((object) => Object.freeze(object));
/**
* The list of all tips. (now exported)
*
* @public
* @const
* @type {Array.<TipObject>}
*/
export const tips = Object.freeze(tipArray);