\r
initialize: function (options) {\r
var text = {\r
- channel_name: '<a class="channel_name_title">' + _kiwi.global.i18n.translate('client_applets_chanlist_channelname').fetch() + '</a>',\r
- users: '<a class="users_title">' + _kiwi.global.i18n.translate('client_applets_chanlist_users').fetch() + '</a>',\r
+ channel_name: _kiwi.global.i18n.translate('client_applets_chanlist_channelname').fetch(),\r
+ users: _kiwi.global.i18n.translate('client_applets_chanlist_users').fetch(),\r
topic: _kiwi.global.i18n.translate('client_applets_chanlist_topic').fetch()\r
};\r
this.$el = $(_.template($('#tmpl_channel_list').html().trim(), text));\r
tbody = table.children('tbody:first').detach(),\r
that = this,\r
channels_length = this.channels.length,\r
- icon_asc = '<span class="icon-sort-up"> </span>',\r
- icon_desc = '<span class="icon-sort-down"> </span>',\r
i;\r
\r
- if (override_channels != undefined) {\r
+ if (override_channels !== undefined) {\r
that.channels = override_channels;\r
tbody.remove();\r
this.sorting_channels = true;\r
that.channels = this.sortChannels(this.channels, this.order);\r
}\r
\r
- // Clean the sorting icon and add the new one\r
- $('.applet_chanlist .users_title').find('span').remove();\r
- $('.applet_chanlist .channel_name_title').find('span').remove();\r
+ // Create the sort icon container and clean previous any previous ones\r
+ if($('.applet_chanlist .users_title').find('span.chanlist_sort_users').length == 0) {\r
+ this.$('.users_title').append('<span class="chanlist_sort_users"> </span>');\r
+ } else {\r
+ this.$('.users_title span.chanlist_sort_users').removeClass('icon-sort-up');\r
+ this.$('.users_title span.chanlist_sort_users').removeClass('icon-sort-down');\r
+ }\r
+ if ($('.applet_chanlist .channel_name_title').find('span.chanlist_sort_names').length == 0) {\r
+ this.$('.channel_name_title').append('<span class="chanlist_sort_names"> </span>');\r
+ } else {\r
+ this.$('.channel_name_title span.chanlist_sort_names').removeClass('icon-sort-up');\r
+ this.$('.channel_name_title span.chanlist_sort_names').removeClass('icon-sort-down');\r
+ }\r
+\r
+ // Push the new sort icon\r
switch (this.order) {\r
case 'user_desc':\r
default:\r
- this.$('.users_title').append(icon_desc);\r
+ this.$('.users_title span.chanlist_sort_users').addClass('icon-sort-down');\r
break;\r
case 'user_asc':\r
- this.$('.users_title').append(icon_asc);\r
+ this.$('.users_title span.chanlist_sort_users').addClass('icon-sort-up');\r
break;\r
case 'name_asc':\r
- this.$('.channel_name_title').append(icon_asc);\r
+ this.$('.channel_name_title span.chanlist_sort_names').addClass('icon-sort-up');\r
break;\r
case 'name_desc':\r
- this.$('.channel_name_title').append(icon_desc);\r
+ this.$('.channel_name_title span.chanlist_sort_names').addClass('icon-sort-down');\r
break;\r
}\r
\r
\r
sortChannelsByNameClick: function (event) {\r
// Revert the sorting to switch between orders\r
- if (this.order == 'name_asc') {\r
- this.order = 'name_desc';\r
- } else {\r
- this.order = 'name_asc';\r
- }\r
+ this.order = (this.order == 'name_asc') ? 'name_desc' : 'name_asc';\r
\r
this.sortChannelsClick(this.order);\r
},\r
\r
sortChannelsByUsersClick: function (event) {\r
// Revert the sorting to switch between orders\r
- if (this.order == 'user_desc' || this.order == '') {\r
- this.order = 'user_asc';\r
- } else {\r
- this.order = 'user_desc';\r
- }\r
+ this.order = (this.order == 'user_desc' || this.order == '') ? 'user_asc' : 'user_desc';\r
\r
this.sortChannelsClick(this.order);\r
},\r
switch (order) {\r
case 'user_asc':\r
return a.num_users - b.num_users;\r
- break;\r
case 'user_desc':\r
return b.num_users - a.num_users;\r
- break; \r
case 'name_asc':\r
if (a.channel.toLowerCase() > b.channel.toLowerCase()) return 1;\r
if (a.channel.toLowerCase() < b.channel.toLowerCase()) return -1;\r
- break;\r
case 'name_desc':\r
if (a.channel.toLowerCase() < b.channel.toLowerCase()) return 1;\r
if (a.channel.toLowerCase() > b.channel.toLowerCase()) return -1;\r
- break;\r
default:\r
return b.num_users - a.num_users;\r
- break;\r
}\r
return 0;\r
});\r