PNotify is a JavaScript notification plugin, developed by SciActive. Formerly known as Pines Notify. It is designed to provide an unparalleled level of flexibility, while still being very easy to implement and use.
PNotify provides desktop notifications based on the web notifications draft. If desktop notifications are not available or not allowed, PNotify will fall back to displaying the notice as a regular, in-browser notice.
See http://sciactive.com/pnotify/ for more information and examples.
jQuery (1.4 or higher) and either Bootstrap CSS or a jQuery UI Theme.
PNotify comes with the following files:
pnotify.custom.js
&pnotify.custom.min.js
(Minified)pnotify.custom.css
&pnotify.custom.min.css
(Minified)
So here's how you'd include them on your page:
<script type="text/javascript" src="pnotify.custom.min.js"></script>
<link href="pnotify.custom.min.css" media="all" rel="stylesheet" type="text/css" />
Now you can use PNotify like this:
<script type="text/javascript">
$(function(){
new PNotify({
title: 'Regular Notice',
text: 'Check me out! I\'m a notice.'
});
});
</script>
If you are using Bootstrap version 2, include this line somewhere before your first notice:
PNotify.prototype.options.styling = "bootstrap2";
If you are using jQuery UI for all your styling, include this line somewhere before your first notice:
PNotify.prototype.options.styling = "jqueryui";
A stack is an object which PNotify uses to determine where to position notices. A stack has two mandatory properties, dir1
and dir2
. dir1
is the first direction in which the notices are stacked. When the notices run out of room in the window, they will move over in the direction specified by dir2
. The directions can be "up"
, "down"
, "right"
, or "left"
. Stacks are independent of each other, so a stack doesn't know and doesn't care if it overlaps (and blocks) another stack. The default stack, which can be changed like any other default, goes down, then left. Stack objects are used and manipulated by PNotify, and therefore, should be a variable when passed. So, calling something like new PNotify({stack: {"dir1": "down", "dir2": "left"}});
will NOT work. It will create a notice, but that notice will be in its own stack and may overlap other notices.
var stack_topleft = {"dir1": "down", "dir2": "right", "push": "top"};
var stack_bottomleft = {"dir1": "right", "dir2": "up", "push": "top"};
var stack_bar_top = {"dir1": "down", "dir2": "right", "push": "top", "spacing1": 0, "spacing2": 0};
var stack_bar_bottom = {"dir1": "up", "dir2": "right", "spacing1": 0, "spacing2": 0};
var stack_context = {"dir1": "down", "dir2": "left", "context": $("#stack-context")};
This stack is initially positioned through code instead of CSS.
var stack_bottomright = {"dir1": "up", "dir2": "left", "firstpos1": 25, "firstpos2": 25};
This is done through two extra variables. firstpos1
and firstpos2
are pixel values, relative to a viewport edge. dir1
and dir2
, respectively, determine which edge. It is calculated as follows:
dir = "up"
- firstpos is relative to the bottom of viewport.dir = "down"
- firstpos is relative to the top of viewport.dir = "right"
- firstpos is relative to the left of viewport.dir = "left"
- firstpos is relative to the right of viewport.
To create a stack in the top left, define the stack:
var stack_topleft = {"dir1": "down", "dir2": "right"};
and then add two options to your pnotify call:
addclass: "stack-topleft", // This is one of the included default classes.
stack: stack_topleft
There are several CSS classes included which will position your notices for you:
stack-topleft
stack-bottomleft
stack-bottomright
You can create your own custom position and movement by defining a custom stack.
title: false
- The notice's title.title_escape: false
- Whether to escape the content of the title. (Not allow HTML.)text: false
- The notice's text.text_escape: false
- Whether to escape the content of the text. (Not allow HTML.)styling: "bootstrap3"
- What styling classes to use. (Can be either jqueryui, bootstrap2, bootstrap3, fontawesome, or a custom style object. See the source for the properties in a style object.)addclass: ""
- Additional classes to be added to the notice. (For custom styling.)cornerclass: ""
- Class to be added to the notice for corner styling.auto_display: true
- Display the notice when it is created. Turn this off to add notifications to the history without displaying them.width: "300px"
- Width of the notice.min_height: "16px"
- Minimum height of the notice. It will expand to fit content.type: "notice"
- Type of the notice. "notice", "info", "success", or "error".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.animation: "fade"
- The animation to use when displaying and hiding the notice. "none", "show", "fade", and "slide" are built in to jQuery. Others require jQuery UI. Use an object with effect_in and effect_out to use different effects.animate_speed: "slow"
- Speed at which the notice animates in and out. "slow", "def" or "normal", "fast" or number of milliseconds.position_animate_speed: 500
- Specify a specific duration of position animation.opacity: 1
- Opacity of the notice.shadow: true
- Display a drop shadow.hide: true
- After a delay, remove the notice.delay: 8000
- Delay in milliseconds before the notice is removed.mouse_reset: true
- Reset the hide timer if the mouse moves over the notice.remove: true
- Remove the notice's elements from the DOM after it is removed.insert_brs: true
- Change new lines to br tags.stack: {"dir1": "down", "dir2": "left", "push": "bottom", "spacing1": 25, "spacing2": 25, context: $("body")}
- The stack on which the notices will be placed. Also controls the direction the notices stack.
desktop: {
desktop: false
- Display the notification as a desktop notification.icon: null
- The URL of the icon to display. If false, no icon will show. If null, a default icon will show.
}
buttons: {
closer: true
- Provide a button for the user to manually close the notice.closer_hover: true
- Only show the closer button on hover.sticker: true
- Provide a button for the user to manually stick the notice.sticker_hover: true
- Only show the sticker button on hover.labels: {close: "Close", stick: "Stick"}
- Lets you change the displayed text, facilitating internationalization.
}
nonblock: {
nonblock: false
- Create a non-blocking notice. It lets the user click elements underneath it.nonblock_opacity: .2
- The opacity of the notice (if it's non-blocking) when the mouse is over it.
}
confirm: {
confirm: false
- Make a confirmation box.align: "right"
- Where to align the buttons. (right, center, left, justify)buttons: [{text: "Ok", addClass: "", click: function(notice){ notice.get().trigger("pnotify.confirm"); notice.remove(); }},{text: "Cancel", addClass: "", click: function(notice){ notice.get().trigger("pnotify.cancel"); notice.remove(); }}]
- The buttons to display, and their callbacks.
}
history: {
history: true
- Place the notice in the history.menu: false
- Display a pull down menu to redisplay previous notices.fixed: true
- Make the pull down menu fixed to the top of the viewport.maxonscreen: Infinity
- Maximum number of notifications to have onscreen.labels: {redisplay: "Redisplay", all: "All", last: "Last"}
- Lets you change the displayed text, facilitating internationalization.
}
reference: {
putThing: false
- Provide a thing for stuff. Turned off by default.labels: {text: "Spin Around"}
- If you are displaying any text, you should use a labels options to support internationalization.
}
The callback options all expect one argument, a function, which will be called when that event occurs. They can be included in the options object passed to $.pnotify() just like any other options. If the function returns false on the "before_open" or "before_close" callback, that event will be canceled.
before_init
- This option is called before the notice has been initialized. It accepts one argument, the options object.after_init
- This option is called after the notice has been initialized. It accepts one argument, the notice object.before_open
- This option is called before the notice has been displayed. It accepts one argument, the notice object.after_open
- This option is called after the notice has been displayed. It accepts one argument, the notice object.before_close
- This option is called before the notice closes. It accepts one argument, the notice object.after_close
- This option is called after the notice closes. It accepts one argument, the notice object.
For examples/demos see http://sciactive.com/pnotify/