-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrapAlert.js
More file actions
101 lines (88 loc) · 3.24 KB
/
bootstrapAlert.js
File metadata and controls
101 lines (88 loc) · 3.24 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*!
* BootstrapAlert v1.0
* Copyright MantaCode Sp. z o.o.
* Licensed under MIT
* requires: jQuery, Bootstrap
*/
(function (root, factory) {
'use strict';
if (typeof define === "function" && define.amd) {
define("bootstrapAlert", [ "jquery" ], function(a0) {
return root["BootstrapAlert"] = factory(a0);
});
} else if (typeof exports === "object") {
module.exports = factory(require("jquery"));
} else {
root["BootstrapAlert"] = factory(jQuery);
}
})(this, function($) {
'use strict';
function createBootstrapAlert() {
var BootstrapAlert = {};
function showAlert(cssClass, userConfig) {
var config = {
autoHide: true,
hideTimeout: 3000,
dissmissible: false,
parentClass: 'bootstrap-alert',
innerClass: 'bootstrap-alert-message',
title: '',
message: ''
};
$.extend(config, userConfig);
var contentStyle = [
'position: relative;',
'width: 100%;',
'left: -50%;'
].join('');
var alertContent = document.createElement('div');
alertContent.className = 'alert ' + config.innerClass + ' ' + cssClass;
alertContent.setAttribute('role', 'alert');
alertContent.style = contentStyle;
if (config.dissmissible) {
alertContent.innerHTML += [
'<button type="button" class="close" data-dismiss="alert">',
'<span aria-hidden="true">×</span>',
'</button>'
].join('');
}
alertContent.innerHTML += '<strong>' + config.title + '</strong> ' + config.message;
var alertElement = document.createElement('div');
alertElement.className = config.parentClass;
alertElement.style = [
'position: fixed;',
'width: 90%;',
'max-width: 600px;',
'left: 50%;',
'top: 15px;',
'z-index: 9999;',
].join('');
alertElement.appendChild(alertContent);
document.body.appendChild(alertElement);
if(config.autoHide) {
window.setTimeout(function() {
$(alertElement).fadeOut(function() {
$(alertElement).remove();
});
}, config.hideTimeout);
}
$(alertElement).on('closed.bs.alert', function () {
$(alertElement).remove();
});
}
BootstrapAlert.alert = function (config) {
showAlert('alert-danger', config);
};
BootstrapAlert.info = function (config) {
showAlert('alert-info', config);
};
BootstrapAlert.warning = function (config) {
showAlert('alert-warning', config);
};
BootstrapAlert.success = function (config) {
showAlert('alert-success', config);
};
return BootstrapAlert;
}
return createBootstrapAlert();
});