Commit 00b73c493ced56732c7adebd649f7c43722abadb
Committed by
Rodrigo Souto
1 parent
7007c8d4
Exists in
master
and in
27 other branches
Improve html templates for chat components
Showing
3 changed files
with
72 additions
and
36 deletions
Show diff stats
app/views/shared/logged_in/xmpp_chat.html.erb
@@ -24,16 +24,22 @@ | @@ -24,16 +24,22 @@ | ||
24 | </div> | 24 | </div> |
25 | 25 | ||
26 | <div id="friends"> | 26 | <div id="friends"> |
27 | - <div id='title-bar'><h1 class='title'><%= _("Online") %> (<span id='friends-online'>0</span>)</h1></div> | ||
28 | - <ul class='buddy-list online'></ul> | 27 | + <div class="status-group"> |
28 | + <div class='title-bar'><a href="#"><h1 class='title'><%= _("Online") %> (<span id='friends-online'>0</span>)</h1></a></div> | ||
29 | + <ul class='buddy-list online'></ul> | ||
30 | + </div> | ||
29 | 31 | ||
30 | - <div id='title-bar'><h1 class='title'><%= _("Offline") %></h1></div> | ||
31 | - <ul class='buddy-list offline'></ul> | 32 | + <div class="status-group"> |
33 | + <div class='title-bar'><a href="#"><h1 class='title'><%= _("Offline") %> (<span id='friends-offline'>0</span>)</h1></a></div> | ||
34 | + <ul class='buddy-list offline'></ul> | ||
35 | + </div> | ||
32 | </div> | 36 | </div> |
33 | 37 | ||
34 | <div id="rooms"> | 38 | <div id="rooms"> |
35 | - <div id='title-bar'><h1 class='title'><%= _("Groups") %></h1></div> | ||
36 | - <ul class="buddy-list room-list"></ul> | 39 | + <div class="status-group"> |
40 | + <div class='title-bar'><a href="#"><h1 class='title'><%= _("Groups") %> (<span id='groups-online'>0</span>)</h1></a></div> | ||
41 | + <ul class="buddy-list room-list"></ul> | ||
42 | + </div> | ||
37 | </div> | 43 | </div> |
38 | </div> | 44 | </div> |
39 | 45 | ||
@@ -42,18 +48,21 @@ | @@ -42,18 +48,21 @@ | ||
42 | </div> | 48 | </div> |
43 | 49 | ||
44 | <div id="chat-templates"> | 50 | <div id="chat-templates"> |
45 | - <div class='conversation' style="display: none;"> | ||
46 | - <div class="header"> | ||
47 | - <span class="chat-target"> | ||
48 | - <img class="avatar"> | ||
49 | - <span class="other-name"></span> | ||
50 | - </span> | ||
51 | - <a href="#" class="back"><%= _('Back') %></a> | ||
52 | - </div> | ||
53 | - <div class='history'></div> | ||
54 | - <div class='input-div'> | ||
55 | - <div class='icon-chat'></div> | ||
56 | - <textarea class='input'></textarea> | 51 | + |
52 | + <div class="conversation-template"> | ||
53 | + <div class='conversation' style="display: none;"> | ||
54 | + <div class="header"> | ||
55 | + <span class="chat-target"> | ||
56 | + <img class="avatar"> | ||
57 | + <span class="other-name"></span> | ||
58 | + </span> | ||
59 | + <a href="#" class="back"><%= _('Back') %></a> | ||
60 | + </div> | ||
61 | + <div class='history'></div> | ||
62 | + <div class='input-div'> | ||
63 | + <div class='icon-chat'></div> | ||
64 | + <textarea class='input'></textarea> | ||
65 | + </div> | ||
57 | </div> | 66 | </div> |
58 | </div> | 67 | </div> |
59 | 68 | ||
@@ -67,6 +76,20 @@ | @@ -67,6 +76,20 @@ | ||
67 | </li> | 76 | </li> |
68 | </div> | 77 | </div> |
69 | 78 | ||
79 | + <div class="occupant-list-template"> | ||
80 | + <div class="occupant-list"> | ||
81 | + <ul class='occupant-list'></ul> | ||
82 | + </div> | ||
83 | + </div> | ||
84 | + | ||
85 | + <div class="occupant-item"> | ||
86 | + <li class='%{presence_status}'> | ||
87 | + <a data-id='%{jid_id}' class='icon-menu-%{presence_status}-11' href='#'> | ||
88 | + %{name} | ||
89 | + </a> | ||
90 | + </li> | ||
91 | + </div> | ||
92 | + | ||
70 | <div class="message"> | 93 | <div class="message"> |
71 | <div data-who="%{who}" class="message %{who}"> | 94 | <div data-who="%{who}" class="message %{who}"> |
72 | <div class="author"> | 95 | <div class="author"> |
@@ -79,5 +102,10 @@ | @@ -79,5 +102,10 @@ | ||
79 | </div> | 102 | </div> |
80 | </div> | 103 | </div> |
81 | </div> | 104 | </div> |
105 | + | ||
106 | + <div class="error-message"> | ||
107 | + <span class='error'>%{text}</span> | ||
108 | + </div> | ||
109 | + | ||
82 | </div> | 110 | </div> |
83 | </div> | 111 | </div> |
public/javascripts/chat.js
@@ -28,11 +28,8 @@ jQuery(function($) { | @@ -28,11 +28,8 @@ jQuery(function($) { | ||
28 | jids: {}, | 28 | jids: {}, |
29 | rooms: {}, | 29 | rooms: {}, |
30 | 30 | ||
31 | - templates: { | ||
32 | - occupant_item: "<li class='%{presence_status}'><a data-id='%{jid_id}' class='icon-menu-%{presence_status}-11' href='#'>%{name}</a></li>", | ||
33 | - room_item: "<li class='room'><a id='%{jid_id}' class='icon-chat' href='#'>%{name}</a></li>", | ||
34 | - error: "<span class='error'>%{text}</span>", | ||
35 | - occupant_list: "<div class='occupant-list'><ul class='occupant-list'></ul></div>" | 31 | + template: function(selector) { |
32 | + return $('#chat #chat-templates '+selector).clone().html(); | ||
36 | }, | 33 | }, |
37 | 34 | ||
38 | jid_to_id: function (jid) { | 35 | jid_to_id: function (jid) { |
@@ -72,7 +69,7 @@ jQuery(function($) { | @@ -72,7 +69,7 @@ jQuery(function($) { | ||
72 | var item = $('#' + jid_id); | 69 | var item = $('#' + jid_id); |
73 | presence = presence || ($(item).length > 0 ? $(item).parent('li').attr('class') : 'offline'); | 70 | presence = presence || ($(item).length > 0 ? $(item).parent('li').attr('class') : 'offline'); |
74 | log('adding or updating contact ' + jid + ' as ' + presence); | 71 | log('adding or updating contact ' + jid + ' as ' + presence); |
75 | - Jabber.insert_or_update_user(list, item, jid, Jabber.name_of(jid_id), presence, $('#chat #chat-templates .buddy-item').clone().html(), 'groupchat'); | 72 | + Jabber.insert_or_update_user(list, item, jid, Jabber.name_of(jid_id), presence, Jabber.template('.buddy-item'), 'groupchat'); |
76 | $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") | 73 | $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") |
77 | .removeClass() | 74 | .removeClass() |
78 | .addClass('icon-menu-' + presence + '-11'); | 75 | .addClass('icon-menu-' + presence + '-11'); |
@@ -84,7 +81,7 @@ jQuery(function($) { | @@ -84,7 +81,7 @@ jQuery(function($) { | ||
84 | var list = $('#buddy-list #friends .buddy-list' + (presence=='offline' ? '.offline' : '.online')); | 81 | var list = $('#buddy-list #friends .buddy-list' + (presence=='offline' ? '.offline' : '.online')); |
85 | 82 | ||
86 | log('adding or updating contact ' + jid + ' as ' + presence); | 83 | log('adding or updating contact ' + jid + ' as ' + presence); |
87 | - Jabber.insert_or_update_user(list, item, jid, name, presence, $('#chat #chat-templates .buddy-item').clone().html(), 'chat'); | 84 | + Jabber.insert_or_update_user(list, item, jid, name, presence, Jabber.template('.buddy-item'), 'chat'); |
88 | $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") | 85 | $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") |
89 | .removeClass() | 86 | .removeClass() |
90 | .addClass('icon-menu-' + presence + '-11'); | 87 | .addClass('icon-menu-' + presence + '-11'); |
@@ -94,7 +91,7 @@ jQuery(function($) { | @@ -94,7 +91,7 @@ jQuery(function($) { | ||
94 | var jid_id = Jabber.jid_to_id(jid); | 91 | var jid_id = Jabber.jid_to_id(jid); |
95 | var list = $('#' + Jabber.conversation_prefix + Jabber.jid_to_id(room_jid) + ' .occupant-list ul'); | 92 | var list = $('#' + Jabber.conversation_prefix + Jabber.jid_to_id(room_jid) + ' .occupant-list ul'); |
96 | var item = $(list).find('a[data-id='+ jid_id +']'); | 93 | var item = $(list).find('a[data-id='+ jid_id +']'); |
97 | - Jabber.insert_or_update_user(list, item, jid, name, presence, Jabber.templates.occupant_item, 'chat'); | 94 | + Jabber.insert_or_update_user(list, item, jid, name, presence, Jabber.template('.occupant-item'), 'chat'); |
98 | if (Jabber.rooms[Jabber.jid_to_id(room_jid)] === undefined) { | 95 | if (Jabber.rooms[Jabber.jid_to_id(room_jid)] === undefined) { |
99 | Jabber.rooms[Jabber.jid_to_id(room_jid)] = {}; | 96 | Jabber.rooms[Jabber.jid_to_id(room_jid)] = {}; |
100 | } | 97 | } |
@@ -130,7 +127,7 @@ jQuery(function($) { | @@ -130,7 +127,7 @@ jQuery(function($) { | ||
130 | if (time==undefined) { | 127 | if (time==undefined) { |
131 | time = new Date().toISOString(); | 128 | time = new Date().toISOString(); |
132 | } | 129 | } |
133 | - var message_html = $('#chat #chat-templates .message').clone().html() | 130 | + var message_html = Jabber.template('.message') |
134 | .replace('%{message}', body) | 131 | .replace('%{message}', body) |
135 | .replace(/%{who}/g, who) | 132 | .replace(/%{who}/g, who) |
136 | .replace('%{time}', time) | 133 | .replace('%{time}', time) |
@@ -170,8 +167,8 @@ jQuery(function($) { | @@ -170,8 +167,8 @@ jQuery(function($) { | ||
170 | Jabber.connection.send( | 167 | Jabber.connection.send( |
171 | $pres({to: room_jid + '/' + $own_name}).c('x', {xmlns: Strophe.NS.MUC}).c('history', {maxchars: 0}) | 168 | $pres({to: room_jid + '/' + $own_name}).c('x', {xmlns: Strophe.NS.MUC}).c('history', {maxchars: 0}) |
172 | ); | 169 | ); |
173 | - //FIXME list group | ||
174 | Jabber.insert_or_update_group(room_jid, 'group'); | 170 | Jabber.insert_or_update_group(room_jid, 'group'); |
171 | + Jabber.update_chat_title(); | ||
175 | }, | 172 | }, |
176 | 173 | ||
177 | leave_room: function(room_jid) { | 174 | leave_room: function(room_jid) { |
@@ -180,8 +177,12 @@ jQuery(function($) { | @@ -180,8 +177,12 @@ jQuery(function($) { | ||
180 | }, | 177 | }, |
181 | 178 | ||
182 | update_chat_title: function () { | 179 | update_chat_title: function () { |
183 | - var friends_online = $('#buddy-list .buddy-list.online li').length; | 180 | + var friends_online = $('#buddy-list #friends .buddy-list.online li').length; |
184 | $('#friends-online').text(friends_online); | 181 | $('#friends-online').text(friends_online); |
182 | + var friends_offline = $('#buddy-list #friends .buddy-list.offline li').length; | ||
183 | + $('#friends-offline').text(friends_offline); | ||
184 | + var groups_online = $('#buddy-list #rooms .buddy-list li').length; | ||
185 | + $('#groups-online').text(groups_online); | ||
185 | }, | 186 | }, |
186 | 187 | ||
187 | on_connect: function (status) { | 188 | on_connect: function (status) { |
@@ -360,7 +361,7 @@ jQuery(function($) { | @@ -360,7 +361,7 @@ jQuery(function($) { | ||
360 | message = Jabber.parse(message) | 361 | message = Jabber.parse(message) |
361 | var jid = Strophe.getBareJidFromJid(message.from); | 362 | var jid = Strophe.getBareJidFromJid(message.from); |
362 | log('Receiving error message from ' + jid); | 363 | log('Receiving error message from ' + jid); |
363 | - var body = Jabber.templates.error.replace('%{text}', message.error); | 364 | + var body = Jabber.template('.error-message').replace('%{text}', message.error); |
364 | Jabber.show_message(jid, Jabber.name_of(Jabber.jid_to_id(jid)), body, 'other', Strophe.getNodeFromJid(jid)); | 365 | Jabber.show_message(jid, Jabber.name_of(Jabber.jid_to_id(jid)), body, 'other', Strophe.getNodeFromJid(jid)); |
365 | return true; | 366 | return true; |
366 | }, | 367 | }, |
@@ -559,7 +560,7 @@ jQuery(function($) { | @@ -559,7 +560,7 @@ jQuery(function($) { | ||
559 | 560 | ||
560 | // opening chat with selected online friend | 561 | // opening chat with selected online friend |
561 | var panel = $('<div id="'+conversation_id +'"></div>').appendTo($conversations); | 562 | var panel = $('<div id="'+conversation_id +'"></div>').appendTo($conversations); |
562 | - panel.append($('#chat #chat-templates .conversation').clone()); | 563 | + panel.append(Jabber.template('.conversation-template')); |
563 | panel.find('.chat-target .avatar').replaceWith(getAvatar(identifier)); | 564 | panel.find('.chat-target .avatar').replaceWith(getAvatar(identifier)); |
564 | panel.find('.chat-target .other-name').html(title); | 565 | panel.find('.chat-target .other-name').html(title); |
565 | $('#chat .history').perfectScrollbar(); | 566 | $('#chat .history').perfectScrollbar(); |
@@ -568,7 +569,7 @@ jQuery(function($) { | @@ -568,7 +569,7 @@ jQuery(function($) { | ||
568 | textarea.attr('name', panel.id); | 569 | textarea.attr('name', panel.id); |
569 | 570 | ||
570 | if (Jabber.is_a_room(jid_id)) { | 571 | if (Jabber.is_a_room(jid_id)) { |
571 | - panel.append(Jabber.templates.occupant_list); | 572 | + panel.append(Jabber.template('.occupant-list-template')); |
572 | panel.find('.history').addClass('room'); | 573 | panel.find('.history').addClass('room'); |
573 | } | 574 | } |
574 | textarea.attr('data-to', jid); | 575 | textarea.attr('data-to', jid); |
@@ -668,6 +669,10 @@ jQuery(function($) { | @@ -668,6 +669,10 @@ jQuery(function($) { | ||
668 | Jabber.show_status('offline'); | 669 | Jabber.show_status('offline'); |
669 | } | 670 | } |
670 | 671 | ||
672 | + $('.title-bar a').click(function() { | ||
673 | + $(this).parents('.status-group').find('.buddy-list').toggle('fast'); | ||
674 | + }); | ||
675 | + | ||
671 | //restore connection if user was connected | 676 | //restore connection if user was connected |
672 | if($presence=='' || $presence == 'chat') { | 677 | if($presence=='' || $presence == 'chat') { |
673 | $('#chat-connect').trigger('click'); | 678 | $('#chat-connect').trigger('click'); |
public/stylesheets/chat.css
@@ -46,8 +46,8 @@ | @@ -46,8 +46,8 @@ | ||
46 | width: 32px; | 46 | width: 32px; |
47 | max-height: 40px; | 47 | max-height: 40px; |
48 | } | 48 | } |
49 | -#buddy-list .buddy-list li.offline, .occupant-list li.offline { | ||
50 | -/* display: none;*/ | 49 | +#buddy-list .buddy-list.offline, .occupant-list.offline { |
50 | + display: none; | ||
51 | } | 51 | } |
52 | #chat #buddy-list .toolbar { | 52 | #chat #buddy-list .toolbar { |
53 | border: 0; | 53 | border: 0; |
@@ -195,14 +195,17 @@ | @@ -195,14 +195,17 @@ | ||
195 | margin-left: 0; | 195 | margin-left: 0; |
196 | } | 196 | } |
197 | 197 | ||
198 | -#chat #title-bar { | 198 | +#chat .title-bar { |
199 | height: 34px; | 199 | height: 34px; |
200 | background: #ccc url(/images/icons-app/chat-22x22.png) 3px 5px no-repeat; | 200 | background: #ccc url(/images/icons-app/chat-22x22.png) 3px 5px no-repeat; |
201 | width: 250px; | 201 | width: 250px; |
202 | background-color: #303030; | 202 | background-color: #303030; |
203 | border-bottom: 1px solid #383838; | 203 | border-bottom: 1px solid #383838; |
204 | } | 204 | } |
205 | -#title-bar .title { | 205 | +#chat .title-bar a { |
206 | + text-decoration: none; | ||
207 | +} | ||
208 | +.title-bar .title { | ||
206 | margin: 0; | 209 | margin: 0; |
207 | font-size: 12px; | 210 | font-size: 12px; |
208 | padding-left: 30px; | 211 | padding-left: 30px; |