diff --git a/src/converse-chatview.js b/src/converse-chatview.js index 0f01e98fc..32d33ea69 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -427,10 +427,11 @@ 'extra_classes': this.getExtraMessageClasses(attrs) }) )); - text = utils.addEmoji(_converse, emojione, text); const msg_content = $msg[0].querySelector('.chat-msg-content'); - msg_content.innerHTML = xss.filterXSS(text, {'whiteList': {}}); - utils.addHyperlinks(msg_content); + msg_content.innerHTML = utils.addEmoji( + _converse, emojione, utils.addHyperlinks(xss.filterXSS(text, {'whiteList': {}})) + ); + utils.renderImageURLs(msg_content); return $msg; }, diff --git a/src/utils.js b/src/utils.js index 81fcba41f..169987157 100755 --- a/src/utils.js +++ b/src/utils.js @@ -97,10 +97,6 @@ return false; }; - var throttledHTML = _.throttle(function (el, html) { - el.innerHTML = html; - }, 500); - function calculateSlideStep (height) { if (height > 100) { return 10; @@ -157,21 +153,24 @@ } }; - utils.addHyperlinks = function (obj) { - var x = obj.innerHTML; - var list = x.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<]{2,200}\b/g ) || []; + utils.addHyperlinks = function (text) { + var list = text.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<>]{2,200}\b/g ) || []; _.each(list, (match) => { const prot = match.indexOf('http://') === 0 || match.indexOf('https://') === 0 ? '' : 'http://'; const url = prot + encodeURI(decodeURI(match)).replace(/[!'()]/g, escape).replace(/\*/g, "%2A"); - x = x.replace(match, ''+ match + '' ); + text = text.replace(match, ''+ match + '' ); }); - obj.innerHTML = x; + return text; + }; + + utils.renderImageURLs = function (obj) { + var list = obj.textContent.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<>]{2,200}\b/g ) || []; _.forEach(list, function (url) { isImage(unescapeHTML(url)).then(function (img) { img.className = 'chat-image'; var a = obj.querySelector('a'); if (!_.isNull(a)) { - throttledHTML(a, img.outerHTML); + a.innerHTML = img.outerHTML; } }); });