Improved image and thumbnail loading

This commit is contained in:
Marcin Kurczewski 2014-10-05 11:05:34 +02:00
parent 784ff22050
commit b57fee0ad8
15 changed files with 28 additions and 17 deletions

6
TODO
View file

@ -2,9 +2,6 @@ This is transient file that lists functionalities to be implemented before
first major release. first major release.
everything related to posts: everything related to posts:
- post listing
- better thumbnail loading
- single post view - single post view
- editing - editing
- ability to loop video posts - ability to loop video posts
@ -22,9 +19,6 @@ everything related to posts:
- post notes should be visible in post edit history. - post notes should be visible in post edit history.
(move post snapshot factory methods to PostService) (move post snapshot factory methods to PostService)
everything related to users:
- better avatar loading
everything related to tags: everything related to tags:
- tag listing - tag listing
- tag autocompletion (difficult) - tag autocompletion (difficult)

View file

@ -32,6 +32,8 @@
} }
.post-small img { .post-small img {
display: block; display: block;
border: 0;
background: white;
} }
.post-small a:focus, .post-small a:focus,

View file

@ -83,6 +83,7 @@ App.Presenters.GlobalCommentListPresenter = function(
postTemplate: templates.post, postTemplate: templates.post,
}) + '</li>'); }) + '</li>');
util.loadImagesNicely($post.find('img'));
var presenter = App.DI.get('postCommentListPresenter'); var presenter = App.DI.get('postCommentListPresenter');
presenter.init({ presenter.init({

View file

@ -100,6 +100,7 @@ App.Presenters.PostCommentListPresenter = function(
canEditComment: auth.isLoggedIn(comment.user.name) ? privileges.editOwnComments : privileges.editAllComments, canEditComment: auth.isLoggedIn(comment.user.name) ? privileges.editOwnComments : privileges.editAllComments,
canDeleteComment: auth.isLoggedIn(comment.user.name) ? privileges.deleteOwnComments : privileges.deleteAllComments, canDeleteComment: auth.isLoggedIn(comment.user.name) ? privileges.deleteOwnComments : privileges.deleteAllComments,
}) + '</li>'); }) + '</li>');
util.loadImagesNicely($item.find('img'));
$targetList.append($item); $targetList.append($item);
$item.find('a.edit').click(function(e) { $item.find('a.edit').click(function(e) {
e.preventDefault(); e.preventDefault();

View file

@ -92,10 +92,12 @@ App.Presenters.PostListPresenter = function(
} }
_.each(posts, function(post) { _.each(posts, function(post) {
$target.append(jQuery('<li>' + templates.listItem({ var $post = jQuery('<li>' + templates.listItem({
searchArgs: searchArgs, searchArgs: searchArgs,
post: post, post: post,
}) + '</li>')); }) + '</li>')
util.loadImagesNicely($post.find('img'));
$target.append($post);
}); });
} }

View file

@ -77,10 +77,12 @@ App.Presenters.UserListPresenter = function(
} }
_.each(users, function(user) { _.each(users, function(user) {
$target.append(jQuery('<li>' + templates.listItem({ var $item = jQuery('<li>' + templates.listItem({
user: user, user: user,
formatRelativeTime: util.formatRelativeTime, formatRelativeTime: util.formatRelativeTime,
}) + '</li>')); }) + '</li>');
util.loadImagesNicely($item.find('img'));
$target.append($item);
}); });
} }

View file

@ -70,6 +70,7 @@ App.Presenters.UserPresenter = function(
canChangeBrowsingSettings: userBrowsingSettingsPresenter.getPrivileges().canChangeBrowsingSettings, canChangeBrowsingSettings: userBrowsingSettingsPresenter.getPrivileges().canChangeBrowsingSettings,
canChangeAccountSettings: _.any(userAccountSettingsPresenter.getPrivileges()), canChangeAccountSettings: _.any(userAccountSettingsPresenter.getPrivileges()),
canDeleteAccount: userAccountRemovalPresenter.getPrivileges().canDeleteAccount})); canDeleteAccount: userAccountRemovalPresenter.getPrivileges().canDeleteAccount}));
util.loadImagesNicely($el.find('img'));
userBrowsingSettingsPresenter.render(); userBrowsingSettingsPresenter.render();
userAccountSettingsPresenter.render(); userAccountSettingsPresenter.render();
userAccountRemovalPresenter.render(); userAccountRemovalPresenter.render();

View file

