Skip to content

Commit

Permalink
Move addMessage code into ChatView.
Browse files Browse the repository at this point in the history
  • Loading branch information
akavlie committed Jan 14, 2012
1 parent 20d1555 commit be2f47a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion assets/css/subway.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
width: 100%;
}

.message_me{
.message-me {
background: #F9F9F9;
}

Expand Down
4 changes: 0 additions & 4 deletions assets/js/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
var Stream = Backbone.Collection.extend({
model: Message,

initialize: function() {
this.bind('add', irc.appView.addMessage);
},

unread: function() {
return this.filter(function(msg) { return msg.get('unread'); });
},
Expand Down
2 changes: 1 addition & 1 deletion assets/js/views/channel_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var ChannelListView = Backbone.View.extend({

addChannel: function(chat) {
console.log('channel added to list');
var view = new ChannelTabView({model: chat})
var view = new ChannelTabView({model: chat});
$(this.el).append(view.render().el);
irc.chatWindows.setActive(chat);
view.setActive();
Expand Down
23 changes: 22 additions & 1 deletion assets/js/views/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var ChatView = Backbone.View.extend({
this.el = ich.chat();
this.render();
this.model.bind('change:topic', this.updateTitle, this);
this.model.stream.bind('add', this.addMessage, this);
},

updateTitle: function(channel) {
Expand Down Expand Up @@ -82,5 +83,25 @@ var ChatView = Backbone.View.extend({
}
}
});
}
},

addMessage: function(msg) {
var view = new MessageView({model: msg});
$('#chat-contents').append(view.el);

if (msg.get('sender') === irc.me.nick) {
$(view.el).addClass('message-me');
}

// Scroll down to show new message
var chatWindowHeight = ($('#chat-contents')[0].scrollHeight - 555);
// If the window is large enough to be scrollable
if (chatWindowHeight > 0) {
// If the user isn't scrolling go to the bottom message
if ((chatWindowHeight - $('#chat-contents').scrollTop()) < 200) {
$('#chat-contents').scrollTo(view.el, 500);
}
}
},

});
20 changes: 0 additions & 20 deletions assets/js/views/chat_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@ var ChatApplicationView = Backbone.View.extend({
return this;
},

addMessage: function(msg) {
var view = new MessageView({model: msg});
var targetDiv = this.channel.view.$('#chat-contents');
targetDiv.append(view.el);

if (msg.get('sender') === irc.me.nick) {
$(view.el).addClass('message_me');
}

console.log('message added!');
var chatWindowHeight = (targetDiv.get(0).scrollHeight-555);
// If the window is large enough to be scrollable
if(chatWindowHeight > 0) {
// If the user isn't scrolling go to the bottom message
if ((chatWindowHeight - targetDiv.scrollTop()) < 200) {
targetDiv.scrollTo(view.el, 500);
}
}
},

focus: function(chat) {
if (!chat.get('active')) {
return;
Expand Down

0 comments on commit be2f47a

Please sign in to comment.