parent
24942d6d0a
commit
cb94fd1940
25
src/utils.js
25
src/utils.js
@ -46,11 +46,20 @@
|
|||||||
|
|
||||||
var isImage = function (url) {
|
var isImage = function (url) {
|
||||||
var deferred = new $.Deferred();
|
var deferred = new $.Deferred();
|
||||||
$("<img>", {
|
var img = new Image();
|
||||||
src: url,
|
var timer = window.setTimeout(function () {
|
||||||
error: deferred.reject,
|
deferred.reject();
|
||||||
load: deferred.resolve
|
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();
|
return deferred.promise();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,12 +95,12 @@
|
|||||||
}
|
}
|
||||||
$obj.html(x);
|
$obj.html(x);
|
||||||
_.forEach(list, function (url) {
|
_.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 prot = url.indexOf('http://') === 0 || url.indexOf('https://') === 0 ? '' : 'http://';
|
||||||
var escaped_url = encodeURI(decodeURI(url)).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
|
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>';
|
var new_url = '<a target="_blank" rel="noopener" href="' + prot + escaped_url + '">'+ url + '</a>';
|
||||||
ev.target.className = 'chat-image';
|
img.className = 'chat-image';
|
||||||
x = x.replace(new_url, ev.target.outerHTML);
|
x = x.replace(new_url, img.outerHTML);
|
||||||
$obj.throttledHTML(x);
|
$obj.throttledHTML(x);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user