Fixed thumbnails for non-images in post upload
This commit is contained in:
parent
a3fbe80281
commit
37da38e929
3 changed files with 18 additions and 9 deletions
3
TODO
3
TODO
|
@ -2,9 +2,6 @@ This is transient file that lists functionalities to be implemented before
|
|||
first major release.
|
||||
|
||||
everything related to posts:
|
||||
- uploads
|
||||
- fix thumbnails for files that are neither youtube or images
|
||||
|
||||
- post list
|
||||
- add style for hovered and focused element
|
||||
- fav count
|
||||
|
|
|
@ -124,16 +124,17 @@ App.Presenters.PostUploadPresenter = function(
|
|||
|
||||
function addPostFromUrl(url) {
|
||||
var post = _.extend({}, getDefaultPost(), {url: url, source: url, fileName: url});
|
||||
postAdded(post);
|
||||
|
||||
var matches = url.match(/watch.*?=([a-zA-Z0-9_-]+)/);
|
||||
if (matches) {
|
||||
var youtubeThumbnailUrl = 'http://img.youtube.com/vi/' + matches[1] + '/mqdefault.jpg';
|
||||
post.thumbnail = youtubeThumbnailUrl;
|
||||
} else {
|
||||
postThumbnailLoaded(post);
|
||||
} else if (url.match(/image|img|jpg|png|gif/i)) {
|
||||
post.thumbnail = url;
|
||||
postThumbnailLoaded(post);
|
||||
}
|
||||
postAdded(post);
|
||||
postThumbnailLoaded(post);
|
||||
}
|
||||
|
||||
function postAdded(post) {
|
||||
|
@ -184,13 +185,19 @@ App.Presenters.PostUploadPresenter = function(
|
|||
}
|
||||
|
||||
function updatePostThumbnailInForm(post) {
|
||||
$el.find('.form-slider .thumbnail img')[0].setAttribute('src', post.thumbnail);
|
||||
if (post.thumbnail === null) {
|
||||
$el.find('.form-slider .thumbnail img').hide();
|
||||
} else {
|
||||
$el.find('.form-slider .thumbnail img').show()[0].setAttribute('src', post.thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePostThumbnailInTable(post) {
|
||||
var $row = post.$tableRow;
|
||||
if (post.thumbnail === null) {
|
||||
$row.find('img')[0].setAttribute('src', util.transparentPixel());
|
||||
//huge speedup thanks to this condition
|
||||
if ($row.find('img').attr('src') !== post.thumbnail && post.thumbnail !== null) {
|
||||
} else if ($row.find('img').attr('src') !== post.thumbnail) {
|
||||
$row.find('img')[0].setAttribute('src', post.thumbnail);
|
||||
}
|
||||
}
|
||||
|
@ -409,7 +416,7 @@ App.Presenters.PostUploadPresenter = function(
|
|||
|
||||
function postTableRowImageHovered(e) {
|
||||
var $img = jQuery(this);
|
||||
if ($img.attr('src')) {
|
||||
if ($img.parents('tr').data('post').thumbnail) {
|
||||
var $lightbox = jQuery('#lightbox');
|
||||
$lightbox.find('img').attr('src', $img.attr('src'));
|
||||
$lightbox
|
||||
|
|
|
@ -5,6 +5,10 @@ App.Util = function(_, jQuery, promise) {
|
|||
var templateCache = {};
|
||||
var exitConfirmationEnabled = false;
|
||||
|
||||
function transparentPixel() {
|
||||
return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
||||
}
|
||||
|
||||
function enableExitConfirmation() {
|
||||
exitConfirmationEnabled = true;
|
||||
jQuery(window).bind('beforeunload', function(e) {
|
||||
|
@ -156,6 +160,7 @@ App.Util = function(_, jQuery, promise) {
|
|||
enableExitConfirmation: enableExitConfirmation,
|
||||
disableExitConfirmation: disableExitConfirmation,
|
||||
isExitConfirmationEnabled: isExitConfirmationEnabled,
|
||||
transparentPixel: transparentPixel,
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue