-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap-alerts.js
58 lines (47 loc) · 1.37 KB
/
bootstrap-alerts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Bootstrap Alerts v1.2.2, jQuery plugin
*
* Copyright(c) 2015, Javier Prieto
* http://jprieton.github.io/bootstrap-alerts/
*
* A jQuery plugin for displaying Bootstrap alerts.
* Licensed under the MIT License
*/
(function ($) {
'use strict';
$.fn.bootstrapAlert = function (options) {
var settings = $.extend({
type: 'info',
dismissible: true,
heading: '',
message: '',
clear: true
}, options);
if (settings.type.length === 0) {
console.log('bootstrapAlert: type is empty');
return false;
}
if (settings.message.length === 0) {
console.log('bootstrapAlert: message is empty');
return false;
}
var div = $('<div class="alert alert-' + settings.type + '" role="alert">');
if (settings.dismissible) {
$(div).addClass('alert-dismissible');
var button = $('<button type="button" class="close" data-dismiss="alert" aria-label="Close">');
var span = $('<span aria-hidden="true">').html('×');
$(span).appendTo(button);
$(button).appendTo(div);
}
if (settings.heading.length > 0) {
var heading = $('<h4 class="alert-heading">').html(settings.heading);
$(heading).appendTo(div);
}
$(div).append(settings.message);
if (settings.clear) {
$(this).empty();
}
$(div).appendTo(this);
return this;
};
})(jQuery);