From fb6910635261273ec956280bb5057cdf2dc7c7cd Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 16 Jun 2017 15:09:40 +0200 Subject: [PATCH] Fixes #887 Enclose embedded images in URLs --- CHANGES.md | 1 + spec/chatbox.js | 9 +++++++-- src/utils.js | 15 ++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cff9688eb..3a81c1676 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ - #754 Show unread messages next to roster contacts. [jcbrand] - #864 Remove all inline CSS to comply with strict Content-Security-Policy headers [mathiasertl] - #873 Inconsistent unread messages count updating [novokrest] +- #887 Make embedded images clickabe [jcbrand] - #890 Message carbons not sent out after reconnection [jcbrand] - #894 Room affiliation lost when connection jid and room presence jid are of different case [Rayzen] diff --git a/spec/chatbox.js b/spec/chatbox.js index 097bae69b..d956b9fa9 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -1247,7 +1247,9 @@ }, 500).then(function () { expect(view.sendMessage).toHaveBeenCalled(); var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content'); - expect(msg.html()).toEqual(''); + expect(msg.html()).toEqual( + ''); message += "?param1=val1¶m2=val2"; test_utils.sendMessage(view, message); return test_utils.waitUntil(function () { @@ -1256,7 +1258,10 @@ }).then(function () { expect(view.sendMessage).toHaveBeenCalled(); var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content'); - expect(msg.html()).toEqual(''); + expect(msg.html()).toEqual( + '') done(); }); })); diff --git a/src/utils.js b/src/utils.js index 9a8c061d4..6d8058bf6 100755 --- a/src/utils.js +++ b/src/utils.js @@ -94,14 +94,15 @@ return false; }; - $.fn.throttledHTML = _.throttle($.fn.html, 500); + var throttledHTML = _.throttle(function (el, html) { + el.innerHTML = html; + }, 500); $.fn.addHyperlinks = function () { if (this.length > 0) { this.each(function (i, obj) { var prot, escaped_url; - var $obj = $(obj); - var x = $obj.html(); + var x = obj.innerHTML; var list = x.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<]{2,200}\b/g ); if (list) { for (i=0; i'+ list[i] + '' ); } } - $obj.html(x); + obj.innerHTML = x; _.forEach(list, function (url) { isImage(unescapeHTML(url)).then(function (img) { - var prot = url.indexOf('http://') === 0 || url.indexOf('https://') === 0 ? '' : 'http://'; - var escaped_url = encodeURI(decodeURI(url)).replace(/[!'()]/g, escape).replace(/\*/g, "%2A"); - var new_url = ''+ url + ''; img.className = 'chat-image'; - x = x.replace(new_url, img.outerHTML); - $obj.throttledHTML(x); + throttledHTML(obj.querySelector('a'), img.outerHTML); }); }); });