unify goToNext methods, add keyboard shortcuts for previous/next chapter

This commit is contained in:
rlx 2013-07-18 12:54:14 +00:00
parent c4d2bb7a3d
commit 86b741f552

View file

@ -286,13 +286,16 @@ Ox.VideoPlayer = function(options, self) {
that.bindEvent({ that.bindEvent({
key_0: toggleMuted, key_0: toggleMuted,
key_1: toggleScale, key_1: toggleScale,
key_down: function() {
goToNext('chapter', 1);
},
key_equal: function() { key_equal: function() {
changeVolume(0.1); changeVolume(0.1);
}, },
key_escape: hideControlMenus, key_escape: hideControlMenus,
key_f: focusFind, key_f: focusFind,
key_g: function() { key_g: function() {
goToNextResult(1); goToNext('result', 1);
}, },
key_left: function() { key_left: function() {
setPosition(self.options.position - self.secondsPerFrame); setPosition(self.options.position - self.secondsPerFrame);
@ -310,7 +313,7 @@ Ox.VideoPlayer = function(options, self) {
self.options.enableFullscreen && toggleFullscreen(); self.options.enableFullscreen && toggleFullscreen();
}, },
key_shift_g: function() { key_shift_g: function() {
goToNextResult(-1); goToNext('result', -1);
}, },
key_shift_left: function() { key_shift_left: function() {
setPosition(self.options.position - 1); setPosition(self.options.position - 1);
@ -318,7 +321,10 @@ Ox.VideoPlayer = function(options, self) {
key_shift_right: function() { key_shift_right: function() {
setPosition(self.options.position + 1); setPosition(self.options.position + 1);
}, },
key_space: togglePaused key_space: togglePaused,
key_up: function() {
goToNext('chapter', -1);
}
}); });
if (self.options.focus == 'mouseenter') { if (self.options.focus == 'mouseenter') {
that.on({ that.on({
@ -715,7 +721,7 @@ Ox.VideoPlayer = function(options, self) {
} else if (control == 'next') { } else if (control == 'next') {
self.$nextClipButton = Ox.Button({ self.$nextChapterButton = Ox.Button({
style: 'video', style: 'video',
title: 'arrowRight', title: 'arrowRight',
tooltip: Ox._('Next'), tooltip: Ox._('Next'),
@ -723,7 +729,7 @@ Ox.VideoPlayer = function(options, self) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
goToNextChapter(1); goToNext('chapter', 1);
} }
}) })
.appendTo(self['$controls' + titleCase]); .appendTo(self['$controls' + titleCase]);
@ -838,7 +844,7 @@ Ox.VideoPlayer = function(options, self) {
} else if (control == 'previous') { } else if (control == 'previous') {
self.$previousClipButton = Ox.Button({ self.$previousChapterButton = Ox.Button({
style: 'video', style: 'video',
title: 'arrowLeft', title: 'arrowLeft',
tooltip: Ox._('Previous'), tooltip: Ox._('Previous'),
@ -846,7 +852,7 @@ Ox.VideoPlayer = function(options, self) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
goToNextChapter(-1); goToNext('chapter', -1);
} }
}) })
.appendTo(self['$controls' + titleCase]); .appendTo(self['$controls' + titleCase]);
@ -1050,7 +1056,7 @@ Ox.VideoPlayer = function(options, self) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
goToNextResult(-1); goToNext('result', -1);
} }
}) })
.appendTo(self.$find); .appendTo(self.$find);
@ -1064,7 +1070,7 @@ Ox.VideoPlayer = function(options, self) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
goToNextResult(1); goToNext('result', 1);
} }
}) })
.appendTo(self.$find); .appendTo(self.$find);
@ -1685,63 +1691,25 @@ Ox.VideoPlayer = function(options, self) {
return symbol; return symbol;
} }
function goToNextChapter(direction) { function goToNext(type, direction) {
var next, // type can be 'chapter' or 'result'
points = self.options.chapters.map(function(chapter) { var position, positions;
if (type == 'chapter') {
positions = self.options.chapters.map(function(chapter) {
return chapter.position; return chapter.position;
}).concat([self.options.duration]); });
if (direction == 1) { } else if (type == 'result') {
next = points.filter(function(point) { positions = Ox.unique(self.results.map(function(result) {
return point > self.options.position; return result['in'];
})[0]; }));
} else {
next = points.filter(function(point) {
return point < self.options.position;
}).slice(-1)[0];
} }
if (Ox.isUndefined(next)) { position = Ox.nextValue(positions, self.options.position, direction);
next = direction == 1 ? self.options.duration : 0; setPosition(position);
if (self.options.loop && next == 0) {
next = points.slice(-2)[0];
}
}
if (self.options.loop && next == self.options.duration) {
next = 0;
}
setPosition(next);
that.triggerEvent('position', { that.triggerEvent('position', {
position: self.options.position position: self.options.position
}); });
} }
function goToNextResult(direction) {
var found = false,
result;
if (self.results.length) {
direction == -1 && self.results.reverse();
Ox.forEach(self.results, function(v) {
if (
direction == 1
? v['in'] > self.options.position
: v.out < self.options.position
) {
result = v
found = true;
return false; // break
}
});
direction == -1 && self.results.reverse();
if (!found) {
result = self.results[direction == 1 ? 0 : self.results.length - 1];
}
setPosition(result['in'] + self.secondsPerFrame);
that.triggerEvent('position', {
position: self.options.position
});
result.id && that.triggerEvent('select', result);
}
}
function goToPoint() { function goToPoint() {
that.triggerEvent('gotopoint'); that.triggerEvent('gotopoint');
} }
@ -2391,7 +2359,7 @@ Ox.VideoPlayer = function(options, self) {
}); });
if (hasPressedEnter) { if (hasPressedEnter) {
if (self.results.length) { if (self.results.length) {
goToNextResult(1); goToNext('result', 1);
that.gainFocus(); that.gainFocus();
} else { } else {
self.$findInput.focusInput(true); self.$findInput.focusInput(true);