diff options
author | Joe Robinson <joe@grabyo.com> | 2016-08-17 15:13:29 +0100 |
---|---|---|
committer | Joe Robinson <joe@grabyo.com> | 2016-08-17 15:13:29 +0100 |
commit | 90533882ae77f811f01cc842fce9cab68df877ba (patch) | |
tree | 36079eb6002e8240d426bddf8f74fde738cd4732 /util.js | |
parent | f3d0c81c7b004218665ab1123fb6c8915b190ce0 (diff) |
Fixed receiving messages
Diffstat (limited to 'util.js')
-rw-r--r-- | util.js | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ + +module.exports.imagify = function(url, channel) { + console.log(url); + $.ajax({ + type: 'HEAD', + url: url, + complete: function(xhr) { + var type = xhr.getResponseHeader('Content-Type') + var size = xhr.getResponseHeader('Content-Length'); + console.log(type); + console.log(size); + if (size < 10000000) { + $("[data-img='"+url+"']").append("("+humanize(size)+")"); + $("[data-img='"+url+"']").append("<p class='chat-line'><img src="+url+" onload=scrollToTop('"+channel+"')></p>"); + $("[data-img='"+url+"']").removeClass("loading"); + + } + + } + }); + + return "<div data-img='"+url+"' class='ui image loading'></div>"; + +} + +humanize = function(size) { + var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']; + var ord = Math.floor(Math.log(size) / Math.log(1000)); + var s = Math.round((size / Math.pow(1000, ord)) * 100) / 100; + return s + ' ' + units[ord]; +} |