From dde5dcd98f5d3f0829608e5f03bad29da16f9117 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Tue, 27 Sep 2011 12:22:54 +0100 Subject: [PATCH] Reworked client-side /list implementation --- js/front.events.js | 64 ++++++---------------------------------------- js/front.js | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/js/front.events.js b/js/front.events.js index ad0716a..08f78da 100644 --- a/js/front.events.js +++ b/js/front.events.js @@ -225,7 +225,7 @@ kiwi.front.events = { return; } - if (typeof data.idle !== 'undefined'){ + if (typeof data.idle !== 'undefined') { idle_time = secondsToTime(parseInt(data.idle, 10)); idle_time = idle_time.h.toString().lpad(2, "0") + ':' + idle_time.m.toString().lpad(2, "0") + ':' + idle_time.s.toString().lpad(2, "0"); } @@ -283,64 +283,16 @@ kiwi.front.events = { }, onChannelListStart: function (e, data) { - /*global Utilityview */ - var tab, table; - - tab = new Utilityview('Channel List'); - tab.div.css('overflow-y', 'scroll'); - table = $(''); - tab.div.append(table); - - kiwi.front.cache.list = {chans: [], tab: tab, table: table, - update: function (newChans) { - var body = this.table.children('tbody:first').detach(), - chan, - html; - - html = ''; - for (chan in newChans) { - this.chans.push(newChans[chan]); - html += newChans[chan].html; - } - body.append(html); - this.table.append(body); - - }, - finalise: function () { - var body = this.table.children('tbody:first').detach(), - list, - chan; - - list = $.makeArray($(body).children()); - - for (chan in list) { - list[chan] = $(list[chan]).detach(); - } - - list = _.sortBy(list, function (channel) { - return parseInt(channel.children('.num_users').first().text(), 10); - }).reverse(); - - for (chan in list) { - body.append(list[chan]); - } - - this.table.append(body); - - }}; + /*global ChannelList */ + kiwi.front.cache.list = new ChannelList(); + console.profile('list'); }, onChannelList: function (e, data) { - var chans; - data = data.chans; - //data = [data]; - for (chans in data) { - data[chans] = {data: data[chans], html: ''}; - } - kiwi.front.cache.list.update(data); + kiwi.front.cache.list.addChannel(data.chans); }, onChannelListEnd: function (e, data) { - kiwi.front.cache.list.finalise(); - kiwi.front.cache.list.tab.show(); + kiwi.front.cache.list.show(); + console.profileEnd(); }, onBanList: function (e, data) { @@ -447,7 +399,7 @@ kiwi.front.events = { case 'invite_only_channel': tab.addMsg(null, ' ', '=== ' + data.channel + ' is invite only.', 'status'); if (t_view !== 'server') { - tab.safe_to_close = true; + tab.safe_to_close = true; } break; case 'channel_is_full': diff --git a/js/front.js b/js/front.js index 47d410c..f23973f 100644 --- a/js/front.js +++ b/js/front.js @@ -507,7 +507,65 @@ kiwi.front = { +var ChannelList = function () { + /*globals Utilityview */ + var chanList, view, table, obj, renderTable, waiting; + chanList = []; + + view = new Utilityview('Channel List'); + view.div.css('overflow-y', 'scroll'); + + table = $('
Channel NameMembersTopic
' + data[chans].channel + '' + data[chans].num_users + '' + kiwi.front.formatIRCMsg(data[chans].topic) + '
'); + table = table.appendTo(view.div); + + waiting = false; + renderTable = function () { + var tbody; + tbody = table.children('tbody:first').detach(); + /*tbody.children().each(function (child) { + var i, chan; + child = $(child); + chan = child.children('td:first').text(); + for (i = 0; i < chanList.length; i++) { + if (chanList[i].channel === chan) { + chanList[i].html = child.detach(); + break; + } + } + });*/ + _.each(chanList, function (chan) { + chan.html = $(chan.html).appendTo(tbody); + }); + table = table.append(tbody); + waiting = false; + }; + obj = { + addChannel: function (channels) { + if (!_.isArray(channels)) { + channels = [channels]; + } + _.each(channels, function (chan) { + var html, channel; + html = $(''); + chan.html = html; + chanList.push(chan); + }); + chanList.sort(function (a, b) { + return b.num_users - a.num_users; + }); + if (!waiting) { + waiting = true; + _.defer(renderTable); + } + }, + show: function () { + view.show(); + }, + prototype: {constructor: this} + }; + return obj; +}; -- 2.25.1
Channel NameMembersTopic
' + chan.channel + '' + chan.num_users + '' + kiwi.front.formatIRCMsg(chan.topic) + '