bsNotify is a configurable interface for working with Boostrap 3 alerts for jQuery. The alert syntax from http://getbootstrap.com/components/#alerts is fully implemented.
Name | Default | Description |
---|---|---|
type | error |
An error type. Each type has a corresponding Botstrap `alert-*className*` defined in `typeClasses`. This can be completely overridden with your own values and mappings. |
code | none | This is displayed in **Bold** in the alert |
message | none | The message for this alert |
prepend | true |
Whether or not to prepend to the collection it was called on, default is to prepend. If you want to append, set this to false |
attachTo | collection |
Where the alert will be placed, by default this is the collection bsNotify was called on, you can pass a jQuery object, selector, or any other input valid for `$(...)` |
dismissable | true |
Whether or not to add the `.alert-dismissable` class and close button |
typeClasses | hash |
A hash that maps the types you plan to use in `type` to a Boostrap `alert-*className*`. This can be completely overridden with your own values and mappings. |
Type | Class |
---|---|
success | alert-success |
info | alert-info |
warning | alert-warning |
error | alert-danger |
$(function(){
$('#errorDiv').bsNotify({
type: 'error',
code: 'Error 404',
message: 'Page Not Found'
});
});
$(function(){
$('#errorDiv').bsNotify({
type: 'error',
code: 'Error 404',
message: 'Page Not Found',
dismissable: false
});
});
$(function(){
$('#errorDiv').bsNotify({
type: 'error',
code: 'Error 404',
message: 'Page Not Found',
animate: false
});
});
$(function(){
$('#errorDiv').bsNotify({
type: 'error',
code: 'Error 404',
message: 'Page Not Found',
prepend: false
});
});
$(function(){
$('#errorDiv').bsNotify({
type: 'error',
code: 'Error 404',
message: 'Page Not Found',
attachTo: 'body' // can be any valid jQuery selector
});
});
$(function(){
$('#errorDiv').bsNotify({
type: 'type1',
code: 'Error 404',
message: 'Page Not Found',
typeClasses: {
type1: 'my-custom-class',
type2: 'another-custom-class'
}
});
});
This plugin was written to be resilient to customized versions of Bootstrap, though I'm sure there are edge cases. You may need to tweak this plugin to suit those instances where you have very heavily modified bootstrap beyond renamming classes and/or changing some colors. I can't help you with this.
If you have customized your copy of Bootstrap at all, and are experiencing issues, try testing the plugin with a Vanilla copy of Bootstrap.
The alerts in Bootstrap 2 are fairly similar to those in Bootstrap 3, however there is no gurantee this plugin is perfectly backwards compatible as the two versions of Bootstrap are not compatible. While it is certainly possible to re-write or modify the plugin to support Bootstrap 2, I cannot do this for you. I also encourage you to move to Bootstrap 3, it's nicer.
Copyright 2014 David Scherer
Licensed under the GPL 2.0 License. http://opensource.org/licenses/GPL-2.0