|
| 1 | +/** |
| 2 | + * The settings/constraints for a tip, represented in an object. |
| 3 | + * |
| 4 | + * @typedef {Object} TipObject |
| 5 | + * @property {string} id just some ID |
| 6 | + * @property {integer|null} requiredShowCount shows the message x times; set |
| 7 | + * to "null" to show infinitively |
| 8 | + * @property {bool} [allowDismiss=true] set to false to disallow dismissing |
| 9 | + * the message. This likely makes no sense for any tip, so the default is true. |
| 10 | + * @property {bool|integer} [requireDismiss=false] show the message, if it is |
| 11 | + * not, at least, dismissed for x times. Alternatively set to true to require |
| 12 | + * that message is dismissed the exact same number as requiredShowCount states, |
| 13 | + * i.e. only dismissed count as "tip shown". |
| 14 | + * @property {integer|null} [maximumDismiss=null] hides the message, if it |
| 15 | + * has been dismissed x times. |
| 16 | + * @property {integer} [requiredTriggers=10] require some displays ("triggers") |
| 17 | + * of (any) add-on page before showing tip. This is effectively just a minimum |
| 18 | + * limit, so it is not shown too "early". |
| 19 | + * @property {Object.<string: integer>} [showInContext] a key-value object with |
| 20 | + * context -> num to require the tip to be shown in a specific context for the |
| 21 | + * given number of times. See {@link RandomTips.setContext}. |
| 22 | + * @property {Object.<string: integer>} [maximumInContest] a key-value object with |
| 23 | + * context -> num to only show the tip in a specific context at most for the |
| 24 | + * given number of times. See {@link RandomTips.setContext}. |
| 25 | + * @property {bool|integer} [randomizeDisplay] Randomizes the display with a |
| 26 | + * chance of 50% by default (when set to "true"). You can override that percentage |
| 27 | + * (as an integer, e.g. 0.2 instead of 20%). |
| 28 | + * Note that the tip message display in general is already randomized |
| 29 | + * with a chance of 20%, see {@link RandomTips.GLOBAL_RANDOMIZE}. |
| 30 | + * @property {string} text The text to actually show. It is passed to the |
| 31 | + * {@link MessageHandler}, so you can (& should) use a translatable string here. |
| 32 | + * @property {Object} [actionButton] adds an action button to the message // TODO: document action button |
| 33 | + */ |
| 34 | + |
| 35 | +/** |
| 36 | + * An array of all tips. |
| 37 | + * |
| 38 | + * @private |
| 39 | + * @const |
| 40 | + * @type {Array.<TipObject>} |
| 41 | + */ |
| 42 | +const tipArray = [ |
| 43 | + { |
| 44 | + id: "likeAddon", |
| 45 | + requiredShowCount: 3, |
| 46 | + requireDismiss: 1, |
| 47 | + maximumDismiss: 2, |
| 48 | + requiredTriggers: 10, |
| 49 | + showInContext: { |
| 50 | + "popup": 1 |
| 51 | + }, |
| 52 | + randomizeDisplay: false, |
| 53 | + text: "tipYouLikeAddon", |
| 54 | + actionButton: { |
| 55 | + text: "tipYouLikeAddonButton", |
| 56 | + action: "https://addons.mozilla.org/firefox/addon/.../reviews/" |
| 57 | + } |
| 58 | + } |
| 59 | +]; |
| 60 | + |
| 61 | +// freeze the inner tib objects, this is strongly recommend |
| 62 | +tipArray.forEach((object) => Object.freeze(object)); |
| 63 | + |
| 64 | +/** |
| 65 | + * The list of all tips. (now exported) |
| 66 | + * |
| 67 | + * @public |
| 68 | + * @const |
| 69 | + * @type {Array.<TipObject>} |
| 70 | + */ |
| 71 | +export const tips = Object.freeze(tipArray); |
0 commit comments