-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessages.js
More file actions
40 lines (32 loc) · 1023 Bytes
/
messages.js
File metadata and controls
40 lines (32 loc) · 1023 Bytes
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
function Messages(clear, empty, firstMessage, displayMessage, displayMessageLong) {
this.messages = [];
this.clear = clear;
this.empty = empty;
this.firstMessage = firstMessage;
this.displayMessage = displayMessage;
this.displayMessageLong = displayMessageLong;
}
Messages.prototype.hasMessages = function () {
return this.messages.length > 0;
}
Messages.prototype.showMessage = function () {
var message = this.messages[0];
var display = message.length > 16 ? this.displayMessageLong : this.displayMessage;
this.clear();
setImmediate(function() { display(message); });
}
Messages.prototype.nextMessage = function () {
if (this.messages.length < 1) return;
this.messages.splice(0, 1);
if (this.messages.length > 0) this.showMessage();
else { this.clear(); this.empty(); }
}
Messages.prototype.receive = function (message) {
var firstMessage = this.messages.length === 0;
this.messages.push(message);
if (firstMessage) {
this.firstMessage();
this.showMessage();
}
}
module.exports = Messages;