diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-05 12:53:38 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-05 12:53:38 -0400 |
| commit | b9aaeaf616ed0a46a81e313bede00f1598d245ca (patch) | |
| tree | 0d2256c9332b6d0ef97bb56e1c771a976f3497db /public/js/lib/chat.js | |
| parent | 21e31e46ff167ede7cb5ad4452cbd406236bc83d (diff) | |
| parent | 3b7da491072e5c366738ff549e8958d97948076a (diff) | |
mergez
Diffstat (limited to 'public/js/lib/chat.js')
| -rw-r--r-- | public/js/lib/chat.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/public/js/lib/chat.js b/public/js/lib/chat.js index 6c227eb..0968418 100644 --- a/public/js/lib/chat.js +++ b/public/js/lib/chat.js @@ -3,29 +3,46 @@ var ChatView = View.extend({ template: $("#collaborator-template").html(), events: { - "submit form": "send" + "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 = + 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 } }) |
