parent
24942d6d0a
commit
cb94fd1940
25
src/utils.js
25
src/utils.js
@ -46,11 +46,20 @@
|
||||
|
||||
var isImage = function (url) {
|
||||
var deferred = new $.Deferred();
|
||||
$("<img>", {
|
||||
src: url,
|
||||
error: deferred.reject,
|
||||
load: deferred.resolve
|
||||
});
|
||||
var img = new Image();
|
||||
var timer = window.setTimeout(function () {
|
||||
deferred.reject();
|
||||
img = null;
|
||||
}, 3000);
|
||||
img.onerror = img.onabort = function () {
|
||||
clearTimeout(timer);
|
||||
deferred.reject();
|
||||
};
|
||||
img.onload = function () {
|
||||
clearTimeout(timer);
|
||||
deferred.resolve(img);
|
||||
};
|
||||
img.src = url;
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
@ -86,12 +95,12 @@
|
||||
}
|
||||
$obj.html(x);
|
||||
_.forEach(list, function (url) {
|
||||
isImage(url).then(function (ev) {
|
||||
isImage(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 = '<a target="_blank" rel="noopener" href="' + prot + escaped_url + '">'+ url + '</a>';
|
||||
ev.target.className = 'chat-image';
|
||||
x = x.replace(new_url, ev.target.outerHTML);
|
||||
img.className = 'chat-image';
|
||||
x = x.replace(new_url, img.outerHTML);
|
||||
$obj.throttledHTML(x);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user