pandora/static/js/embedTimeline.js

221 lines
7.4 KiB
JavaScript
Raw Permalink Normal View History

2013-03-02 08:47:57 +00:00
'use strict';
pandora.ui.embedTimeline = function() {
var that = Ox.Element(),
ui = pandora.user.ui,
defaults = {
annotationsRange: ui.annotationsRange,
annotationsSort: ui.annotationsSort,
paused: true,
showAnnotations: false,
showLayers: pandora.site.layers.map(function(layer) {
return layer.id;
}),
timeline: ui.videoTimeline
},
options = getOptions(),
2013-11-04 14:09:43 +00:00
removed = false,
2013-03-02 08:47:57 +00:00
video,
2013-11-04 14:09:43 +00:00
$title, $panel, $player, $annotations;
2013-03-02 08:47:57 +00:00
2016-10-03 10:45:52 +00:00
pandora.api.get({id: ui.item, keys: pandora.VIDEO_OPTIONS_KEYS}, function(result) {
2013-11-04 14:09:43 +00:00
if (removed) {
return;
}
2013-03-02 08:47:57 +00:00
video = Ox.extend(result.data, pandora.getVideoOptions(result.data));
if (options.title) {
$title = Ox.Element()
.css({position: 'absolute'})
.append(
$('<div>')
.css({
marginTop: !options.title.match(/\\n/) ? '8px' : '2px',
textAlign: 'center'
})
.html(options.title.replace(/\\n/g, '<br>'))
);
} else {
$title = Ox.Element();
}
2013-11-04 14:09:43 +00:00
var sizes = getSizes();
2013-03-02 08:47:57 +00:00
$player = Ox.VideoTimelinePlayer({
censored: video.censored,
censoredIcon: pandora.site.cantPlay.icon,
censoredTooltip: pandora.site.cantPlay.text,
duration: video.duration,
followPlayer: ui.followPlayer,
getFrameURL: function(position) {
return pandora.getMediaURL(
'/' + ui.item + '/' + ui.videoResolution + 'p' + position + '.jpg'
);
2013-03-02 08:47:57 +00:00
},
getLargeTimelineURL: function(type, i) {
return pandora.getMediaURL(
'/' + ui.item + '/timeline' + type + '64p' + i + '.jpg'
);
2013-03-02 08:47:57 +00:00
},
2013-11-04 14:09:43 +00:00
height: sizes.innerHeight,
2013-03-02 08:47:57 +00:00
muted: ui.videoMuted,
paused: options.paused,
position: options.position,
resolution: Ox.min(pandora.site.video.resolutions),
smallTimelineURL: pandora.getMediaURL('/' + ui.item + '/timeline16p.jpg'),
subtitles: pandora.getSubtitles(video),
2013-11-04 14:09:43 +00:00
timeline: ui.videoTimeline,
timelines: pandora.site.timelines,
2013-03-02 08:47:57 +00:00
video: video.video,
videoRatio: video.videoRatio,
volume: ui.videoVolume,
2013-11-04 14:09:43 +00:00
width: sizes.innerWidth
2013-03-02 08:47:57 +00:00
})
.bindEvent({
playing: function(data) {
setPosition(data.position, true);
},
position: function(data) {
setPosition(data.position);
},
});
if (options.showAnnotations) {
video.annotations = video.annotations.filter(function(layer) {
return Ox.contains(options.showLayers, layer.id);
});
if (options.playInToOut) {
video.annotations.forEach(function(layer) {
var items = [];
layer.items.forEach(function(item) {
if ((
item['in'] >= options['in'] && item['in'] <= options.out
) || (
item.out >= options['in'] && item.out <= options.out
)) {
items.push(item);
}
});
layer.items = items;
});
}
$annotations = Ox.AnnotationPanel(Ox.extend({
clickLink: pandora.clickLink,
2013-03-02 08:47:57 +00:00
layers: video.annotations,
position: options.position,
range: options.annotationsRange,
showLayers: ui.showLayers,
showUsers: true,
sort: options.annotationsSort,
width: window.innerWidth
}, options['in'] ? {
'in': options['in']
} : {}, options.out ? {
out: options.out
} : {}))
.bindEvent({
select: selectAnnotation
})
} else {
$annotations = Ox.Element();
}
$panel = Ox.SplitPanel({
elements: [
{element: $title, size: options.title ? 32 : 0},
{element: $player},
{element: $annotations, size: options.showAnnotations ? 256 : 0}
],
orientation: 'vertical'
});
that.setElement($panel);
Ox.$parent.postMessage('loaded');
2013-11-04 14:09:43 +00:00
});
2013-03-02 08:47:57 +00:00
function getOptions() {
var options = {};
2013-11-04 14:09:43 +00:00
if (ui._hash.query) {
ui._hash.query.forEach(function(condition) {
options[condition.key] = condition.value;
});
}
2013-03-02 08:47:57 +00:00
options = Ox.extend(
{item: ui.item},
ui.videoPoints[ui.item] || {},
defaults,
options
);
if (!options.position) {
options.position = options['in'] || 0;
}
if (!options['in'] && !options.out) {
options.playInToOut = false;
} else if (options['in'] && options['in'] == options.out) {
options.invertHighlight = false;
options.paused = true;
options.playInToOut = false;
}
return options;
}
2013-11-04 14:09:43 +00:00
function getSizes() {
var innerHeight,
innerWidth,
maxVideoHeight = window.innerHeight
- (options.title ? 32 : 0)
- (options.showTimeline ? 80 : 0)
- (options.showAnnotations ? 128 : 0),
videoHeight;
if (options.matchRatio || options.showAnnotations) {
videoHeight = Math.round(window.innerWidth / video.videoRatio);
options.matchRatio = videoHeight <= maxVideoHeight;
if (!options.matchRatio) {
videoHeight = maxVideoHeight;
}
} else {
videoHeight = window.innerHeight
- (options.title ? 32 : 0)
- (options.showTimeline ? 80 : 0);
}
innerHeight = videoHeight
+ (options.title ? 32 : 0)
+ (options.showTimeline ? 80 : 0);
innerWidth = window.innerWidth;
return {
innerHeight: innerHeight,
innerWidth: innerWidth,
videoHeight: videoHeight
};
}
2013-03-02 08:47:57 +00:00
function getTimelineHeight() {
return window.innerHeight
- (options.title ? 32 : 0)
- (options.showAnnotations ? 256 : 0);
}
function selectAnnotation(data) {
if (data.id) {
setPosition(Math.max(data['in'], options['in'] || 0));
$annotations.options({selected: ''});
}
}
function setPosition(position, playing) {
!playing && $player.options({position: position});
options.showAnnotations && $annotations.options({position: position});
}
that.resizePanel = function() {
var sizes = getSizes();
$player.options({width: window.innerWidth, height: getTimelineHeight()});
options.showAnnotations && $annotations.options({width: window.innerWidth});
return that;
};
return that;
2013-11-04 14:09:43 +00:00
};