Commit cb94fd19 authored by JC Brand's avatar JC Brand

Update isImage to not use jQuery

Updates #814
parent 24942d6d
......@@ -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);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment