pandora/static/js/embedInfo.js

140 lines
3.9 KiB
JavaScript
Raw Normal View History

2014-01-22 12:11:33 +00:00
'use strict';
pandora.ui.embedInfo = function() {
2014-01-22 13:57:38 +00:00
var data,
item = pandora.user.ui.item,
2014-01-22 17:10:13 +00:00
margin = 16,
2014-01-22 13:57:38 +00:00
that = Ox.Element(),
2014-01-22 17:02:26 +00:00
$icon, $reflection, $reflectionIcon, $reflectionGradient,
$text;
2014-01-22 13:46:52 +00:00
pandora.api.get({
id: item,
keys: ['director', 'posterRatio', 'title', 'year']
}, function(result) {
data = result.data;
2014-01-22 13:57:38 +00:00
$icon = Ox.$('<img>')
.attr({src: pandora.getMediaURL('/' + item + '/poster512.jpg')})
2014-01-22 13:57:38 +00:00
.css({
position: 'absolute',
2014-01-22 17:10:13 +00:00
top: margin + 'px',
2014-01-22 13:57:38 +00:00
cursor: 'pointer'
})
2014-01-22 17:30:49 +00:00
.on({
click: function() {
window.open('/' + item + '/info', '_blank');
}
})
2014-01-22 13:57:38 +00:00
.appendTo(that);
$reflection = Ox.$('<div>')
.addClass('OxReflection')
.css({
position: 'absolute',
overflow: 'hidden'
})
.appendTo(that);
2014-01-22 17:02:26 +00:00
$reflectionIcon = Ox.$('<img>')
.attr({src: pandora.getMediaURL('/' + item + '/poster512.jpg')})
2014-01-22 13:57:38 +00:00
.css({
2014-01-22 17:02:26 +00:00
position: 'absolute'
2014-01-22 13:57:38 +00:00
})
.appendTo($reflection);
2014-01-22 17:02:26 +00:00
$reflectionGradient = Ox.$('<div>')
2014-01-22 13:57:38 +00:00
.css({
2014-01-22 17:02:26 +00:00
position: 'absolute'
2014-01-22 13:57:38 +00:00
})
.appendTo($reflection);
$text = Ox.$('<div>')
.css({
position: 'absolute',
2014-01-22 17:10:13 +00:00
left: margin + 'px',
right: margin + 'px'
2014-01-22 13:57:38 +00:00
})
.appendTo(that);
2014-01-22 13:46:52 +00:00
Ox.$('<div>')
2014-01-22 17:10:13 +00:00
.css({
fontWeight: 'bold',
fontSize: '13px',
textAlign: 'center'
})
2014-01-22 17:30:49 +00:00
.html(data.title + (
data.year
? ' (<a href="/year=' + data.year
+ '" target="_blank">' + data.year + '</a>)'
: ''
))
2014-01-22 13:46:52 +00:00
.appendTo($text);
if (data.director) {
Ox.$('<div>')
2014-01-22 17:10:13 +00:00
.css({
marginTop: '8px',
fontWeight: 'bold',
fontSize: '13px',
textAlign: 'center'
})
2014-01-22 17:02:26 +00:00
.html(data.director.map(function(director) {
// fixme: there should be a utils method for this
return '<a href="/name='
+ director.replace('_', '\t').replace(' ', '_')
+ '" target="_blank">' + director + '</a>'
}).join(', '))
2014-01-22 13:46:52 +00:00
.appendTo($text);
}
2014-01-22 17:02:26 +00:00
that.resizePanel();
2014-01-22 13:46:52 +00:00
});
2014-01-22 12:11:33 +00:00
2014-01-22 13:57:38 +00:00
that.resizePanel = function() {
2014-01-22 17:10:13 +00:00
var posterSize = Math.floor((Math.min(
window.innerWidth, window.innerHeight
) - 2 * margin) * 2/3),
2014-01-22 17:02:26 +00:00
posterWidth = Math.round(
data.posterRatio > 1
? posterSize
: posterSize * data.posterRatio
),
posterHeight = Math.round(
data.posterRatio > 1
? posterSize / data.posterRatio
: posterSize
),
posterLeft = Math.floor((window.innerWidth - posterWidth) / 2);
$icon.css({
left: posterLeft + 'px',
width: posterWidth + 'px',
height: posterHeight + 'px'
});
$reflection.css({
left: posterLeft + 'px',
2014-01-22 17:10:13 +00:00
top: posterHeight + margin + 'px',
2014-01-22 17:02:26 +00:00
width: posterWidth + 'px',
height: Math.round(posterHeight / 2) + 'px'
});
$reflectionIcon.css({
width: posterWidth + 'px',
height: posterHeight + 'px'
});
$reflectionGradient.css({
width: posterSize + 'px',
height: Math.round(posterHeight / 2) + 'px'
});
$text.css({
2014-01-22 17:10:13 +00:00
top: 2 * margin + posterHeight + 'px'
2014-01-22 17:02:26 +00:00
});
return that;
2014-01-22 13:57:38 +00:00
};
2014-01-22 12:11:33 +00:00
return that;
};