@ -24,6 +24,13 @@ App.Util = function(_, jQuery, promise) {
return exitConfirmationEnabled; return exitConfirmationEnabled;
} }
function loadImagesNicely($img) {
$img.css('opacity', '0');
$img.bind('load', function() {
$img.animate({opacity: 1}, 'fast');
});
}
function parseComplexRouteArgs(args) { function parseComplexRouteArgs(args) {
var result = {}; var result = {};
args = (args || '').split(/;/); args = (args || '').split(/;/);
@ -189,6 +196,7 @@ App.Util = function(_, jQuery, promise) {
disableExitConfirmation: disableExitConfirmation, disableExitConfirmation: disableExitConfirmation,
isExitConfirmationEnabled: isExitConfirmationEnabled, isExitConfirmationEnabled: isExitConfirmationEnabled,
transparentPixel: transparentPixel, transparentPixel: transparentPixel,
loadImagesNicely: loadImagesNicely,
}; };
}; };

View file

@ -4,7 +4,7 @@
<a href="#/user/<%= comment.user.name %>"> <a href="#/user/<%= comment.user.name %>">
<% } %> <% } %>
<img class="author-avatar" <img width="40" height="40" class="author-avatar"
src="/data/thumbnails/40x40/avatars/<%= comment.user.name || '!' %>" src="/data/thumbnails/40x40/avatars/<%= comment.user.name || '!' %>"
alt="<%= comment.user.name || 'Anonymous user' %>"/> alt="<%= comment.user.name || 'Anonymous user' %>"/>

View file

@ -13,7 +13,7 @@
<a href="#/user/<%= userName %>"> <a href="#/user/<%= userName %>">
<% } %> <% } %>
<img class="author-avatar" <img width="20" height="20" class="author-avatar"
src="/data/thumbnails/20x20/avatars/<%= userName || '!' %>" src="/data/thumbnails/20x20/avatars/<%= userName || '!' %>"
alt="<%= userName || 'Anonymous user' %>"/> alt="<%= userName || 'Anonymous user' %>"/>

View file

@ -35,7 +35,7 @@
<a href="#/user/<%= post.user.name %>"> <a href="#/user/<%= post.user.name %>">
<% } %> <% } %>
<img class="author-avatar" <img width="25" height="25" class="author-avatar"
src="/data/thumbnails/25x25/avatars/<%= post.user.name || '!' %>" src="/data/thumbnails/25x25/avatars/<%= post.user.name || '!' %>"
alt="<%= post.user.name || 'Anonymous user' %>"/> alt="<%= post.user.name || 'Anonymous user' %>"/>

View file

@ -7,7 +7,7 @@
<% } %> <% } %>
title="<%= _.map(post.tags, function(tag) { return '#' + tag.name; }).join(', ') %>"> title="<%= _.map(post.tags, function(tag) { return '#' + tag.name; }).join(', ') %>">
<img class="thumb" src="/data/thumbnails/160x160/posts/<%= post.name %>" alt="<%= post.idMarkdown %>"/> <img width="160" height="160" class="thumb" src="/data/thumbnails/160x160/posts/<%= post.name %>" alt="<%= post.idMarkdown %>"/>
<% if (post.favoriteCount || post.score || post.commentCount) { %> <% if (post.favoriteCount || post.score || post.commentCount) { %>
<div class="info"> <div class="info">

View file

@ -89,7 +89,7 @@
<a href="#/user/<%= post.user.name %>"> <a href="#/user/<%= post.user.name %>">
<% } %> <% } %>
<img class="author-avatar" <img width="40" height="40" class="author-avatar"
src="/data/thumbnails/40x40/avatars/<%= post.user.name || '!' %>" src="/data/thumbnails/40x40/avatars/<%= post.user.name || '!' %>"
alt="<%= post.user.name || 'Anonymous user' %>"/> alt="<%= post.user.name || 'Anonymous user' %>"/>

View file

@ -1,6 +1,6 @@
<div class="user"> <div class="user">
<a href="#/user/<%= user.name %>"> <a href="#/user/<%= user.name %>">
<img src="/data/thumbnails/80x80/avatars/<%= user.name %>" alt="<%= user.name %>"/> <img width="80" height="80" src="/data/thumbnails/80x80/avatars/<%= user.name %>" alt="<%= user.name %>"/>
</a> </a>
<div class="details"> <div class="details">
<h1> <h1>

View file

@ -3,7 +3,7 @@
<div class="top"> <div class="top">
<div class="side"> <div class="side">
<img src="/data/thumbnails/100x100/avatars/<%= user.name %>" alt="Avatar"/> <img width="100" height="100" src="/data/thumbnails/100x100/avatars/<%= user.name %>" alt="Avatar"/>
<br/> <br/>
<%= user.name %> <%= user.name %>
</div> </div>