Added "loading X..." text to thumbnails

This commit is contained in:
Marcin Kurczewski 2014-10-19 12:01:22 +02:00
parent 56ac7adb1b
commit 317d9ff02b
3 changed files with 25 additions and 4 deletions

View file

@ -55,6 +55,7 @@
background: white; background: white;
} }
.post-small a:focus, .post-small a:focus,
.post-small a:hover { .post-small a:hover {
background: #64C2ED; background: #64C2ED;
@ -63,8 +64,8 @@
outline: 0; outline: 0;
} }
.post-small a:focus img, .post-small a:focus img:not(.loading),
.post-small a:hover img { .post-small a:hover img:not(.loading) {
opacity: .8 !important; opacity: .8 !important;
} }

View file

@ -80,9 +80,9 @@ App.Presenters.UserListPresenter = function(
user: user, user: user,
formatRelativeTime: util.formatRelativeTime, formatRelativeTime: util.formatRelativeTime,
}) + '</li>'); }) + '</li>');
util.loadImagesNicely($item.find('img'));
$target.append($item); $target.append($item);
}); });
_.map(_.map($target.find('img'), jQuery), util.loadImagesNicely);
} }
return { return {

View file

@ -26,9 +26,29 @@ App.Util = function(_, jQuery, marked, promise) {
function loadImagesNicely($img) { function loadImagesNicely($img) {
if (!$img.get(0).complete) { if (!$img.get(0).complete) {
$img.css('opacity', '0'); $img.addClass('loading');
$img.css({opacity: 0});
var $div = jQuery('<div>Loading ' + $img.attr('alt') + '&hellip;</div>');
var width = $img.width();
var height = $img.height();
if (width > 50 && height > 50) {
$div.css({
position: 'absolute',
width: width + 'px',
height: height + 'px',
color: 'rgba(0, 0, 0, 0.15)',
zIndex: -1,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center'});
$div.insertBefore($img);
$div.offset($img.offset());
}
$img.bind('load', function() { $img.bind('load', function() {
$img.animate({opacity: 1}, 'fast'); $img.animate({opacity: 1}, 'fast');
$img.removeClass('loading');
$div.fadeOut($div.remove);
}); });
} }
} }