Skip to content

Commit fed25be

Browse files
committed
Migrated all options to camelCase instead of snake_case. Closes #329. New Compat module for running v3 code with v4.
1 parent c9a4a0e commit fed25be

22 files changed

+858
-235
lines changed

README.md

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,31 @@ PNotify is a JavaScript notification plugin. PNotify can provide [desktop notifi
1111

1212
Unless you're an alpha tester, **none of this README applies to you!** You want to check out the **[README on the master branch](https://github.com/sciactive/pnotify/blob/master/README.md)**.
1313

14-
This README is for **PNotify v4**. v4 is only in alpha stage, but it's got some huge changes:
14+
This README is for **PNotify 4**. v4 is only in alpha stage, but it's got some huge changes:
1515

1616
* jQuery is no longer required. v4 doesn't require any libraries, actually.
1717
* It's built using [Svelte](http://svelte.technology), which means it compiles down to vanilla JS.
1818
* PNotify now has an ES6 module build.
19-
* `text_escape` and `title_escape` have been replaced by `trust_text` and `trust_title`, and the default behavior changed.
19+
* All options are now in camelCase instead of snake_case.
20+
* `text_escape` and `title_escape` have been replaced by `textTrusted` and `titleTrusted`, and the default behavior changed.
2021
* `insert_brs` option has gone away. (Text and title now have `white-space: pre-line;`.)
2122
* The default width was raised from 300px to 360px.
23+
* There is a Compat module available to allow you to run PNotify 3 code with PNotify 4.
24+
25+
## Running PNotify 3 Code with the Compat Module
26+
27+
You can require `PNotifyCompat` instead of `PNotify` in order to run PNotify 3 code. Check out `index-compat.html` for more examples.
28+
29+
```js
30+
requirejs(['PNotifyCompat'], function(PNotify){
31+
PNotify = PNotify && PNotify.__esModule ? PNotify['default'] : PNotify;
32+
33+
new PNotify({
34+
title: 'Regular Notice',
35+
text: 'Check me out! I\'m a notice.'
36+
});
37+
});
38+
```
2239

2340
# Getting Started
2441

@@ -107,7 +124,7 @@ PNotify.error({
107124
});
108125
```
109126

110-
Or you can manually create a new notice (but, why would you?):
127+
Or you can manually create a new notice:
111128

112129
```js
113130
new PNotify({
@@ -122,24 +139,24 @@ new PNotify({
122139
# Options
123140

124141
* `title: false` - The notice's title.
125-
* `trust_title: false` - Whether to trust the title or escape its contents. (Not allow HTML.)
142+
* `titleTrusted: false` - Whether to trust the title or escape its contents. (Not allow HTML.)
126143
* `text: false` - The notice's text.
127-
* `trust_text: false` - Whether to trust the text or escape its contents. (Not allow HTML.)
144+
* `textTrusted: false` - Whether to trust the text or escape its contents. (Not allow HTML.)
128145
* `styling: "brighttheme"` - What styling classes to use. (Can be "brighttheme", "bootstrap3", "bootstrap4", or a styling object. See the source in PNotifyStyleMaterial.html for the properties in a style object.)
129146
* `icons: "brighttheme"` - What icons classes to use (Can be "brighttheme", "bootstrap3", "fontawesome4", "fontawesome5", or an icon object. See the source in PNotifyStyleMaterial.html for the properties in an icon object.)
130-
* `addclass: ""` - Additional classes to be added to the notice. (For custom styling.)
131-
* `cornerclass: ""` - Class to be added to the notice for corner styling.
132-
* `auto_display: true` - Display the notice when it is created. Turn this off to add notifications to the history without displaying them.
147+
* `addClass: ""` - Additional classes to be added to the notice. (For custom styling.)
148+
* `cornerClass: ""` - Class to be added to the notice for corner styling.
149+
* `autoDisplay: true` - Display the notice when it is created. Turn this off to add notifications to the history without displaying them.
133150
* `width: "360px"` - Width of the notice.
134-
* `min_height: "16px"` - Minimum height of the notice. It will expand to fit content.
151+
* `minHeight: "16px"` - Minimum height of the notice. It will expand to fit content.
135152
* `type: "notice"` - Type of the notice. "notice", "info", "success", or "error".
136153
* `icon: true` - Set icon to true to use the default icon for the selected style/type, false for no icon, or a string for your own icon class.
137154
* `animation: "fade"` - The animation to use when displaying and hiding the notice. "none" and "fade" are supported through CSS. Others are supported through the Animate module and Animate.css.
138-
* `animate_speed: "normal"` - Speed at which the notice animates in and out. "slow", "normal", or "fast". Respectively, 400ms, 250ms, 100ms.
155+
* `animateSpeed: "normal"` - Speed at which the notice animates in and out. "slow", "normal", or "fast". Respectively, 400ms, 250ms, 100ms.
139156
* `shadow: true` - Display a drop shadow.
140157
* `hide: true` - After a delay, close the notice.
141158
* `delay: 8000` - Delay in milliseconds before the notice is closed.
142-
* `mouse_reset: true` - Reset the hide timer if the mouse moves over the notice.
159+
* `mouseReset: true` - Reset the hide timer if the mouse moves over the notice.
143160
* `remove: true` - Remove the notice's elements from the DOM after it is closed.
144161
* `destroy: true` - Whether to remove the notice from the global array when it is closed.
145162
* `stack: PNotify.defaultStack` - The stack on which the notices will be placed. Also controls the direction the notices stack.
@@ -170,12 +187,12 @@ Changing a default option for modules can be done in a couple ways.
170187

171188
```js
172189
// This will change the default for every notice and is the recommended way.
173-
PNotify.modules.History.defaults.max_in_stack = 10;
190+
PNotify.modules.History.defaults.maxInStack = 10;
174191

175192
// This will change the default only for notices that don't specify any module options.
176193
PNotify.defaults.modules = {
177194
History: {
178-
max_in_stack: 10
195+
maxInStack: 10
179196
}
180197
};
181198
```
@@ -197,12 +214,12 @@ PNotify.defaults.modules = {
197214

198215
`Buttons: {`
199216
* `closer: true` - Provide a button for the user to manually close the notice.
200-
* `closer_hover: true` - Only show the closer button on hover.
217+
* `closerHover: true` - Only show the closer button on hover.
201218
* `sticker: true` - Provide a button for the user to manually stick the notice.
202-
* `sticker_hover: true` - Only show the sticker button on hover.
203-
* `show_on_nonblock: false` - Show the buttons even when the nonblock module is in use.
219+
* `stickerHover: true` - Only show the sticker button on hover.
220+
* `showOnNonblock: false` - Show the buttons even when the nonblock module is in use.
204221
* `labels: {close: "Close", stick: "Stick", unstick: "Unstick"}` - Lets you change the displayed text, facilitating internationalization.
205-
* `classes: {closer: null, pin_up: null, pin_down: null}` - The classes to use for button icons. Leave them null to use the classes from the styling you're using.
222+
* `classes: {closer: null, pinUp: null, pinDown: null}` - The classes to use for button icons. Leave them null to use the classes from the styling you're using.
206223

207224
`}`
208225

@@ -216,7 +233,7 @@ PNotify.defaults.modules = {
216233
## Mobile Module
217234

218235
`Mobile: {`
219-
* `swipe_dismiss: true` - Let the user swipe the notice away.
236+
* `swipeDismiss: true` - Let the user swipe the notice away.
220237
* `styling: true` - Styles the notice to look good on mobile.
221238

222239
`}`
@@ -227,8 +244,8 @@ The Animate module requires you to include [Animate.css](https://daneden.github.
227244

228245
`Animate: {`
229246
* `animate: false` - Use animate.css to animate the notice.
230-
* `in_class: ""` - The class to use to animate the notice in.
231-
* `out_class: ""` - The class to use to animate the notice out.
247+
* `inClass: ""` - The class to use to animate the notice in.
248+
* `outClass: ""` - The class to use to animate the notice out.
232249

233250
`}`
234251

@@ -239,16 +256,16 @@ The Animate module also creates a method, `attention`, on notices which accepts
239256
`Confirm: {`
240257
* `confirm: false` - Make a confirmation box.
241258
* `prompt: false` - Make a prompt.
242-
* `prompt_class: ""` - Classes to add to the input element of the prompt.
243-
* `prompt_value: ""` - The value of the prompt. (Note that this is two-way bound to the input.)
244-
* `prompt_multi_line: false` - Whether the prompt should accept multiple lines of text.
259+
* `promptClass: ""` - Classes to add to the input element of the prompt.
260+
* `promptValue: ""` - The value of the prompt. (Note that this is two-way bound to the input.)
261+
* `promptMultiLine: false` - Whether the prompt should accept multiple lines of text.
245262
* `align: "right"` - Where to align the buttons. (right, center, left, justify)
246263

247264
```js
248265
buttons: [
249266
{
250267
text: "Ok",
251-
trustText: false,
268+
textTrusted: false,
252269
addClass: "",
253270
primary: true,
254271
promptTrigger: true,
@@ -259,7 +276,7 @@ buttons: [
259276
},
260277
{
261278
text: "Cancel",
262-
trustText: false,
279+
textTrusted: false,
263280
addClass: "",
264281
click: (notice) => {
265282
notice.close();
@@ -293,7 +310,7 @@ PNotify.alert({
293310

294311
`History: {`
295312
* `history: true` - Place the notice in the history.
296-
* `max_in_stack: Infinity` - Maximum number of notices to have open in its stack.
313+
* `maxInStack: Infinity` - Maximum number of notices to have open in its stack.
297314

298315
`}`
299316

@@ -306,15 +323,15 @@ In PNotify v3, the history module could make a dropdown which had these function
306323

307324
## Callbacks Module
308325

309-
The callback options all expect one argument, a function, which will be called when that event occurs. If the function returns false on the "before_open" or "before_close" callback, that event will be canceled.
326+
The callback options all expect one argument, a function, which will be called when that event occurs. If the function returns false on the "beforeOpen" or "beforeClose" callback, that event will be canceled. `beforeInit` and `afterInit` will only work for notices created with the helper functions.
310327

311328
`Callbacks: {`
312-
* `before_init` - This option is called before the notice has been initialized. It accepts one argument, the options object.
313-
* `after_init` - This option is called after the notice has been initialized. It accepts one argument, the notice object.
314-
* `before_open` - This option is called before the notice has been displayed. It accepts one argument, the notice object.
315-
* `after_open` - This option is called after the notice has been displayed. It accepts one argument, the notice object.
316-
* `before_close` - This option is called before the notice closes. It accepts one argument, the notice object.
317-
* `after_close` - This option is called after the notice closes. It accepts one argument, the notice object.
329+
* `beforeInit` - This option is called before the notice has been initialized. It accepts one argument, the options object.
330+
* `afterInit` - This option is called after the notice has been initialized. It accepts one argument, the notice object.
331+
* `beforeOpen` - This option is called before the notice has been displayed. It accepts one argument, the notice object.
332+
* `afterOpen` - This option is called after the notice has been displayed. It accepts one argument, the notice object.
333+
* `beforeClose` - This option is called before the notice closes. It accepts one argument, the notice object.
334+
* `afterClose` - This option is called after the notice closes. It accepts one argument, the notice object.
318335

319336
`}`
320337

@@ -390,7 +407,7 @@ A stack is an object which PNotify uses to determine where to position notices.
390407

391408
You can set a stack as modal by setting the `modal` property to true. A modal stack creates an overlay behind it when any of its notices are open. When the last notice within it is closed, the overlay is removed.
392409

393-
If the `overlay_close` property is set to true, then clicking the overlay will close all of the notices in that stack.
410+
If the `overlayClose` property is set to true, then clicking the overlay will close all of the notices in that stack.
394411

395412
## Example Stacks
396413

@@ -420,7 +437,7 @@ const stack_modal = {
420437
"firstpos1": 25,
421438
"push": "top",
422439
"modal": true,
423-
"overlay_close": true
440+
"overlayClose": true
424441
};
425442
const stack_bar_top = {
426443
"dir1": "down",
@@ -470,7 +487,7 @@ This will create a notice that is positioned 90px from the top edge and 90px fro
470487
* Notification types: notice, info, success, and error.
471488
* Stacks allow notices to position together or independently.
472489
* Control stack direction and push to top or bottom.
473-
* Full RTL language support.
490+
* RTL language support.
474491
* Feature rich API.
475492
* Desktop notifications based on the Web Notifications standard.
476493
* Confirm dialogs, alert buttons, and prompts.

0 commit comments

Comments
 (0)