pandora/static/js/tv.js

212 lines
7.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,
2013-07-11 18:13:34 +00:00
list = pandora.user.ui.part.tv,
2012-02-19 12:58:49 +00:00
lists = [],
muted;
2011-12-24 06:07:23 +00:00
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) {
2012-05-24 09:56:52 +00:00
lists.push(l.id.slice(8));
2011-12-24 06:07:23 +00:00
});
});
}
2011-12-19 21:12:23 +00:00
2014-09-16 11:30:53 +00:00
function getSubtitles(options) {
return options.subtitlesLayer ? options.annotations.filter(function(layer) {
return layer.id == options.subtitlesLayer;
})[0].items.map(function(subtitle) {
return {
id: subtitle.id,
'in': subtitle['in'],
out: subtitle.out,
text: subtitle.value.replace(/\n/g, ' ').replace(/<br\/?>/g, '\n'),
tracks: subtitle.languages || [Ox.getLanguageNameByCode(pandora.site.language)]
};
}) : []
}
2011-12-19 21:12:23 +00:00
function play() {
2012-04-23 08:57:52 +00:00
var $loading = $('<img>')
.attr({src: Ox.UI.getImageURL('symbolLoadingAnimated')})
.css({
position: 'absolute',
left: 0, top: 0, right: 0, bottom: 0,
width: '32px', height: '32px',
margin: 'auto'
})
.appendTo(that);
2011-12-19 21:12:23 +00:00
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);
2012-04-23 08:57:52 +00:00
$loading.remove();
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,
2013-06-18 15:31:03 +00:00
censoredIcon: pandora.site.cantPlay.icon,
2011-12-24 06:07:23 +00:00
controlsBottom: [
'zapPrevious', 'zapHome', 'zapNext',
'volume', 'scale', 'timeline', 'position', 'settings'
],
controlsTooltips: {
2013-05-09 10:13:58 +00:00
open: Ox._('Open in {0} View', [Ox._(Ox.getObjectById(
pandora.site.itemViews, pandora.user.ui.videoView
2013-05-09 10:13:58 +00:00
).title)])
},
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/logo.png' : '',
2012-02-19 12:58:49 +00:00
muted: muted || pandora.user.ui.videoMuted,
2011-12-19 21:12:23 +00:00
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',
2014-09-16 11:30:53 +00:00
subtitles: getSubtitles(videoOptions),
2014-09-13 21:18:46 +00:00
subtitlesDefaultTrack: Ox.getLanguageNameByCode(pandora.site.language),
subtitlesLayer: videoOptions.subtitlesLayer,
subtitlesTrack: Ox.getLanguageNameByCode(pandora.site.language),
2011-12-19 21:12:23 +00:00
tooltips: true,
2012-05-17 09:38:59 +00:00
timeline: '/' + result.data.item + '/timeline16p.jpg',
2011-12-19 21:12:23 +00:00
title: pandora.site.site.name + ' &mdash; ' + (
2013-05-09 10:13:58 +00:00
list || Ox._('All {0}', [Ox._(pandora.site.itemName.plural)])
2011-12-19 21:12:23 +00:00
) + ' &mdash; '
+ result.data.title
2012-02-23 10:51:32 +00:00
+ (
result.data.director
? ' (' + result.data.director.join(', ') + ') '
: ''
) + result.data.year,
2011-12-19 21:12:23 +00:00
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) {
2013-07-14 15:36:49 +00:00
!muted && pandora.UI.set({videoMuted: data.muted});
2011-12-22 15:48:48 +00:00
},
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) {
2013-07-14 15:36:49 +00:00
pandora.UI.set({videoResolution: data.resolution});
2011-12-22 15:48:48 +00:00
},
scale: function(data) {
2013-07-14 15:36:49 +00:00
pandora.UI.set({videoScale: data.scale});
2011-12-22 15:48:48 +00:00
},
subtitles: function(data) {
2013-07-14 15:36:49 +00:00
pandora.UI.set({videoSubtitles: data.subtitles});
2011-12-22 15:48:48 +00:00
},
volume: function(data) {
2013-07-14 15:36:49 +00:00
pandora.UI.set({videoVolume: data.volume});
2011-12-22 15:48:48 +00:00
},
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();
});
2013-07-14 15:36:49 +00:00
pandora.UI.set({page: ''});
2011-12-20 13:08:30 +00:00
return that;
2011-12-19 21:12:23 +00:00
};
that.hideScreen = function() {
2011-12-20 13:08:30 +00:00
that.remove();
2013-07-14 15:36:49 +00:00
pandora.UI.set({page: ''});
2011-12-20 13:08:30 +00:00
return that;
2011-12-19 21:12:23 +00:00
};
2012-02-19 12:58:49 +00:00
that.mute = function() {
muted = true;
$player && $player.options({muted: muted});
return that;
2012-02-19 12:58:49 +00:00
};
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
};
2012-02-19 12:58:49 +00:00
that.unmute = function() {
$player && $player.options({muted: pandora.user.ui.videoMuted});
muted = false;
return that;
2012-02-19 12:58:49 +00:00
};
2011-12-19 21:12:23 +00:00
return that;
2011-12-20 13:08:30 +00:00
}