From df0aee0935acf9a94f15a3f118cd0d439ba70ef5 Mon Sep 17 00:00:00 2001 From: Cory Chaplin Date: Mon, 3 Mar 2014 11:19:44 +0100 Subject: [PATCH] Cleanup to take comments into account --- client/src/applets/chanlist.js | 51 ++++++++++++++++------------------ client/src/index.html.tmpl | 4 +-- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/client/src/applets/chanlist.js b/client/src/applets/chanlist.js index 8fb67bf..2cc676a 100644 --- a/client/src/applets/chanlist.js +++ b/client/src/applets/chanlist.js @@ -11,8 +11,8 @@ initialize: function (options) { var text = { - channel_name: '' + _kiwi.global.i18n.translate('client_applets_chanlist_channelname').fetch() + '', - users: '' + _kiwi.global.i18n.translate('client_applets_chanlist_users').fetch() + '', + channel_name: _kiwi.global.i18n.translate('client_applets_chanlist_channelname').fetch(), + users: _kiwi.global.i18n.translate('client_applets_chanlist_users').fetch(), topic: _kiwi.global.i18n.translate('client_applets_chanlist_topic').fetch() }; this.$el = $(_.template($('#tmpl_channel_list').html().trim(), text)); @@ -32,11 +32,9 @@ tbody = table.children('tbody:first').detach(), that = this, channels_length = this.channels.length, - icon_asc = '  ', - icon_desc = '  ', i; - if (override_channels != undefined) { + if (override_channels !== undefined) { that.channels = override_channels; tbody.remove(); this.sorting_channels = true; @@ -44,22 +42,34 @@ that.channels = this.sortChannels(this.channels, this.order); } - // Clean the sorting icon and add the new one - $('.applet_chanlist .users_title').find('span').remove(); - $('.applet_chanlist .channel_name_title').find('span').remove(); + // Create the sort icon container and clean previous any previous ones + if($('.applet_chanlist .users_title').find('span.chanlist_sort_users').length == 0) { + this.$('.users_title').append('  '); + } else { + this.$('.users_title span.chanlist_sort_users').removeClass('icon-sort-up'); + this.$('.users_title span.chanlist_sort_users').removeClass('icon-sort-down'); + } + if ($('.applet_chanlist .channel_name_title').find('span.chanlist_sort_names').length == 0) { + this.$('.channel_name_title').append('  '); + } else { + this.$('.channel_name_title span.chanlist_sort_names').removeClass('icon-sort-up'); + this.$('.channel_name_title span.chanlist_sort_names').removeClass('icon-sort-down'); + } + + // Push the new sort icon switch (this.order) { case 'user_desc': default: - this.$('.users_title').append(icon_desc); + this.$('.users_title span.chanlist_sort_users').addClass('icon-sort-down'); break; case 'user_asc': - this.$('.users_title').append(icon_asc); + this.$('.users_title span.chanlist_sort_users').addClass('icon-sort-up'); break; case 'name_asc': - this.$('.channel_name_title').append(icon_asc); + this.$('.channel_name_title span.chanlist_sort_names').addClass('icon-sort-up'); break; case 'name_desc': - this.$('.channel_name_title').append(icon_desc); + this.$('.channel_name_title span.chanlist_sort_names').addClass('icon-sort-down'); break; } @@ -87,22 +97,14 @@ sortChannelsByNameClick: function (event) { // Revert the sorting to switch between orders - if (this.order == 'name_asc') { - this.order = 'name_desc'; - } else { - this.order = 'name_asc'; - } + this.order = (this.order == 'name_asc') ? 'name_desc' : 'name_asc'; this.sortChannelsClick(this.order); }, sortChannelsByUsersClick: function (event) { // Revert the sorting to switch between orders - if (this.order == 'user_desc' || this.order == '') { - this.order = 'user_asc'; - } else { - this.order = 'user_desc'; - } + this.order = (this.order == 'user_desc' || this.order == '') ? 'user_asc' : 'user_desc'; this.sortChannelsClick(this.order); }, @@ -132,21 +134,16 @@ switch (order) { case 'user_asc': return a.num_users - b.num_users; - break; case 'user_desc': return b.num_users - a.num_users; - break; case 'name_asc': if (a.channel.toLowerCase() > b.channel.toLowerCase()) return 1; if (a.channel.toLowerCase() < b.channel.toLowerCase()) return -1; - break; case 'name_desc': if (a.channel.toLowerCase() < b.channel.toLowerCase()) return 1; if (a.channel.toLowerCase() > b.channel.toLowerCase()) return -1; - break; default: return b.num_users - a.num_users; - break; } return 0; }); diff --git a/client/src/index.html.tmpl b/client/src/index.html.tmpl index bd9af3c..c5fd5c5 100644 --- a/client/src/index.html.tmpl +++ b/client/src/index.html.tmpl @@ -342,8 +342,8 @@ - - + + -- 2.25.1
<%= channel_name %><%= users %><%= channel_name %><%= users %> <%= topic %>