User Rating: 2.8/5 ( 2 votes)
noty is a jQuery plugin that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog. Each notification is added to a queue. (Optional)
The notifications can be positioned at the:
top - topLeft - topCenter - topRight - center - centerLeft - centerRight - bottom - bottomLeft -bottomCenter - bottomRight
The API provides lots of other options to customise the text, animation, speed, buttons and much more.
It also has various callbacks for the buttons such as opening and closing the notifications and queue control.
Source: ned.im
1. INCLUDE JS FILES
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="js/noty/packaged/jquery.noty.packaged.min.js"></script>
2. JAVASCRIPT
var n = noty({text: 'noty - a jquery notification library!'});
3. OPTIONS
$.noty.defaults = {
layout: 'top',
theme: 'defaultTheme',
type: 'alert',
text: '', // can be html or string
dismissQueue: true, // If you want to use queue feature set this true
template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
animation: {
open: {height: 'toggle'},
close: {height: 'toggle'},
easing: 'swing',
speed: 500 // opening & closing animation speed
},
timeout: false, // delay for closing event. Set false for sticky notifications
force: false, // adds notification to the beginning of queue when set to true
modal: false,
maxVisible: 5, // you can set max visible notification for dismissQueue true option,
killer: false, // for close all notifications before show
closeWith: ['click'], // ['click', 'button', 'hover']
callback: {
onShow: function() {},
afterShow: function() {},
onClose: function() {},
afterClose: function() {}
},
buttons: false // an array of buttons
};
4. CALLBACKS
noty have 4 callback option for now. We will add more callback asap.
onShow - afterShow - onClose - afterClose
5. API
$.noty.get(id) - Returns a noty javascript object
$.noty.close(id) - Close a noty - same as var n = noty({text: 'Hi!'})); n.close();
$.noty.clearQueue() - Clears the notification queue
$.noty.closeAll() - Close all notifications
$.noty.setText(id, text) - Notification text updater - same as var n = noty({text: 'Hi!'})); n.setText('Hi again!');
$.noty.setType(id, type) - Notification type updater - same as var n = noty({text: 'Hi!'})); n.setType('error');
6. EXAMPLES
Custom Container
var n = $('.custom_container').noty({text: 'noty - a jquery notification library!'});
Theme
Noty is easily themable using Javascript or CSS.
Theme structre is in noty/themes/default.js file. You can copy-paste this file and change.
After that you can set your new theme with noty theme property. Like;
var n = noty({
text: 'noty - a jquery notification library!',
theme: 'your_new_theme',
});
Buttons
noty({
text: 'Do you want to continue?',
buttons: [
{addClass: 'btn btn-primary', text: 'Ok', onClick: function($noty) {
// this = button element
// $noty = $noty element
$noty.close();
noty({text: 'You clicked "Ok" button', type: 'success'});
}
},
{addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
$noty.close();
noty({text: 'You clicked "Cancel" button', type: 'error'});
}
}
]
});