From a5daeb017efdf63203d582a160f2ff58fc294f07 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sat, 19 Oct 2013 23:18:17 +0200 Subject: [PATCH] Emoticons now supported for single-user chat. --- CHANGES.rst | 2 +- converse.css | 5 ++++ converse.js | 70 ++++++++++++++++++++++++++++++++++++++-------------- mockup.html | 5 +++- 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7a0c01075..fabe32b01 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,7 @@ Changelog * Add a toolbar for single user chat [jcbrand] * Add support for OTR (off-the-record) encryption [jcbrand] -* Add smileys [jcbrand] +* Add support for smileys [jcbrand] * Simplified initial boilerplate markup [jcbrand] 0.6.6 (2013-10-16) diff --git a/converse.css b/converse.css index 988f5ddb0..58f617e98 100644 --- a/converse.css +++ b/converse.css @@ -21,6 +21,11 @@ color: rgb(79, 79, 79); } + +#chatpanel .emoticon { + font-size: 14px; +} + .hidden { display: none } diff --git a/converse.js b/converse.js index da574d170..eba1a0c24 100644 --- a/converse.js +++ b/converse.js @@ -70,6 +70,7 @@ this.prebind = false; this.show_controlbox_by_default = false; this.show_only_online_users = false; + this.show_emoticons = true; this.show_toolbar = true; this.testing = false; // Exposes sensitive data for testing. Never set to true in production systems! this.xhr_custom_status = false; @@ -93,6 +94,7 @@ 'prebind', 'rid', 'show_controlbox_by_default', + 'show_emoticons', 'show_only_online_users', 'show_toolbar', 'sid', @@ -679,24 +681,25 @@ ), toolbar_template: _.template( - '
  • ' + - '' + - '
  • ' + - + '{[ if (show_emoticons) { ]}' + + '
  • ' + + '' + + '
  • ' + + '{[ } ]}' + '{[ if (allow_otr) { ]}' + '
  • '+ '{{otr_translated_status}}'+ @@ -783,6 +786,34 @@ this.scrollDown(); }, + insertEmoticons: function (text) { + if (converse.show_emoticons) { + text = text.replace(/:\)/g, ''); + text = text.replace(/:\-\)/g, ''); + text = text.replace(/;\)/g, ''); + text = text.replace(/;\-\)/g, ''); + text = text.replace(/:D/g, ''); + text = text.replace(/:\-D/g, ''); + text = text.replace(/:P/g, ''); + text = text.replace(/:\-P/g, ''); + text = text.replace(/:p/g, ''); + text = text.replace(/:\-p/g, ''); + text = text.replace(/8\)/g, ''); + text = text.replace(/>:\)/g, ''); + text = text.replace(/:S/g, ''); + text = text.replace(/:\\/g, ''); + text = text.replace(/>:\(/g, ''); + text = text.replace(/:\(/g, ''); + text = text.replace(/:\-\(/g, ''); + text = text.replace(/:O/g, ''); + text = text.replace(/:\-O/g, ''); + text = text.replace(/\=\-O/g, ''); + text = text.replace(/\(\^.\^\)b/g, ''); + text = text.replace(/<3/g, ''); + } + return text; + }, + showMessage: function ($el, msg_dict) { var this_date = converse.parseISO8601(msg_dict.time), text = msg_dict.message, @@ -803,7 +834,7 @@ template({ 'sender': sender, 'time': this_date.toTimeString().substring(0,5), - 'message': text, + 'message': this.insertEmoticons(text), 'username': username, 'extra_classes': msg_dict.delayed && 'delayed' || '' })); @@ -1143,6 +1174,7 @@ data.otr_tooltip = __('Your buddy has closed their end of the private session, you should do the same'); } data.allow_otr = converse.allow_otr; + data.show_emoticons = converse.show_emoticons; data.otr_translated_status = OTR_TRANSLATED_MAPPING[data.otr_status]; data.otr_status_class = OTR_CLASS_MAPPING[data.otr_status]; this.$el.find('.chat-toolbar').html(this.toolbar_template(data)); diff --git a/mockup.html b/mockup.html index af426d48a..832e91636 100644 --- a/mockup.html +++ b/mockup.html @@ -208,7 +208,10 @@
    This is an error message
    09:35 me:  - Hello world + + Hello world + +
    19:25 Benedict-John: