-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlay.js
94 lines (81 loc) · 2.26 KB
/
overlay.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
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
app.service("overlay", function($timeout) {
var _overlay;
var _state; // when loading set to laoding, timeout after 10s
var success = function() {
_overlay = iosOverlay({
text: "Success!",
duration: 2e3,
icon: "lib/iosOverlay/check.png"
});
};
var error = function() {
if (_overlay) {
_overlay.hide(); // Loading leading to an error...
}
_overlay = iosOverlay({
text: "Error!",
duration: 2e3,
icon: "lib/iosOverlay/cross.png"
});
};
var loading = function(text) {
if (!text) {
text = "Loading";
}
var opts = {
lines: 13, // The number of lines to draw
length: 11, // The length of each line
width: 5, // The line thickness
radius: 17, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
color: '#FFF', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
var target = document.createElement("div");
document.body.appendChild(target);
var spinner = new Spinner(opts).spin(target);
var duration = 12000;
_state = "loading";
_overlay = iosOverlay({
text: text,
duration: duration,
spinner: spinner
});
$timeout(function() {
if (_state === "loading") {
_overlay.update({
text: "Error!",
icon: "lib/iosOverlay/cross.png"
});
}
}, duration - 2000); // duration is set up already...
};
var update = function(text) {
if (! _overlay) {
console.error("Please make sure iosOverlay is instantiated by previous calls");
return;
}
_overlay.update({
text: text,
});
}
var hide = function() {
_overlay.hide();
_state = null;
};
return {
success : success,
error : error,
loading : loading,
hide : hide,
update : update
};
});