')
.css(css)
.html(
formatKey(key) + data[key].map(function(value) {
return '
'
}).join(', ')
)
.appendTo($text);
});
$('
').css({height: '8px'}).appendTo($text);
if (pandora.user.level == 'admin') {
$icon.bindEvent({
doubleclick: function() {
if (!edit) {
$info.animate({
left: 0
}, 250);
edit = true;
} else {
$info.animate({
left: -listWidth + 'px'
}, 250);
edit = false;
}
}
});
renderList();
}
function formatKey(key) {
return '
' + Ox.toTitleCase(key) + ': ';
}
function formatLight(str) {
return '
' + str + '';
}
function formatValue(value, key) {
return (Ox.isArray(value) ? value : [value]).map(function(value) {
return key ?
'
' + value + ''
: value;
//return key ? '
' + value + '' : value;
}).join(', ');
}
function renderList() {
pandora.api.get({
id: data.id,
keys: [pandora.user.ui.icons == 'posters' ? 'posters' : 'frames']
}, 0, function(result) {
Ox.print('RESULT', result.data)
var images = result.data[pandora.user.ui.icons == 'posters' ? 'posters' : 'frames'],
selectedImage = images.filter(function(image) {
return image.selected;
})[0];
$list = Ox.IconList({
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) {
var ratio = data.width / data.height;
size = size || 128;
return {
height: ratio <= 1 ? size : size / ratio,
id: data['id'],
info: data.width + ' x ' + data.height + ' px',
title: pandora.user.ui.icons == 'posters' ? data.source : Ox.formatDuration(data.position),
url: data.url,
width: ratio >= 1 ? size : size * ratio
}
},
items: images,
keys: pandora.user.ui.icons == 'posters'
? ['index', 'source', 'width', 'height', 'url']
: ['index', 'position', 'width', 'height', 'url'],
max: 1,
min: 1,
orientation: 'vertical',
selected: [selectedImage['index']],
size: 128,
sort: [{key: 'index', operator: '+'}],
unique: 'index'
})
.css({
display: 'block',
position: 'absolute',
left: 0,
top: 0,
width: listWidth + 'px',
height: pandora.$ui.contentPanel.size(1) + 'px'
})
.bindEvent({
select: function(event) {
var index = event.ids[0];
selectedImage = images.filter(function(image) {
return image.index == index;
})[0];
var imageRatio = selectedImage.width / selectedImage.height,
src = selectedImage.url;
if ($browserImages.length == 0) {
$browserImages = pandora.$ui.browser.find('img[src*="/' + data.id + '/"]');
}
if (pandora.user.ui.icons == 'posters') {
$browserImages.each(function() {
var $this = $(this),
size = Math.max($this.width(), $this.height());
$this.attr({src: src});
pandora.user.ui.icons == 'posters' && $this.css(imageRatio < 1 ? {
width: Math.round(size * imageRatio) + 'px',
height: size + 'px'
} : {
width: size + 'px',
height: Math.round(size / imageRatio) + 'px'
});
});
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
iconRatio = imageRatio;
iconSize = iconSize == 256 ? 512 : 256;
toggleIconSize();
}
pandora.api[pandora.user.ui.icons == 'posters' ? 'setPoster' : 'setPosterFrame'](Ox.extend({
id: data.id
}, pandora.user.ui.icons == 'posters' ? {
source: selectedImage.source
} : {
position: selectedImage.index // fixme: api slightly inconsistent, this shouldn't be "position"
}), function() {
// fixme: update the info (video preview) frame as well
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() {
$(this).attr({src: '/' + data.id + '/' + (
pandora.user.ui.icons == 'posters' ? 'poster' : 'icon'
) + '64.jpg?' + Ox.uid()});
});
});
}
})
.appendTo($info);
});
}
function toggleIconSize() {
iconSize = iconSize == 256 ? 512 : 256;
iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio);
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio);
iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
borderRadius = pandora.user.ui.icons == 'posters' ? 0 : iconSize / 8;
$icon.animate({
left: margin + iconLeft + 'px',
width: iconWidth + 'px',
height: iconHeight + 'px',
borderRadius: borderRadius + 'px'
}, 250);
$reflection.animate({
top: margin + iconHeight + 'px',
width: iconSize + 'px',
height: iconSize / 2 + 'px'
}, 250);
$reflectionIcon.animate({
left: iconLeft + 'px',
width: iconWidth + 'px',
height: iconHeight + 'px',
borderRadius: borderRadius + 'px'
}, 250);
$reflectionGradient.animate({
width: iconSize + 'px',
height: iconSize / 2 + 'px'
}, 250);
$text.animate({
left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
}, 250);
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();
pandora.user.level == 'admin' && $list.replaceWith($list = renderList());
};
that.resize = function() {
var height = pandora.$ui.contentPanel.size(1);
$list && $list.css({height: height + 'px'});
$data.css({height: height + 'px'});
};
return that;
}