-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationCenter.js
More file actions
64 lines (58 loc) · 1.91 KB
/
NotificationCenter.js
File metadata and controls
64 lines (58 loc) · 1.91 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
// Could be a singleton, training the prototype chain
function NotificationCenter(x,y,width,height) {
this.limit=4;
this.notifications = [];
this.container = new createjs.Container();
this.container.x=x;
this.container.y=y;
this.textWidth=width-20;
this.textHeight=height;
stage.addChild(this.container);
}
// Add a couple of methods to NotificationCenter.prototype
NotificationCenter.prototype.add = function(message){
var shape, text, container;
shape = new createjs.Shape();
shape.graphics.beginFill("#FFF");
shape.graphics.drawRoundRect(0,0,this.textWidth,this.textHeight,4);
shape.x=0; shape.y=0;
text = new createjs.Text(message, "18px Calibri", "#808080");
text.x=10;
text.y=this.textHeight/2;
text.textBaseline="middle";
container = new createjs.Container();
//this.container.addChild(container);
container.addChild(shape);
container.addChild(text);
container.key=message+"_"+Math.random();
container.on('click',this.close.bind(this));
//console.log(container);
this.notifications.push(container);
this.showNotifications();
};
NotificationCenter.prototype.showNotifications = function(){
this.container.removeAllChildren();
var i, limit, yPos=0;
limit=this.limit;
if(this.limit>this.notifications.length){
limit=this.notifications.length;
}
for(i=0; i<limit; i++){
this.notifications[i].y=yPos;
yPos+= 40;
this.container.addChild(this.notifications[i]);
}
};
NotificationCenter.prototype.close = function(e){
var i;
console.log(e.currentTarget);
for(i=0; i<this.notifications.length; i++){
//console.log(this.notifications[i]);
if(this.notifications[i].key == e.currentTarget.key) {
this.container.removeChild(e.currentTarget);
this.notifications.splice(i,1);
break;
}
}
this.showNotifications();
};