blob: 0968418542a9be2f74e0b938f0adeeddfc9e4fd1 (
plain)
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
|
var ChatView = View.extend({
template: $("#collaborator-template").html(),
events: {
"submit form": "send",
"scroll #messages": "scroll",
},
initialize: function(){
this.$msg = this.$("#message")
this.$messages = this.$("#messages")
this.messages = this.$messages.get(0)
},
add: function(msg){
var $el = $( this.template )
$el.find(".nick").html(msg.nick)
$el.find(".msg").html(msg.msg)
this.$messages.append($el)
if (! this.scrolled) {
this.scrollToBottom()
}
},
send: function(){
var val = this.$msg.sanitize()
if (! val) return
var msg = {}
msg.room = room.name()
msg.msg = val
msg.nick = user.username
// app.socket.send("message", msg)
},
empty: function(){
this.$messages.empty()
},
scrolled: false,
scroll: function(){
this.scrolled = (this.messages.scrollTop > this.messages.scrollHeight - this.$el.height() - 100)
},
scrollToBottom: function(){
this.messages.scrollTop = document.body.scrollHeight
}
})
|