Commit cb94fd19 authored by JC Brand's avatar JC Brand

Update isImage to not use jQuery

Updates #814
parent 24942d6d
...@@ -46,11 +46,20 @@ ...@@ -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 @@ ...@@ -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);
}); });
}); });
......
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