pandora/static/js/pandora/itemClips.js

117 lines
4.5 KiB
JavaScript
Raw Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2011-10-19 10:47:33 +00:00
pandora.ui.itemClips = function(options) {
var self = {},
2012-01-18 19:03:29 +00:00
textKey = pandora.getClipTextKey(),
2011-10-19 10:47:33 +00:00
that = Ox.Element()
.css({
height: '192px',
margin: '4px'
})
.bindEvent({
doubleclick: doubleclick,
singleclick: singleclick
2011-10-19 10:47:33 +00:00
});
self.options = Ox.extend({
2011-10-19 16:40:52 +00:00
clips: [],
2011-10-19 10:47:33 +00:00
duration: 0,
id: '',
ratio: 8/5
}, options);
self.size = 128;
self.width = self.options.ratio > 1 ? self.size : Math.round(self.size * self.options.ratio);
self.height = self.options.ratio > 1 ? Math.round(self.size / self.options.ratio) : self.size;
2011-10-19 16:40:52 +00:00
self.options.clips.forEach(function(clip, i) {
2011-11-04 15:54:42 +00:00
Ox.Log('', 'CLIP', clip)
2011-10-19 10:47:33 +00:00
var id = self.options.id + '/' + clip['in'],
2011-10-19 16:40:52 +00:00
title = Ox.map(clip.annotations, function(annotation) {
2012-01-18 19:03:29 +00:00
if(textKey == 'subtitles') {
return annotation.layer == 'subtitles' ? annotation.value : 0;
}
return annotation.value;
2011-10-19 16:40:52 +00:00
}),
2011-10-19 10:47:33 +00:00
url = '/' + self.options.id + '/' + self.height + 'p' + clip['in'] + '.jpg',
$item = Ox.IconItem({
imageHeight: self.height,
imageWidth: self.width,
id: id,
info: Ox.formatDuration(clip['in']) + ' - ' + Ox.formatDuration(clip.out),
2011-10-19 16:40:52 +00:00
title: title[0] || '',
2011-10-19 10:47:33 +00:00
url: url,
})
.addClass('OxInfoIcon')
.css({
float: 'left',
margin: i == 0 ? '2px 2px 2px -2px'
: i == self.options.clips.length - 1 ? '2px -2px 2px 2px'
: '2px'
2011-10-19 10:47:33 +00:00
})
.data({'in': clip['in'], out: clip.out});
$item.$element.find('.OxTarget').addClass('OxSpecialTarget');
that.append($item);
});
function doubleclick(data) {
var $item, $target = $(data.target), item, points, set;
2011-10-19 13:00:10 +00:00
if ($target.parent().parent().is('.OxSpecialTarget')) {
// for videos, the click registers deeper inside
$target = $target.parent().parent();
}
if ($target.is('.OxSpecialTarget')) {
$item = $target.parent().parent();
item = self.options.id;
points = [$item.data('in'), $item.data('out')];
set = {};
set['videoPoints.' + item] = {
'in': points[0],
out: points[1],
position: points[0]
};
pandora.UI.set(set);
}
}
function singleclick(data) {
2011-10-19 13:00:10 +00:00
var $img, $item, $target = $(data.target), points;
2011-10-19 10:47:33 +00:00
if ($target.is('.OxSpecialTarget')) {
$item = $target.parent().parent();
$img = $item.find('.OxIcon > img');
points = [$item.data('in'), $item.data('out')];
if ($img.length) {
2011-10-25 13:59:27 +00:00
pandora.api.get({id: self.options.id, keys: ['durations', 'rightslevel']}, function(result) {
2011-10-19 10:47:33 +00:00
var partsAndPoints = pandora.getVideoPartsAndPoints(
result.data.durations, points
),
$player = Ox.VideoPlayer({
2011-10-25 13:59:27 +00:00
censored: pandora.site.capabilities.canPlayClips[pandora.user.level] < result.data.rightslevel
2011-10-22 21:03:28 +00:00
? [{'in': partsAndPoints.points[0], out: partsAndPoints.points[1]}]
: [],
enableMouse: true,
2011-10-19 10:47:33 +00:00
height: self.height,
'in': partsAndPoints.points[0],
out: partsAndPoints.points[1],
playInToOut: true,
poster: '/' + self.options.id + '/' + self.height + 'p' + points[0] + '.jpg',
rewind: true,
video: partsAndPoints.parts.map(function(i) {
2011-10-29 15:24:54 +00:00
var part = (i + 1),
prefix = pandora.site.site.videoprefix.replace('PART', part);
return prefix + '/' + self.options.id + '/96p' + part + '.' + pandora.user.videoFormat;
2011-10-19 10:47:33 +00:00
}),
width: self.width
})
.addClass('OxTarget OxSpecialTarget');
2011-10-19 10:47:33 +00:00
$img.replaceWith($player.$element);
});
}
}
}
return that;
2011-10-29 15:24:54 +00:00
};