forked from pusewicz/sonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
campfire.js
51 lines (41 loc) · 1.53 KB
/
campfire.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
var Campfire = Class.create(Widget, {
initialize: function($super, widget_id, config) {
this.messages = [];
return($super(widget_id, config));
},
handlePayload: function(payload) {
if(this.messages.length >= this.config.nitems) {
this.messages.shift();
}
this.messages.push(payload);
},
build: function() {
this.contentContainer = this.buildContent();
this.headerContainer = this.buildHeader();
this.iconContainer = this.buildWidgetIcon();
this.container.insert(this.headerContainer);
this.container.insert(this.iconContainer);
this.container.insert(this.contentContainer);
new Draggable(this.container, { scroll: window });
},
update: function() {
this.contentContainer.childElements().invoke('remove');
this.messages.reverse(false).each(function(message) {
var cont = new Element('p');
cont.insert(new Element('img', { src: message.avatar, width: 48, height: 48 }));
cont.insert(new Element('div', { 'class': 'author' }).update(message.user));
cont.insert(new Element('div', { 'class': 'message' }).update(message.body));
cont.insert(new Element('hr' ));
this.contentContainer.insert(cont);
}.bind(this));
},
buildHeader: function() {
return(new Element("h2", { 'class': 'handle' }).update(this.title));
},
buildWidgetIcon: function() {
return(new Element("img", {src: "images/campfire.png", 'class': 'campfire icon'}));
},
buildContent: function() {
return(new Element("div", { 'class': "content" }));
},
});