improving info view

This commit is contained in:
rolux 2011-08-06 03:19:14 +00:00
parent 732852ebc2
commit 280373f88e

View file

@ -1,12 +1,18 @@
pandora.ui.infoView = function(data) { pandora.ui.infoView = function(data) {
var listWidth = 144 + Ox.UI.SCROLLBAR_SIZE, var css = {
margin = 8, marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
},
listWidth = 144 + Ox.UI.SCROLLBAR_SIZE,
margin = 16,
posterSize = pandora.user.ui.infoIconSize, posterSize = pandora.user.ui.infoIconSize,
posterRatio = data.poster.width / data.poster.height, posterRatio = data.poster.width / data.poster.height,
posterWidth = posterRatio > 1 ? posterSize : Math.round(posterSize * posterRatio), posterWidth = posterRatio > 1 ? posterSize : Math.round(posterSize * posterRatio),
posterHeight = posterRatio < 1 ? posterSize : Math.round(posterSize / posterRatio), posterHeight = posterRatio < 1 ? posterSize : Math.round(posterSize / posterRatio),
posterLeft = Math.floor((posterSize - posterWidth) / 2), posterLeft = posterSize == 256 ? Math.floor((posterSize - posterWidth) / 2) : 0,
editPoster = false, editPoster = false,
that = Ox.Element(), that = Ox.Element(),
$list, $list,
@ -71,7 +77,6 @@ pandora.ui.infoView = function(data) {
.css({ .css({
display: 'block', display: 'block',
position: 'absolute', position: 'absolute',
left: margin + 'px',
width: posterSize + 'px', width: posterSize + 'px',
height: posterSize / 2 + 'px' height: posterSize / 2 + 'px'
}) })
@ -81,49 +86,55 @@ pandora.ui.infoView = function(data) {
$text = $('<div>') $text = $('<div>')
.css({ .css({
position: 'absolute', position: 'absolute',
left: margin + posterSize + margin + 'px', left: margin + (posterSize == 256 ? 256 : posterWidth) + margin + 'px',
top: margin + 'px', top: margin + 'px',
right: margin + 'px' right: margin + 'px'
}) })
.appendTo($data.$element); .appendTo($data.$element);
Ox.print('DATA', data);
['title', 'director'].forEach(function(key) { var match = /(\(S\d{2}(E\d{2})?\))/.exec(data.title);
$('<div>') if (match) {
.css({ data.title = data.title.replace(match[0], formatLight(match[0]));
marginTop: key == 'title' ? '-2px' : '2px', }
fontWeight: 'bold',
fontSize: '13px', $('<div>')
MozUserSelect: 'text', .css({
WebkitUserSelect: 'text' marginTop: '-2px',
}) fontWeight: 'bold',
.html( fontSize: '13px',
key == 'title' MozUserSelect: 'text',
? data.title + ( WebkitUserSelect: 'text'
data.original_title })
? ' <span style="color: rgb(128, 128, 128)">(' + data.original_title + ')</span>' .html(
: '' data.title + (data.original_title ? ' '
) + formatLight('(' + data.original_title + ')') : '')
: formatValue(data.director, 'name') )
) .appendTo($text);
.appendTo($text);
}); $('<div>')
.css({
marginTop: '2px',
fontWeight: 'bold',
fontSize: '13px',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html(formatValue(data.director, 'name'))
.appendTo($text);
if (data.country || data.year || data.language || data.runtime || pandora.user.level == 'admin') { if (data.country || data.year || data.language || data.runtime || pandora.user.level == 'admin') {
var $div = $('<div>') var $div = $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify'
})
.appendTo($text); .appendTo($text);
var html = []; var html = [];
['country', 'year', 'language', 'runtime'].forEach(function(key) { ['country', 'year', 'language', 'runtime'].forEach(function(key) {
if (data[key] || (['country', 'year'].indexOf(key) > -1 && pandora.user.level == 'admin')) { if (data[key] || (['country', 'year'].indexOf(key) > -1 && pandora.user.level == 'admin')) {
var value = data[key] || '<span style="color: rgb(128, 128, 128)">unknown</span>'; var value = data[key] || formatLight('unknown');
html.push( html.push(
formatKey(key) formatKey(key)
+ (key == 'runtime' + (key == 'runtime'
? Math.round(value / 60) + ' min' ? Math.round(value / 60) + ' min'
: formatValue(value, key == 'runtime' ? null : key)) : formatValue(value, key == 'runtime' || !data[key] ? null : key))
); );
} }
}); });
@ -132,34 +143,21 @@ pandora.ui.infoView = function(data) {
// fixme: should be camelCase! // fixme: should be camelCase!
data.alternative_titles && $('<div>') data.alternative_titles && $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html( .html(
formatKey('Alternative Titles') + data.alternative_titles.map(function(value) { formatKey('Alternative Titles') + data.alternative_titles.map(function(value) {
return value[0] + ( return value[0] + (value[1] ? ' '
value[1] + formatLight('(' + value[1] + ')') : '');
? ' <span style="color: rgb(128, 128, 128)">(' + value[1] + ')</span>'
: ''
);
}).join(', ') }).join(', ')
) )
.appendTo($text); .appendTo($text);
if (data.writer || data.producer || data.cinematographer || data.editor) { if (data.creator || data.writer || data.producer || data.cinematographer || data.editor) {
$div = $('<div>') $div = $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.appendTo($text); .appendTo($text);
html = []; html = [];
['writer', 'producer', 'cinematographer', 'editor'].forEach(function(key) { ['creator', 'writer', 'producer', 'cinematographer', 'editor'].forEach(function(key) {
data[key] && html.push( data[key] && html.push(
formatKey(key) + formatValue(data[key], 'name') formatKey(key) + formatValue(data[key], 'name')
); );
@ -168,32 +166,21 @@ pandora.ui.infoView = function(data) {
} }
data.cast && $('<div>') data.cast && $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html( .html(
formatKey('cast') + data.cast.map(function(value) { formatKey('cast') + data.cast.map(function(value) {
value.character = value.character.replace('(uncredited)', '').trim(); value.character = value.character.replace('(uncredited)', '').trim();
return formatValue(value.actor, 'name') + ( return formatValue(value.actor, 'name')
value.character + (value.character ? ' '
? ' <span style="color: rgb(128, 128, 128)">(' + formatValue(value.character) + ')</span>' + formatLight('(' + formatValue(value.character) + ')')
: '' : '');
);
}).join(', ') }).join(', ')
) )
.appendTo($text); .appendTo($text);
if (data.genre || data.keyword) { if (data.genre || data.keyword) {
$div = $('<div>') $div = $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.appendTo($text); .appendTo($text);
html = []; html = [];
['genre', 'keyword'].forEach(function(key) { ['genre', 'keyword'].forEach(function(key) {
@ -206,12 +193,7 @@ pandora.ui.infoView = function(data) {
} }
data.summary && $('<div>') data.summary && $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html( .html(
formatKey('summary') + data.summary formatKey('summary') + data.summary
) )
@ -249,24 +231,14 @@ pandora.ui.infoView = function(data) {
}); });
data.filming_locations && $('<div>') data.filming_locations && $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html( .html(
formatKey('Filming Locations') + data.filming_locations.join('; ') formatKey('Filming Locations') + data.filming_locations.join('; ')
) )
.appendTo($text); .appendTo($text);
data.releasedate && $('<div>') data.releasedate && $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html( .html(
formatKey('Release Date') + Ox.formatDate(data.releasedate, '%A, %B %e, %Y') formatKey('Release Date') + Ox.formatDate(data.releasedate, '%A, %B %e, %Y')
) )
@ -274,12 +246,7 @@ pandora.ui.infoView = function(data) {
if (data.budget || data.gross || data.profit) { if (data.budget || data.gross || data.profit) {
$div = $('<div>') $div = $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.appendTo($text); .appendTo($text);
html = []; html = [];
['budget', 'gross', 'profit'].forEach(function(key) { ['budget', 'gross', 'profit'].forEach(function(key) {
@ -292,12 +259,7 @@ pandora.ui.infoView = function(data) {
if (data.rating || data.votes) { if (data.rating || data.votes) {
$div = $('<div>') $div = $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.appendTo($text); .appendTo($text);
html = []; html = [];
['rating', 'votes'].forEach(function(key) { ['rating', 'votes'].forEach(function(key) {
@ -310,12 +272,7 @@ pandora.ui.infoView = function(data) {
if (data.connections) { if (data.connections) {
$div = $('<div>') $div = $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.appendTo($text); .appendTo($text);
html = []; html = [];
[ [
@ -336,12 +293,7 @@ pandora.ui.infoView = function(data) {
['reviews', 'links'].forEach(function(key) { ['reviews', 'links'].forEach(function(key) {
data[key] && $('<div>') data[key] && $('<div>')
.css({ .css(css)
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html( .html(
formatKey(key) + data[key].map(function(value) { formatKey(key) + data[key].map(function(value) {
return '<a href="' + value.url + '">' + value.source + '</a>' return '<a href="' + value.url + '">' + value.source + '</a>'
@ -457,6 +409,10 @@ pandora.ui.infoView = function(data) {
return '<span style="font-weight: bold">' + Ox.toTitleCase(key) + ':</span> '; return '<span style="font-weight: bold">' + Ox.toTitleCase(key) + ':</span> ';
} }
function formatLight(str) {
return '<span style="color: rgb(128, 128, 128)">' + str + '</span>';
}
function formatValue(value, key) { function formatValue(value, key) {
return (Ox.isArray(value) ? value : [value]).map(function(value) { return (Ox.isArray(value) ? value : [value]).map(function(value) {
return key ? '<a href="/?find=' + key + ':' + value + '">' + value + '</a>' : value; return key ? '<a href="/?find=' + key + ':' + value + '">' + value + '</a>' : value;
@ -467,7 +423,7 @@ pandora.ui.infoView = function(data) {
posterSize = posterSize == 256 ? 512 : 256; posterSize = posterSize == 256 ? 512 : 256;
posterWidth = posterRatio > 1 ? posterSize : Math.round(posterSize * posterRatio); posterWidth = posterRatio > 1 ? posterSize : Math.round(posterSize * posterRatio);
posterHeight = posterRatio < 1 ? posterSize : Math.round(posterSize / posterRatio); posterHeight = posterRatio < 1 ? posterSize : Math.round(posterSize / posterRatio);
posterLeft = Math.floor((posterSize - posterWidth) / 2); posterLeft = posterSize == 256 ? Math.floor((posterSize - posterWidth) / 2) : 0,
$poster.animate({ $poster.animate({
left: margin + posterLeft + 'px', left: margin + posterLeft + 'px',
width: posterWidth + 'px', width: posterWidth + 'px',
@ -488,7 +444,7 @@ pandora.ui.infoView = function(data) {
height: posterSize / 2 + 'px' height: posterSize / 2 + 'px'
}, 250); }, 250);
$text.animate({ $text.animate({
left: margin + posterSize + margin + 'px', left: margin + (posterSize == 256 ? 256 : posterWidth) + margin + 'px',
}, 250); }, 250);
pandora.api.setUI({infoIconSize: pandora.user.ui.infoIconSize = posterSize}); pandora.api.setUI({infoIconSize: pandora.user.ui.infoIconSize = posterSize});
} }