pandora/static/js/pandora/clipList.js

201 lines
9.2 KiB
JavaScript
Raw Normal View History

2011-09-30 10:33:45 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.ui.clipList = function(videoRatio) {
var ui = pandora.user.ui,
fixedRatio = !ui.item ? 16/9 : videoRatio,
isClipView = !ui.item ? ui.listView == 'clip' : ui.itemView == 'clips',
that = Ox.IconList({
fixedRatio: fixedRatio,
item: function(data, sort, size) {
size = size || 128; // fixme: is this needed?
var ratio, width, height,
format, info, sortKey, url;
2011-09-30 10:33:45 +00:00
if (!ui.item) {
ratio = data.videoRatio;
width = ratio > fixedRatio ? size : Math.round(size * ratio / fixedRatio);
height = Math.round(width / ratio);
} else {
width = fixedRatio > 1 ? size : Math.round(size * fixedRatio);
height = fixedRatio > 1 ? Math.round(size / fixedRatio) : size;
}
2011-10-19 15:59:33 +00:00
title = data.subtitles[0].value; //fixme: could be other layer
url = '/' + data.id.split('/')[0] + '/' + height + 'p' + data['in'] + '.jpg';
sortKey = sort[0].key;
if (['text', 'position', 'duration'].indexOf(sortKey) > -1) {
2011-10-10 07:32:50 +00:00
info = Ox.formatDuration(data['in']) + ' - '
+ Ox.formatDuration(data.out);
} else {
format = pandora.getSortKeyData(sortKey).format;
2011-10-26 14:52:23 +00:00
if (format) {
info = (
/^color/.test(format.type.toLowerCase()) ? Ox.Theme : Ox
)['format' + Ox.toTitleCase(format.type)].apply(
this, Ox.merge([data[sortKey]], format.args || [])
);
} else {
info = data[sortKey];
}
}
2011-09-30 10:33:45 +00:00
return {
height: height,
id: data.id,
info: info,
2011-10-02 18:16:28 +00:00
title: title,
2011-09-30 10:33:45 +00:00
url: url,
width: width
};
},
2011-10-01 13:51:18 +00:00
items: function(data, callback) {
if (!isClipView) {
// fixme: this will have to be updated
callback({data: {items: []}});
return;
}
2011-10-19 16:20:12 +00:00
var itemsQuery, query;
2011-09-30 10:33:45 +00:00
if (!ui.item) {
2011-10-19 16:20:12 +00:00
itemsQuery = ui.find;
2011-09-30 10:33:45 +00:00
query = {conditions: [], operator: '&'};
// if the item query contains a layer condition,
// then this condition is added to the clip query
2011-10-19 16:20:12 +00:00
itemsQuery.conditions.forEach(function(condition) {
if (Ox.getPositionById(pandora.site.layers, condition.key) > -1) {
query.conditions.push(condition);
2011-09-30 10:33:45 +00:00
}
});
} else {
2011-10-19 16:20:12 +00:00
itemsQuery = {
2011-09-30 10:33:45 +00:00
conditions:[{key: 'id', value: ui.item, operator: '=='}],
operator: '&'
};
2011-10-30 16:00:21 +00:00
query = pandora.user.ui.itemFind;
2011-09-30 10:33:45 +00:00
}
2011-10-02 18:16:28 +00:00
pandora.api.findClips(Ox.extend({
2011-10-19 16:20:12 +00:00
itemsQuery: itemsQuery,
2011-09-30 10:33:45 +00:00
query: query
}, data), callback);
2011-10-01 13:51:18 +00:00
},
2011-09-30 10:33:45 +00:00
keys: Ox.merge(
2011-10-02 18:16:28 +00:00
['id', 'in', 'out', 'subtitles'], //fixme: could be other layer
2011-09-30 10:33:45 +00:00
!ui.item ? ['videoRatio'] : []
),
max: 1,
orientation: 'both',
size: 128,
sort: !ui.item ? ui.listSort : ui.itemSort,
unique: 'id'
})
.bindEvent({
init: function(data) {
// fixme: status needs an overhaul
if (!ui.item) {
pandora.$ui.total.html(pandora.ui.status('total', data));
}
},
open: function(data) {
var id = data.ids[0],
item = !ui.item ? id.split('/')[0] : ui.item,
points = {
'in': that.value(id, 'in'),
out: that.value(id, 'out')
},
set = {
item: item,
itemView: pandora.user.ui.videoView
};
set['videoPoints.' + item] = Ox.extend(points, {
position: points['in']
});
pandora.UI.set(set);
},
openpreview: function(data) {
// on press space key
var $video = that.find('.OxItem.OxSelected > .OxIcon > .OxVideoPlayer');
if ($video) {
// trigger singleclick
$video.trigger('mousedown');
Ox.UI.$window.trigger('mouseup');
}
that.closePreview();
},
select: function(data) {
if (data.ids.length) {
var id = data.ids[0],
item = id.split('/')[0], width, height,
$img = that.find('.OxItem.OxSelected > .OxIcon > img'),
$video = that.find('.OxItem.OxSelected > .OxIcon > .OxVideoPlayer'),
size = 128, ratio, width, height;
if ($img.length) {
if (!ui.item) {
ratio = that.value(id, 'videoRatio');
width = ratio > fixedRatio ? size : Math.round(size * ratio / fixedRatio);
height = Math.round(width / ratio);
} else {
width = fixedRatio > 1 ? size : Math.round(size * fixedRatio);
height = fixedRatio > 1 ? Math.round(size / fixedRatio) : size;
}
2011-10-25 13:59:27 +00:00
pandora.api.get({id: item, keys: ['durations', 'rightslevel']}, function(result) {
2011-09-30 10:33:45 +00:00
var points = [that.value(id, 'in'), that.value(id, 'out')],
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]}]
: [],
2011-09-30 10:33:45 +00:00
height: height,
'in': partsAndPoints.points[0],
out: partsAndPoints.points[1],
paused: true,
playInToOut: true,
poster: '/' + item + '/' + height + 'p' + points[0] + '.jpg',
2011-10-03 10:58:47 +00:00
rewind: true,
2011-09-30 10:33:45 +00:00
video: partsAndPoints.parts.map(function(i) {
2011-10-29 15:28:33 +00:00
var part = (i + 1),
prefix = pandora.site.site.videoprefix.replace('PART', part);
return prefix + '/' + item + '/96p' + part + '.' + pandora.user.videoFormat;
2011-10-19 10:47:33 +00:00
}),
width: width
2011-09-30 10:33:45 +00:00
})
.addClass('OxTarget')
.bindEvent({
// doubleclick opens item
singleclick: function() {
$player.$element.is('.OxSelectedVideo') && $player.togglePaused();
2011-09-30 10:33:45 +00:00
}
});
$img.replaceWith($player.$element);
$('.OxSelectedVideo').removeClass('OxSelectedVideo');
$player.$element.addClass('OxSelectedVideo');
});
} else if ($video.length) {
// item select fires before video click
// so we have to make sure that selecting
// an item that already has a video
// doesn't click through to play
///*
2011-09-30 10:33:45 +00:00
setTimeout(function() {
$('.OxSelectedVideo').removeClass('OxSelectedVideo');
$video.addClass('OxSelectedVideo');
}, 300);
//*/
2011-09-30 10:33:45 +00:00
}
!ui.item && pandora.UI.set('listSelection', [item]);
} else {
$('.OxSelectedVideo').removeClass('OxSelectedVideo');
!ui.item && pandora.UI.set('listSelection', []);
}
},
pandora_itemsort: function(data) {
2011-10-29 17:46:46 +00:00
that.options({sort: data.value});
},
pandora_listsort: function(data) {
that.options({sort: data.value});
2011-09-30 10:33:45 +00:00
}
});
return that;
2011-10-02 18:16:28 +00:00
}