|
@@ -49,21 +49,27 @@
|
|
|
$.fn.addHyperlinks = function () {
|
|
|
if (this.length > 0) {
|
|
|
this.each(function (i, obj) {
|
|
|
+ var prot, escaped_url;
|
|
|
var $obj = $(obj);
|
|
|
var x = $obj.html();
|
|
|
- _.each(x.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<]{2,200}\b/g), function (url) {
|
|
|
- isImage(url)
|
|
|
- .then(function () {
|
|
|
- event.target.className = 'chat-image';
|
|
|
- x = x.replace(url, event.target.outerHTML);
|
|
|
- $obj.throttledHTML(x);
|
|
|
- })
|
|
|
- .fail(function () {
|
|
|
- var prot = url.indexOf('http://') === 0 || url.indexOf('https://') === 0 ? '' : 'http://';
|
|
|
- var escaped_url = encodeURI(decodeURI(url)).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
|
|
|
- x = x.replace(url, '<a target="_blank" rel="noopener" href="' + prot + escaped_url + '">'+ url + '</a>' );
|
|
|
- $obj.throttledHTML(x);
|
|
|
- });
|
|
|
+ var list = x.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<]{2,200}\b/g );
|
|
|
+ if (list) {
|
|
|
+ for (i=0; i<list.length; i++) {
|
|
|
+ prot = list[i].indexOf('http://') === 0 || list[i].indexOf('https://') === 0 ? '' : 'http://';
|
|
|
+ escaped_url = encodeURI(decodeURI(list[i])).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
|
|
|
+ x = x.replace(list[i], '<a target="_blank" rel="noopener" href="' + prot + escaped_url + '">'+ list[i] + '</a>' );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $obj.html(x);
|
|
|
+ _.each(list, function (url) {
|
|
|
+ isImage(url).then(function () {
|
|
|
+ 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 = '<a target="_blank" rel="noopener" href="' + prot + escaped_url + '">'+ url + '</a>';
|
|
|
+ event.target.className = 'chat-image';
|
|
|
+ x = x.replace(new_url, event.target.outerHTML);
|
|
|
+ $obj.throttledHTML(x);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
}
|