-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-toasts.js
More file actions
72 lines (63 loc) · 2.06 KB
/
angular-toasts.js
File metadata and controls
72 lines (63 loc) · 2.06 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
angular.module("angular-toasts", []).directive("toast", ["$timeout", function ($timeout) {
return {
replace: true,
templateUrl: "template/toast.html",
link: function (scope, element, attrs) {
var options = angular.extend({
timeout: 4000,
position: "top"
}, scope.$eval(attrs.toast));
var queue = [];
scope.alertClass = "alert-success";
(function init() {
$(element).css({
display: "none",
position: "fixed",
left: "50%",
zIndex: "2000"
});
if (options.position == "top") {
$(element).css({ top: "20px" });
}
else if (options.position == "bottom") {
$(element).css({ bottom: "10px" });
}
})();
function showToast(toastOptions) {
scope.alertClass = toastOptions.type || "alert-info";
scope.text = toastOptions.text;
$timeout(function () {
$(element).css({
display: "block",
marginLeft: -$(element).width() / 2,
});
});
$timeout(function () {
if (toastOptions.reload) {
location.reload();
} else {
$(element).fadeOut(function() {
if (queue.length > 0) {
showToast(queue.pop());
}
});
}
}, options.timeout);
};
scope.$on("toast", function (evt, toastOptions) {
if ($(element).is(":visible")) {
queue.push(toastOptions);
} else {
showToast(toastOptions);
}
});
}
};
}])
.run(["$templateCache", function ($templateCache) {
$templateCache.put("template/toast.html",
"\n" +
"<div class='alert' ng-class='alertClass'>\n" +
" {{text}}\n" +
"</div>\n");
}]);