Permalink
Browse files

add the show_avatar option

  • Loading branch information...
1 parent 6a61b89 commit a5548a2579dfa2a5435f04eac57dba193f711b55 @kerphi committed Mar 4, 2013
Showing with 21 additions and 10 deletions.
  1. +14 −6 client/pfc-core.js
  2. +4 −1 client/pfc.js
  3. +2 −2 client/themes/default/pfc-notimplemented.less
  4. +1 −1 examples/default.html
View
20 client/pfc-core.js
@@ -125,7 +125,7 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
user.op = ($.inArray(user.id, pfc.channels[pfc.cid].op) >= 0);
user.role = user.op ? 'admin' : 'user';
user.name = (user.name !== undefined) ? user.name : 'Guest ' + Math.round(Math.random() * 100);
- user.email = (user.email !== undefined) ? user.email : '';
+ user.email = (user.email !== undefined) ? user.email : user.name + '@phpfreechat.net';
user.active = (user.active !== undefined) ? user.active : true;
// user list DOM element
@@ -152,9 +152,10 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
if (user.op) {
html.find('div.status').addClass('st-op');
}
+ if (pfc.options.show_avatar) {
+ html.find('div.avatar').append('<img src="http://www.gravatar.com/avatar/' + pfc.md5(user.email) + '?d=wavatar&amp;s=20" alt="" />');
+ }
- //html.find('div.avatar').append('<img src="http://www.gravatar.com/avatar/' + pfc.md5(user.email) + '?d=wavatar&amp;s=20" alt="" />');
-
// get all userids from the list (could be cached)
var userids = [];
$(pfc.element).find('div.pfc-users li.user').each(function (i, dom_user) {
@@ -224,6 +225,12 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
msg.body = (msg.body !== undefined) ? msg.body : '';
msg.timestamp = (msg.timestamp !== undefined) ? msg.timestamp : Math.round(new Date().getTime() / 1000);
msg.date = new Date(msg.timestamp * 1000).toLocaleTimeString();
+
+ msg.avatar = (pfc.users[msg.sender] !== undefined) ?
+ (pfc.users[msg.sender].email ?
+ pfc.md5(pfc.users[msg.sender].email)
+ : pfc.md5(pfc.users[msg.sender].name + '@phpfreechat.net'))
+ : '';
// reformat body text
if (msg.type == 'join') {
@@ -237,12 +244,13 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
var html = null;
if (groupmsg_dom.attr('data-from') != msg.from) {
html = $('<div class="messages-group" data-stamp="" data-from="">'
-// + ' <div class="avatar"><img src="http://www.gravatar.com/avatar/00000000000000000000000000000001?d=wavatar&s=30" alt="" /></div>'
-// + ' <div class="avatar"><div style="width:30px; height: 30px; background-color: #DDD;"></div></div>'
+ + (pfc.options.show_avatar ?
+ ' <div class="avatar"><img src="http://www.gravatar.com/avatar/' + msg.avatar + '?d=wavatar&s=30" alt="" /></div>' :
+ '')
+ ' <div class="date"></div>'
+ ' <div class="name"></div>'
+ ' </div>');
-
+
// system messages (join, error ...)
if (/^system-/.test(msg.from)) {
html.addClass('from-' + msg.from);
View
5 client/pfc.js
@@ -50,7 +50,10 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
skip_intro: false,
// skip login step ? (if true, chat will not be usable)
- skip_auth: false
+ skip_auth: false,
+
+ // show user avatar or not
+ show_avatar: false
};
function Plugin(element, options) {
View
4 client/themes/default/pfc-notimplemented.less
@@ -2,8 +2,8 @@
// Not planned for pfc 2.0
//
-@userlist-avatar-w: 0px; // avatar not planned for 2.0
-@message-padding-left: 0px; // avatar not planned for 2.0
+/*@userlist-avatar-w: 0px; // avatar not planned for 2.0
+@message-padding-left: 0px; // avatar not planned for 2.0*/
/*@users-role-title-display: none; // role not planned for 2.0
@users-role-title-border-width: 0px; // role not planned for 2.0*/
View
2 examples/default.html
@@ -56,7 +56,7 @@ <h1 style="font-size:1.5em">phpFreeChat - default theme and default parameters</
<div class="pfc-hook"><a href="http://www.phpfreechat.net">Creating chat rooms everywhere - phpFreeChat</a></div>
<script type="text/javascript">
- $('.pfc-hook').phpfreechat();
+ $('.pfc-hook').phpfreechat({show_avatar: true});
</script>
</div>

0 comments on commit a5548a2

Please sign in to comment.