VideoPlayer: add timelineType and timelineTypes options, update settings menu

This commit is contained in:
rolux 2013-02-21 01:29:49 +05:30
parent 235b47c1d1
commit 35d2aecc4a

View file

@ -71,6 +71,8 @@ Ox.VideoPlayer <f> Generic Video Player
out <n> Out point (sec) out <n> Out point (sec)
text <s> Text text <s> Text
timeline <s> Timeline image URL timeline <s> Timeline image URL
timelineType <s|''> Current timeline type id
timelineTypes <[o]|[]> Array of timeline type objects (id and title)
title <s|''> Video title title <s|''> Video title
type <s|'play'> 'play', 'in' or 'out' type <s|'play'> 'play', 'in' or 'out'
video <s|[s]|o|''> Video URL video <s|[s]|o|''> Video URL
@ -99,6 +101,7 @@ Ox.VideoPlayer <f> Generic Video Player
setpoint <!> setpoint setpoint <!> setpoint
size <!> size size <!> size
subtitles <!> subtitles subtitles <!> subtitles
timeline <!> timeline
volume <!> volume volume <!> volume
zap <!> zap zap <!> zap
@*/ @*/
@ -162,6 +165,8 @@ Ox.VideoPlayer = function(options, self) {
sizeIsLarge: false, sizeIsLarge: false,
subtitles: [], subtitles: [],
timeline: '', timeline: '',
timelineType: '',
timelineTypes: [],
title: '', title: '',
type: 'play', type: 'play',
video: '', video: '',
@ -1721,6 +1726,10 @@ Ox.VideoPlayer = function(options, self) {
return Math.abs(a - b) < 0.001; return Math.abs(a - b) < 0.001;
} }
function isResolution(str) {
return str.slice(0, -1).match(/^\d+$/) && str.slice(-1) == 'p';
}
function loadImage() { function loadImage() {
self.$image self.$image
.one({ .one({
@ -1874,7 +1883,7 @@ Ox.VideoPlayer = function(options, self) {
.addClass('OxControls OxSettings') .addClass('OxControls OxSettings')
.on({ .on({
click: function(e) { click: function(e) {
var $target = $(e.target), resolution, title; var $target = $(e.target), resolution, title, type;
self.$settings.hide(); self.$settings.hide();
if (!$target.is('.OxLine') && !$target.is('.OxSpace')) { if (!$target.is('.OxLine') && !$target.is('.OxSpace')) {
title = $(e.target).parent().children()[0].innerHTML; title = $(e.target).parent().children()[0].innerHTML;
@ -1882,12 +1891,22 @@ Ox.VideoPlayer = function(options, self) {
that.triggerEvent('download'); that.triggerEvent('download');
} else if (title == 'Subtitles') { } else if (title == 'Subtitles') {
toggleSubtitles(); toggleSubtitles();
} else { } else if (isResolution(title)) {
resolution = parseInt(title, 10); resolution = parseInt(title, 10);
if (resolution != self.options.resolution) { if (resolution != self.options.resolution) {
self.options.resolution = resolution; self.options.resolution = resolution;
setResolution(); setResolution();
} }
} else {
type = self.options.timelineTypes[
Ox.indexOf(self.options.timelineTypes, function(type) {
return type.title == title;
})
].id;
if (type != self.options.timelineType) {
self.options.timelineType = type;
// setTimelineType()
}
} }
self.$settings.children('.OxItem').each(function() { self.$settings.children('.OxItem').each(function() {
var children = $(this).children(), var children = $(this).children(),
@ -1896,9 +1915,12 @@ Ox.VideoPlayer = function(options, self) {
title == 'Subtitles' title == 'Subtitles'
&& self.options.enableSubtitles && self.options.enableSubtitles
) || ( ) || (
Ox.last(title) == 'p' isResolution(title)
&& parseInt(title, 10) == self.options.resolution && parseInt(title, 10) == self.options.resolution
); ) || title == Ox.getObjectById(
self.options.timelineTypes,
self.options.timelineType
).title;
$(children[1]).attr({ $(children[1]).attr({
src: Ox.UI.getImageURL( src: Ox.UI.getImageURL(
'symbol' + (checked ? 'Check' : 'None') 'symbol' + (checked ? 'Check' : 'None')
@ -1908,12 +1930,15 @@ Ox.VideoPlayer = function(options, self) {
} }
} }
}), }),
items = [].concat( items = [{
disabled: true,
title: 'Resolution'
}].concat(
self.resolutions.map(function(resolution) { self.resolutions.map(function(resolution) {
return { return {
checked: resolution == self.options.resolution, checked: resolution == self.options.resolution,
title: resolution + 'p' title: resolution + 'p'
} };
}), }),
self.options.subtitles.length self.options.subtitles.length
? [{}, { ? [{}, {
@ -1921,6 +1946,19 @@ Ox.VideoPlayer = function(options, self) {
title: 'Subtitles' title: 'Subtitles'
}] }]
: [], : [],
self.options.timelineTypes
? [{}, {
disabled: true,
title: 'Timeline'
}] : [],
self.options.timelineTypes
? self.options.timelineTypes.map(function(type) {
return {
checked: type.id == self.options.timelineType,
title: type.title
};
})
: [],
self.options.enableDownload self.options.enableDownload
? [{}, {title: 'Download'}] ? [{}, {title: 'Download'}]
: [] : []
@ -1930,16 +1968,18 @@ Ox.VideoPlayer = function(options, self) {
var $item; var $item;
if (item.title) { if (item.title) {
$item = $('<div>') $item = $('<div>')
.addClass('OxItem') .addClass('OxItem' + (item.disabled ? ' OxDisabled' : ''))
.on({ .appendTo($settings);
if (!item.disabled) {
$item.on({
mouseenter: function() { mouseenter: function() {
$(this).addClass('OxSelected'); $(this).addClass('OxSelected');
}, },
mouseleave: function() { mouseleave: function() {
$(this).removeClass('OxSelected'); $(this).removeClass('OxSelected');
} }
}) });
.appendTo($settings); }
$('<div>').html(item.title).appendTo($item); $('<div>').html(item.title).appendTo($item);
$('<img>').attr({ $('<img>').attr({
src: Ox.UI.getImageURL( src: Ox.UI.getImageURL(
@ -2147,12 +2187,9 @@ Ox.VideoPlayer = function(options, self) {
); );
} }
function sizechange() { function setTimelineType() {
self.videoWidth = self.$video.videoWidth(); that.triggerEvent('timeline', {type: self.options.timelineType});
self.videoHeight = self.$video.videoHeight(); }
self.videoCSS = getVideoCSS();
self.$video.css(self.videoCSS);
};
function setVolume(volume) { function setVolume(volume) {
self.options.volume = volume; self.options.volume = volume;
@ -2230,6 +2267,13 @@ Ox.VideoPlayer = function(options, self) {
} }
} }
function sizechange() {
self.videoWidth = self.$video.videoWidth();
self.videoHeight = self.$video.videoHeight();
self.videoCSS = getVideoCSS();
self.$video.css(self.videoCSS);
};
function submitFindInput(value, hasPressedEnter) { function submitFindInput(value, hasPressedEnter) {
self.options.find = value; self.options.find = value;
self.results = find(self.options.find); self.results = find(self.options.find);