aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Kavlie <akavlie@gmail.com>2011-11-05 00:32:25 -0700
committerAaron Kavlie <akavlie@gmail.com>2011-11-05 00:32:25 -0700
commitde6b00eef455eec231d701a75e7890f4819000c6 (patch)
treed9e3de9aa28543c3d166e062cd22f509d4847db0
parent413ff06c6bb91bb7f8c366845f86cad7e6ec06b1 (diff)
downloadreevo-webirc-de6b00eef455eec231d701a75e7890f4819000c6.tar.gz
reevo-webirc-de6b00eef455eec231d701a75e7890f4819000c6.zip
Split out nick list into separate view
Method for adding all nicks to the list is now much faster (channel switching had a noticeable delay before).
-rw-r--r--app.js54
1 files changed, 45 insertions, 9 deletions
diff --git a/app.js b/app.js
index 9ca9486..5aaf348 100644
--- a/app.js
+++ b/app.js
@@ -128,6 +128,46 @@ $(function() {
128 } 128 }
129 }); 129 });
130 130
131 // Nick in the sidebar
132 var NickListView = Backbone.View.extend({
133 el: $('.nicks'),
134 initialize: function() {
135 _.bindAll(this);
136 },
137
138 // this is a temp. hack
139 tmpl: function(opStatus, nick) {
140 return '<div>' + opStatus + ' ' + nick + '</div>'
141 },
142
143 switchChannel: function(ch) {
144 ch.participants.bind('add', this.addOne, this);
145 ch.participants.bind('change', this.changeNick, this);
146 },
147
148 addOne: function(p) {
149 var text = this.tmpl(p.get('opStatus'), p.get('nick'));
150 $(this.el).append(text);
151 },
152
153 addAll: function(participants) {
154 var self = this;
155 var nicks = [];
156 participants.each(function(p) {
157 var text = self.tmpl(p.get('opStatus'), p.get('nick'));
158 nicks.push(text);
159 });
160 $(this.el).html(nicks.join('\n'));
161 },
162
163 changeNick: function() {
164 console.log('Change of nick seen');
165 console.log(arguments);
166 }
167
168 });
169 var nickList = new NickListView;
170
131 var FrameView = Backbone.View.extend({ 171 var FrameView = Backbone.View.extend({
132 el: $('#frame'), 172 el: $('#frame'),
133 // to track scroll position 173 // to track scroll position
@@ -153,11 +193,6 @@ $(function() {
153 } 193 }
154 }, 194 },
155 195
156 addNick: function(person) {
157 // TODO: Use a template here!
158 this.$('.nicks').append('<div>' + person.get('opStatus') + person.get('nick') + '</div>');
159 },
160
161 // Switch focus to a different frame 196 // Switch focus to a different frame
162 focus: function(frame) { 197 focus: function(frame) {
163 // Save scroll position for frame before switching 198 // Save scroll position for frame before switching
@@ -167,13 +202,14 @@ $(function() {
167 this.focused = frame; 202 this.focused = frame;
168 frames.setActive(this.focused); 203 frames.setActive(this.focused);
169 this.$('#output').empty(); 204 this.$('#output').empty();
170 this.$('.nicks').empty();
171 205
172 var self = this; 206 var self = this;
173 frame.stream.each(function(message) { 207 frame.stream.each(function(message) {
174 self.addMessage(message, false); 208 self.addMessage(message, false);
175 }); 209 });
176 frame.participants.each(this.addNick); 210
211 nickList.addAll(frame.participants);
212
177 if (frame.get('name') == 'status') 213 if (frame.get('name') == 'status')
178 this.$('.nicks').hide(); 214 this.$('.nicks').hide();
179 else 215 else
@@ -185,10 +221,10 @@ $(function() {
185 // Only the selected frame should send messages 221 // Only the selected frame should send messages
186 frames.each(function(frm) { 222 frames.each(function(frm) {
187 frm.stream.unbind('add'); 223 frm.stream.unbind('add');
188 frm.participants.unbind('add'); 224 frm.participants.unbind();
189 }); 225 });
190 frame.stream.bind('add', this.addMessage, this); 226 frame.stream.bind('add', this.addMessage, this);
191 frame.participants.bind('add', this.addNick, this); 227 nickList.switchChannel(frame);
192 }, 228 },
193 229
194 updateNicks: function(model, nicks) { 230 updateNicks: function(model, nicks) {