forked from shawnbot/d3-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap-alert.js
51 lines (39 loc) · 1.1 KB
/
bootstrap-alert.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
(function(exports) {
var bootstrap = (typeof exports.bootstrap === "object")
? exports.bootstrap
: (exports.bootstrap = {});
var dismiss = '[data-dismiss="alert"]';
bootstrap.alert = function() {
var alert = function(selection) {
selection.select(dismiss)
.on("click", close);
};
alert.close = function(selection) {
selection.each(close);
};
function close() {
var sel = d3.select(this),
selector = sel.attr("data-target");
if (!selector) {
selector = sel.attr("href");
}
var target = sel.select(selector);
if (d3.event) d3.event.preventDefault();
if (target.empty()) {
target = sel.classed("alert") ? sel : d3.select(sel.node().parentNode);
}
// TODO trigger?
target.classed("in", false);
if (target.classed("fade")) {
// TODO prefixed events?
target.on("transitionEnd", function() {
target.remove();
});
} else {
target.remove();
}
}
return alert;
};
// TODO automatic delegation of alert closing?
})(this);