update info view when switching icons

This commit is contained in:
rolux 2011-08-07 22:15:08 +00:00
parent 881ce6513d
commit 20cb120d4b
2 changed files with 174 additions and 137 deletions

View file

@ -8,12 +8,13 @@ pandora.ui.infoView = function(data) {
}, },
listWidth = 144 + Ox.UI.SCROLLBAR_SIZE, listWidth = 144 + Ox.UI.SCROLLBAR_SIZE,
margin = 16, margin = 16,
posterSize = pandora.user.ui.infoIconSize, iconSize = pandora.user.ui.infoIconSize,
posterRatio = data.poster.width / data.poster.height, iconRatio = pandora.user.ui.icons == 'posters'
posterWidth = posterRatio > 1 ? posterSize : Math.round(posterSize * posterRatio), ? data.poster.width / data.poster.height : 1,
posterHeight = posterRatio < 1 ? posterSize : Math.round(posterSize / posterRatio), iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio),
posterLeft = posterSize == 256 ? Math.floor((posterSize - posterWidth) / 2) : 0, iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio),
editPoster = false, iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
edit = false,
that = Ox.Element(), that = Ox.Element(),
uid = Ox.uid(), uid = Ox.uid(),
$list, $list,
@ -34,20 +35,22 @@ pandora.ui.infoView = function(data) {
height: pandora.$ui.contentPanel.size(1) + 'px' height: pandora.$ui.contentPanel.size(1) + 'px'
}) })
.appendTo($info), .appendTo($info),
$poster = Ox.Element('<img>') $icon = Ox.Element('<img>')
.attr({ .attr({
src: '/' + data.id + '/poster512.jpg?' + uid src: '/' + data.id + '/' + (
pandora.user.ui.icons == 'posters' ? 'poster' : 'icon'
) + '512.jpg?' + uid
}) })
.css({ .css({
position: 'absolute', position: 'absolute',
left: margin + posterLeft + 'px', left: margin + iconLeft + 'px',
top: margin + 'px', top: margin + 'px',
width: posterWidth + 'px', width: iconWidth + 'px',
height: posterHeight + 'px', height: iconHeight + 'px',
cursor: 'pointer' cursor: 'pointer'
}) })
.bindEvent({ .bindEvent({
singleclick: togglePosterSize singleclick: toggleIconSize
}) })
.appendTo($data.$element), .appendTo($data.$element),
$reflection = $('<div>') $reflection = $('<div>')
@ -55,34 +58,36 @@ pandora.ui.infoView = function(data) {
.css({ .css({
position: 'absolute', position: 'absolute',
left: margin + 'px', left: margin + 'px',
top: margin + posterHeight + 'px', top: margin + iconHeight + 'px',
width: posterSize + 'px', width: iconSize + 'px',
height: posterSize / 2 + 'px', height: iconSize / 2 + 'px',
overflow: 'hidden' overflow: 'hidden'
}) })
.appendTo($data.$element), .appendTo($data.$element),
$reflectionPoster = $('<img>') $reflectionIcon = $('<img>')
.attr({ .attr({
src: '/' + data.id + '/poster512.jpg?' + uid src: '/' + data.id + '/' + (
pandora.user.ui.icons == 'posters' ? 'poster' : 'icon'
) + '512.jpg?' + uid
}) })
.css({ .css({
position: 'absolute', position: 'absolute',
left: posterLeft + 'px', left: iconLeft + 'px',
width: posterWidth + 'px', width: iconWidth + 'px',
height: posterHeight + 'px' height: iconHeight + 'px'
}) })
.appendTo($reflection), .appendTo($reflection),
$reflectionGradient = $('<div>') $reflectionGradient = $('<div>')
.css({ .css({
position: 'absolute', position: 'absolute',
width: posterSize + 'px', width: iconSize + 'px',
height: posterSize / 2 + 'px' height: iconSize / 2 + 'px'
}) })
.appendTo($reflection), .appendTo($reflection),
$text = $('<div>') $text = $('<div>')
.css({ .css({
position: 'absolute', position: 'absolute',
left: margin + (posterSize == 256 ? 256 : posterWidth) + margin + 'px', left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
top: margin + 'px', top: margin + 'px',
right: margin + 'px' right: margin + 'px'
}) })
@ -313,36 +318,57 @@ pandora.ui.infoView = function(data) {
$('<div>').css({height: '8px'}).appendTo($text); $('<div>').css({height: '8px'}).appendTo($text);
if (pandora.user.level == 'admin') { if (pandora.user.level == 'admin') {
var icon = 'posters',
selectedImage = {};
$poster.bindEvent({ $icon.bindEvent({
doubleclick: function() { doubleclick: function() {
if (!editPoster) { if (!edit) {
$info.animate({ $info.animate({
left: 0 left: 0
}, 250); }, 250);
editPoster = true; edit = true;
} else { } else {
$info.animate({ $info.animate({
left: -listWidth + 'px' left: -listWidth + 'px'
}, 250); }, 250);
editPoster = false; edit = false;
} }
} }
}); });
renderList();
}
function formatKey(key) {
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) {
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;
}).join(', ');
}
function renderList() {
pandora.api.get({ pandora.api.get({
id: data.id, id: data.id,
keys: [icon] keys: [pandora.user.ui.icons == 'posters' ? 'posters' : 'frames']
}, 0, function(result) { }, 0, function(result) {
Ox.print('RESULT', result.data) Ox.print('RESULT', result.data)
var images = result.data[icon]; var images = result.data[pandora.user.ui.icons == 'posters' ? 'posters' : 'frames'],
selectedImage = images.filter(function(image) { selectedImage = images.filter(function(image) {
return image.selected; return image.selected;
})[0]; })[0];
$list = Ox.IconList({ $list = Ox.IconList({
defaultRatio: 5/8, defaultRatio: pandora.user.ui.icons == 'posters' ? 5/8 : data.stream.aspectRatio,
fixedRatio: pandora.user.ui.icons == 'posters' ? false : data.stream.aspectRatio,
item: function(data, sort, size) { item: function(data, sort, size) {
var ratio = data.width / data.height; var ratio = data.width / data.height;
size = size || 128; size = size || 128;
@ -350,13 +376,13 @@ pandora.ui.infoView = function(data) {
height: ratio <= 1 ? size : size / ratio, height: ratio <= 1 ? size : size / ratio,
id: data['id'], id: data['id'],
info: data.width + ' x ' + data.height + ' px', info: data.width + ' x ' + data.height + ' px',
title: icon == 'posters' ? data.source : Ox.formatDuration(data.position), title: pandora.user.ui.icons == 'posters' ? data.source : Ox.formatDuration(data.position),
url: data.url, url: data.url,
width: ratio >= 1 ? size : size * ratio width: ratio >= 1 ? size : size * ratio
} }
}, },
items: images, items: images,
keys: icon == 'posters' keys: pandora.user.ui.icons == 'posters'
? ['index', 'source', 'width', 'height', 'url'] ? ['index', 'source', 'width', 'height', 'url']
: ['index', 'position', 'width', 'height', 'url'], : ['index', 'position', 'width', 'height', 'url'],
max: 1, max: 1,
@ -384,13 +410,14 @@ pandora.ui.infoView = function(data) {
var imageRatio = selectedImage.width / selectedImage.height, var imageRatio = selectedImage.width / selectedImage.height,
src = selectedImage.url; src = selectedImage.url;
if ($browserImages.length == 0) { if ($browserImages.length == 0) {
$browserImages = pandora.$ui.browser.find('img[src*="/' + data.id + '/poster"]'); $browserImages = pandora.$ui.browser.find('img[src*="/' + data.id + '/"]');
} }
if (pandora.user.ui.icons == 'posters') {
$browserImages.each(function() { $browserImages.each(function() {
var $this = $(this), var $this = $(this),
size = Math.max($this.width(), $this.height()); size = Math.max($this.width(), $this.height());
$this.attr({src: src}); $this.attr({src: src});
icon == 'posters' && $this.css(imageRatio < 1 ? { pandora.user.ui.icons == 'posters' && $this.css(imageRatio < 1 ? {
width: Math.round(size * imageRatio) + 'px', width: Math.round(size * imageRatio) + 'px',
height: size + 'px' height: size + 'px'
} : { } : {
@ -398,75 +425,82 @@ pandora.ui.infoView = function(data) {
height: Math.round(size / imageRatio) + 'px' height: Math.round(size / imageRatio) + 'px'
}); });
}); });
$poster.attr({src: src}); $icon.attr({src: src});
$reflectionPoster.attr({src: src}); $reflectionIcon.attr({src: src});
posterRatio = imageRatio; iconRatio = imageRatio;
posterSize = posterSize == 256 ? 512 : 256; iconSize = iconSize == 256 ? 512 : 256;
togglePosterSize(); toggleIconSize();
pandora.api[icon == 'posters' ? 'setPoster' : 'setPosterFrame'](Ox.extend({ }
pandora.api[pandora.user.ui.icons == 'posters' ? 'setPoster' : 'setPosterFrame'](Ox.extend({
id: data.id id: data.id
}, icon == 'posters' ? { }, pandora.user.ui.icons == 'posters' ? {
source: selectedImage.source source: selectedImage.source
} : { } : {
position: selectedImage.index // fixme: api slightly inconsistent position: selectedImage.index // fixme: api slightly inconsistent
}), function() { }), function() {
var src;
if (pandora.user.ui.icons == 'frames') {
src = '/' + data.id + '/icon512.jpg?' + Ox.uid()
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
}
$browserImages.each(function() { $browserImages.each(function() {
$(this).attr({src: '/' + data.id + '/poster64.jpg?' + Ox.uid()}); $(this).attr({src: '/' + data.id + '/' + (
pandora.user.ui.icons == 'posters' ? 'poster' : 'icon'
) + '64.jpg?' + Ox.uid()});
}); });
}); });
} }
}) })
.appendTo($info); .appendTo($info);
}); });
return ;
} }
function formatKey(key) { function toggleIconSize() {
return '<span style="font-weight: bold">' + Ox.toTitleCase(key) + ':</span> '; iconSize = iconSize == 256 ? 512 : 256;
} iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio);
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio);
function formatLight(str) { iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
return '<span style="color: rgb(128, 128, 128)">' + str + '</span>'; $icon.animate({
} left: margin + iconLeft + 'px',
width: iconWidth + 'px',
function formatValue(value, key) { height: iconHeight + 'px'
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;
}).join(', ');
}
function togglePosterSize() {
posterSize = posterSize == 256 ? 512 : 256;
posterWidth = posterRatio > 1 ? posterSize : Math.round(posterSize * posterRatio);
posterHeight = posterRatio < 1 ? posterSize : Math.round(posterSize / posterRatio);
posterLeft = posterSize == 256 ? Math.floor((posterSize - posterWidth) / 2) : 0,
$poster.animate({
left: margin + posterLeft + 'px',
width: posterWidth + 'px',
height: posterHeight + 'px'
}, 250); }, 250);
$reflection.animate({ $reflection.animate({
top: margin + posterHeight + 'px', top: margin + iconHeight + 'px',
width: posterSize + 'px', width: iconSize + 'px',
height: posterSize / 2 + 'px' height: iconSize / 2 + 'px'
}, 250); }, 250);
$reflectionPoster.animate({ $reflectionIcon.animate({
left: posterLeft + 'px', left: iconLeft + 'px',
width: posterWidth + 'px', width: iconWidth + 'px',
height: posterHeight + 'px', height: iconHeight + 'px',
}, 250); }, 250);
$reflectionGradient.animate({ $reflectionGradient.animate({
width: posterSize + 'px', width: iconSize + 'px',
height: posterSize / 2 + 'px' height: iconSize / 2 + 'px'
}, 250); }, 250);
$text.animate({ $text.animate({
left: margin + (posterSize == 256 ? 256 : posterWidth) + margin + 'px', left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
}, 250); }, 250);
pandora.UI.set({infoIconSize: posterSize}); pandora.UI.set({infoIconSize: iconSize});
} }
that.reload = function() {
var src = src = '/' + data.id + '/' + (
pandora.user.ui.icons == 'posters' ? 'poster' : 'icon'
) + '512.jpg?' + Ox.uid()
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
iconSize = iconSize == 256 ? 512 : 256;
iconRatio = pandora.user.ui.icons == 'posters'
? data.poster.width / data.poster.height : 1,
toggleIconSize();
edit && $list.replaceWith($list = renderList());
};
that.resize = function() { that.resize = function() {
var height = pandora.$ui.contentPanel.size(1); var height = pandora.$ui.contentPanel.size(1);
$list && $list.css({height: height + 'px'}); $list && $list.css({height: height + 'px'});

View file

@ -186,13 +186,16 @@ pandora.ui.mainMenu = function() {
var $list; var $list;
pandora.UI.set({icons: value}); pandora.UI.set({icons: value});
if (pandora.user.ui.item) { if (pandora.user.ui.item) {
if (pandora.user.ui.itemView == 'info') {
pandora.$ui.item.reload();
}
$list = pandora.$ui.browser; $list = pandora.$ui.browser;
} else if (pandora.user.ui.lists[pandora.user.ui.list].listView == 'icons') { } else if (pandora.user.ui.lists[pandora.user.ui.list].listView == 'icons') {
$list = pandora.$ui.list $list = pandora.$ui.list
} }
$list && $list.options({ $list && $list.options({
defaultRatio: value == 'posters' ? 5/8 : 1 defaultRatio: value == 'posters' ? 5/8 : 1
}).reloadList(); }).reloadList(true);
} else if (data.id == 'viewmovies') { } else if (data.id == 'viewmovies') {
url('#view=' + value); url('#view=' + value);
} }