pandora/static/js/pandora.embed.js

133 lines
4.9 KiB
JavaScript
Raw Normal View History

2011-01-04 06:03:00 +00:00
/***
Pandora embed
***/
2011-06-19 12:51:36 +00:00
Ox.load('UI', {
debug: true,
hideScreen: false,
loadImages: true,
showScreen: true,
theme: 'modern'
}, function() {
window.pandora = new Ox.App({url: '/api/'}).bindEvent({
2011-01-04 06:03:00 +00:00
apiURL: '/api/',
2011-06-19 12:51:36 +00:00
}).bindEvent('load', function(data) {
$.extend(pandora, {
ui: {},
2011-02-08 12:07:05 +00:00
info: function(item) {
2011-06-19 12:51:36 +00:00
var that = Ox.Element()
2011-02-08 12:07:05 +00:00
.append(
2011-06-19 12:51:36 +00:00
ui.infoTimeline = Ox.Element('<img>')
2011-02-08 12:07:05 +00:00
.css({
position: 'absolute',
left: 0,
bottom: 0,
height: '16px',
})
2011-08-06 18:20:04 +00:00
.attr('src', '/' + item + '/timeline16p.png')
2011-02-08 12:07:05 +00:00
)
.append(
ui.infoStill = new app.flipbook(item)
.css({
position: 'absolute',
left: 0,
width: '100%',
height: $(document).height()-16 + 'px',
})
)
return that;
},
2011-06-19 12:51:36 +00:00
clip: function(item, inPoint, outPoint) {
Ox.print('!@#!@#!@#', inPoint, outPoint);
var that = Ox.Element();
pandora.api.getItem(item, function(result) {
var video = result.data.stream,
format = $.support.video.supportedFormat(video.formats);
video.height = video.profiles[0];
video.width = parseInt(video.height * video.aspectRatio / 2) * 2;
video.url = video.baseUrl + '/' + video.height + 'p.' + format;
that.append(pandora.player = Ox.VideoPlayer({
controlsBottom: ['playInToOut', 'space', 'position'],
enableFind: false,
enableFullscreen: true,
enableVolume: true,
externalControls: false,
height: 192,
paused: true,
showMarkers: true,
showMilliseconds: 2,
width: 360,
'in': inPoint,
out: outPoint,
position: inPoint,
2011-08-06 18:20:04 +00:00
poster: '/' + item + '/' + '128p' + inPoint +'.jpg',
2011-06-19 12:51:36 +00:00
title: result.data.title,
video: video.url
})
.bindEvent({
position: function(data) {
if(data.position<inPoint || data.position>outPoint) {
if(!pandora.player.options('paused'))
pandora.player.togglePaused();
pandora.player.options({
position: inPoint,
});
}
}
})
);
Ox.UI.hideLoadingScreen();
});
return that;
},
2011-02-08 12:07:05 +00:00
flipbook: function(item) {
2011-06-19 12:51:36 +00:00
var that = Ox.Flipbook({
2011-09-17 17:40:15 +00:00
}).bindEvent('click', function(data) {
2011-02-08 12:07:05 +00:00
var item_url = document.location.origin + '/' + item;
window.top.location.href = item_url + '/timeline#t=' + data.position;
});
pandora.api.getItem(item, function(result) {
var duration = result.data.item.duration,
posterFrame = result.data.item.posterFrame || parseInt(duration/2),
steps = 24,
2011-08-06 18:20:04 +00:00
framePrefix = '/' + item + '/' + that.height() + 'p',
2011-02-08 12:07:05 +00:00
frames = {};
Ox.range(0, duration, duration/steps).forEach(function(position) {
position = parseInt(position);
frames[position] = framePrefix + position + '.jpg';
});
that.options({
frames: frames,
icon: framePrefix + posterFrame + '.jpg',
duration: duration
});
});
return that;
}
2011-06-19 12:51:36 +00:00
});
2011-02-08 12:07:05 +00:00
var item = document.location.pathname.split('/')[1];
2011-06-19 12:51:36 +00:00
function getArgument(key, result) {
var args = Ox.map(document.location.hash.substr(1).split('&'), function(a) {
a = a.split('=');
var key = a[0],
value = a[1];
return {
'key': key,
'value': value
}
});
$.each(args, function(i, a) {
Ox.print(i, a);
if (a.key == key) {
result = a.value;
return false;
}
});
return result;
}
var t = getArgument('t', '0,10').split(',')
pandora.ui.info = pandora.clip(item, parseInt(t[0]), parseInt(t[1]))
.appendTo(document.body);
2011-05-28 11:18:24 +00:00
});
2011-01-04 06:03:00 +00:00
});