pandora/static/js/pandora/tv.js

162 lines
5.7 KiB
JavaScript
Raw Normal View History

2011-12-19 21:12:23 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.tv = function() {
var that = Ox.Element()
.addClass('OxScreen')
.css({
position: 'absolute',
width: '100%',
height: '100%',
opacity: 0,
zIndex: 1000
}),
2011-12-24 06:07:23 +00:00
$player,
list = pandora.user.ui._list,
lists = [];
function getList(direction) {
lists.length == 0 && getLists();
var index = lists.indexOf(list);
return lists[
direction == -1
? (index == 0 ? lists.length - 1 : index - 1)
: (index == lists.length - 1 ? 0 : index + 1)
];
}
function getLists() {
var menu = pandora.$ui.mainMenu.options('menus')[2];
lists = [''];
Ox.loop(3, function(f) {
menu.items[f + 1].items.forEach(function(l) {
lists.push(l.id.substr(8));
});
});
}
2011-12-19 21:12:23 +00:00
function play() {
pandora.api.tv({
2011-12-24 06:07:23 +00:00
list: list
2011-12-19 21:12:23 +00:00
}, function(result) {
var videoOptions = pandora.getVideoOptions(result.data);
2011-12-20 13:08:30 +00:00
$player && $player.remove();
2011-12-19 21:12:23 +00:00
$player = Ox.VideoPlayer({
censored: videoOptions.censored,
2011-12-24 06:07:23 +00:00
controlsBottom: [
'zapPrevious', 'zapHome', 'zapNext',
'volume', 'scale', 'timeline', 'position', 'settings'
],
2011-12-23 10:51:53 +00:00
controlsTop: ['close', 'title', 'open'],
2011-12-19 21:12:23 +00:00
duration: result.data.duration,
2011-12-22 15:48:48 +00:00
enableSubtitles: pandora.user.ui.videoSubtitles,
2011-12-19 21:12:23 +00:00
fullscreen: true,
logo: pandora.site.tv.showLogo ? '/static/png/logo256.png' : '',
position: result.data.position,
2011-12-20 13:08:30 +00:00
resolution: pandora.user.ui.videoResolution,
2011-12-19 21:12:23 +00:00
scaleToFill: pandora.user.ui.videoScale == 'fill',
subtitles: videoOptions.subtitles,
tooltips: true,
timeline: '/' + result.data.item + '/timeline16p.png',
title: pandora.site.site.name + ' — ' + (
2011-12-24 06:07:23 +00:00
list || 'All ' + pandora.site.itemName.plural
2011-12-19 21:12:23 +00:00
) + ' — '
+ result.data.title
+ ' (' + result.data.director.join(', ') + ') '
+ result.data.year,
video: videoOptions.video,
volume: pandora.user.ui.videoVolume
})
.bindEvent({
2011-12-20 13:08:30 +00:00
close: that.fadeOutScreen,
ended: play,
2011-12-22 15:48:48 +00:00
muted: function(data) {
pandora.UI.set('videoMuted', data.muted);
},
2011-12-23 10:51:53 +00:00
open: function() {
var item = result.data.item,
position = $player.options('position'),
set = {
item: item,
itemView: pandora.user.ui.videoView,
page: ''
};
if (pandora.user.ui.videoPoints[item]) {
set['videoPoints.' + item + '.position'] = position;
} else {
set['videoPoints.' + item] = {
'in': 0, out: 0, position: position
};
}
2011-12-23 10:51:53 +00:00
pandora.UI.set(set);
},
2011-12-20 13:08:30 +00:00
resolution: function(data) {
pandora.UI.set('videoResolution', data.resolution);
2011-12-22 15:48:48 +00:00
},
scale: function(data) {
pandora.UI.set('videoScale', data.scale);
},
subtitles: function(data) {
pandora.UI.set('videoSubtitles', data.subtitles);
},
volume: function(data) {
pandora.UI.set('videoVolume', data.volume);
},
2011-12-24 06:07:23 +00:00
zap: function(data) {
if (!(data.direction == 0 && list == '')) {
list = data.direction == 0 ? '' : getList(data.direction);
play();
}
},
key_enter: function() {
$player.triggerEvent('open');
},
key_escape: function() {
$player.triggerEvent('close');
},
key_left: function() {
$player.triggerEvent('zap', {direction: -1});
},
key_right: function() {
$player.triggerEvent('zap', {direction: 1});
},
key_up: function() {
$player.triggerEvent('zap', {direction: 0});
}
2011-12-19 21:12:23 +00:00
})
.appendTo(that);
});
}
that.fadeInScreen = function() {
that.appendTo(Ox.UI.$body).animate({opacity: 1}, 500);
play();
2011-12-20 13:08:30 +00:00
return that;
2011-12-19 21:12:23 +00:00
};
that.fadeOutScreen = function() {
2011-12-20 13:08:30 +00:00
that.animate({opacity: 0}, 500, function() {
that.remove();
});
pandora.UI.set('page', '');
return that;
2011-12-19 21:12:23 +00:00
};
that.hideScreen = function() {
2011-12-20 13:08:30 +00:00
that.remove();
pandora.UI.set('page', '');
return that;
2011-12-19 21:12:23 +00:00
};
that.showScreen = function() {
that.css({opacity: 1}).appendTo(Ox.UI.$body);
play();
2011-12-20 13:08:30 +00:00
return that;
2011-12-19 21:12:23 +00:00
};
return that;
2011-12-20 13:08:30 +00:00
}