2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-22 13:14:40 +00:00
|
|
|
Ox.BlockVideoTimeline <f:Ox.Element> Block Video Timeline
|
|
|
|
([options[, self]]) -> <o> Block Video Timeline
|
2012-05-21 10:38:18 +00:00
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
|
|
|
@*/
|
2011-05-15 16:18:58 +00:00
|
|
|
Ox.BlockVideoTimeline = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
2011-06-19 17:48:32 +00:00
|
|
|
var that = Ox.Element({}, self)
|
2011-05-15 16:18:58 +00:00
|
|
|
.defaults({
|
|
|
|
duration: 0,
|
|
|
|
find: '',
|
2011-05-18 16:00:29 +00:00
|
|
|
getImageURL: null,
|
2011-05-15 16:18:58 +00:00
|
|
|
'in': 0,
|
|
|
|
out: 0,
|
|
|
|
position: 0,
|
|
|
|
results: [],
|
2011-10-17 10:23:16 +00:00
|
|
|
showPointMarkers: false,
|
2012-01-04 17:27:32 +00:00
|
|
|
state: 'default',
|
2011-05-15 16:18:58 +00:00
|
|
|
subtitles: [],
|
2012-04-18 07:43:32 +00:00
|
|
|
type: '',
|
2011-05-15 16:18:58 +00:00
|
|
|
width: 0
|
|
|
|
})
|
|
|
|
.options(options || {})
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxBlockVideoTimeline')
|
2011-05-15 16:18:58 +00:00
|
|
|
.css({
|
2012-05-26 15:48:19 +00:00
|
|
|
position: 'absolute'
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
|
|
|
.bind({
|
|
|
|
mousedown: mousedown,
|
|
|
|
mouseleave: mouseleave,
|
|
|
|
mousemove: mousemove
|
|
|
|
})
|
|
|
|
.bindEvent({
|
2012-01-10 14:49:28 +00:00
|
|
|
doubleclick: doubleclick,
|
2011-09-17 11:49:29 +00:00
|
|
|
drag: function(data) {
|
|
|
|
mousedown(data);
|
2011-05-15 16:18:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
self.$images = [];
|
|
|
|
self.$interfaces = [];
|
|
|
|
self.$lines = [];
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$tooltip = Ox.Tooltip({
|
2012-03-14 10:35:46 +00:00
|
|
|
animate: false
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
textAlign: 'center'
|
|
|
|
});
|
2011-05-15 16:18:58 +00:00
|
|
|
self.height = 16;
|
|
|
|
self.lines = getLines();
|
|
|
|
self.margin = 8;
|
|
|
|
|
|
|
|
setCSS();
|
|
|
|
|
2011-05-16 07:03:37 +00:00
|
|
|
self.$image = Ox.SmallVideoTimelineImage({
|
2012-01-04 17:27:32 +00:00
|
|
|
duration: self.options.duration,
|
|
|
|
editing: self.options.editing,
|
2012-04-18 07:43:32 +00:00
|
|
|
imageURL: self.options.getImageURL,
|
2012-01-04 17:27:32 +00:00
|
|
|
'in': self.options['in'],
|
2012-04-18 07:43:32 +00:00
|
|
|
mode: 'editor',
|
2012-01-04 17:27:32 +00:00
|
|
|
out: self.options.out,
|
|
|
|
results: self.options.results,
|
2012-01-10 14:49:28 +00:00
|
|
|
state: self.options.state,
|
2012-02-19 18:26:57 +00:00
|
|
|
subtitles: self.options.subtitles,
|
2012-04-18 07:43:32 +00:00
|
|
|
type: self.options.type,
|
|
|
|
width: Math.round(self.options.duration)
|
2012-01-04 17:27:32 +00:00
|
|
|
});
|
2011-05-17 10:00:49 +00:00
|
|
|
|
|
|
|
Ox.loop(self.lines, function(i) {
|
|
|
|
addLine(i);
|
|
|
|
});
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
self.$positionMarker = $('<img>')
|
|
|
|
.attr({
|
2011-09-02 03:28:43 +00:00
|
|
|
src: Ox.UI.getImageURL('markerPosition')
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxMarkerPosition')
|
2011-05-15 16:18:58 +00:00
|
|
|
.appendTo(that.$element);
|
|
|
|
setPositionMarker();
|
|
|
|
|
2011-10-17 10:23:16 +00:00
|
|
|
if (self.options.showPointMarkers) {
|
|
|
|
self.$pointMarker = {};
|
|
|
|
['in', 'out'].forEach(function(point) {
|
|
|
|
var titlecase = Ox.toTitleCase(point);
|
|
|
|
self.$pointMarker[point] = $('<img>')
|
|
|
|
.addClass('OxMarkerPoint' + titlecase)
|
|
|
|
.attr({
|
|
|
|
src: Ox.UI.getImageURL('marker' + titlecase)
|
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
|
|
|
setPointMarker(point);
|
|
|
|
});
|
|
|
|
}
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
function addLine(i) {
|
|
|
|
self.$lines[i] = $('<div>')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2012-03-14 10:35:46 +00:00
|
|
|
left: self.margin / 2 + 'px',
|
2011-05-15 16:18:58 +00:00
|
|
|
top: i * (self.height + self.margin) + 'px',
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
height: '24px',
|
|
|
|
overflow: 'hidden'
|
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
2011-05-16 07:03:37 +00:00
|
|
|
self.$images[i] = self.$image.clone()
|
2011-05-15 16:18:58 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2012-03-14 10:35:46 +00:00
|
|
|
marginLeft: -i * self.options.width + 'px'
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
|
|
|
.appendTo(self.$lines[i]);
|
2011-05-15 18:50:05 +00:00
|
|
|
self.$interfaces[i] = $('<div>')
|
2011-10-17 10:23:16 +00:00
|
|
|
// OxTarget and OxSpecialTarget are needed for InfoList
|
|
|
|
.addClass('OxInterface OxTarget OxSpecialTarget')
|
2011-05-15 16:18:58 +00:00
|
|
|
.css({
|
|
|
|
top: '2px',
|
2011-05-18 18:30:58 +00:00
|
|
|
width: Math.round(self.options.duration) + 'px',
|
2011-05-15 16:18:58 +00:00
|
|
|
height: '20px',
|
2012-05-26 15:48:19 +00:00
|
|
|
marginLeft: -i * self.options.width + 'px'
|
2011-05-15 18:50:05 +00:00
|
|
|
//background: 'rgba(255, 0, 0, 0.1)',
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
|
|
|
.appendTo(self.$lines[i]);
|
|
|
|
}
|
|
|
|
|
2012-01-10 14:49:28 +00:00
|
|
|
function doubleclick(e) {
|
|
|
|
var position;
|
|
|
|
if ($(e.target).is('.OxInterface')) {
|
|
|
|
position = getPosition(e);
|
|
|
|
if (
|
|
|
|
self.options.state == 'selected'
|
|
|
|
&& position >= self.options['in']
|
|
|
|
&& position <= self.options.out
|
|
|
|
) {
|
|
|
|
that.triggerEvent('edit');
|
|
|
|
} else if (self.options.state != 'editing') {
|
|
|
|
that.triggerEvent('select');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
function getLines() {
|
|
|
|
return Math.ceil(self.options.duration / self.options.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPosition(e) {
|
|
|
|
//FIXME: this might still be broken in opera according to http://acko.net/blog/mouse-handling-and-absolute-positions-in-javascript
|
2012-03-14 10:35:46 +00:00
|
|
|
return e.offsetX ? e.offsetX
|
|
|
|
: e.clientX - $(e.target).offset().left;
|
2011-05-15 16:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSubtitle(position) {
|
|
|
|
var subtitle = '';
|
|
|
|
Ox.forEach(self.options.subtitles, function(v) {
|
|
|
|
if (v['in'] <= position && v.out > position) {
|
|
|
|
subtitle = v;
|
2012-05-25 07:46:34 +00:00
|
|
|
Ox.Break();
|
2011-05-15 16:18:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return subtitle;
|
|
|
|
}
|
|
|
|
|
2012-01-10 14:49:28 +00:00
|
|
|
function getTooltip(e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
function mousedown(e) {
|
|
|
|
if ($(e.target).is('.OxInterface')) {
|
|
|
|
self.options.position = getPosition(e);
|
|
|
|
setPositionMarker();
|
|
|
|
// fixme: check if this pattern is better
|
|
|
|
// than the one used for list selection
|
|
|
|
if (!self.triggered) {
|
|
|
|
that.triggerEvent('position', {
|
|
|
|
position: self.options.position
|
|
|
|
});
|
|
|
|
self.triggered = true;
|
|
|
|
setTimeout(function() {
|
|
|
|
self.triggered = false;
|
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseleave() {
|
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function mousemove(e) {
|
|
|
|
var position, subtitle;
|
|
|
|
if ($(e.target).is('.OxInterface')) {
|
|
|
|
position = getPosition(e);
|
|
|
|
subtitle = getSubtitle(position);
|
|
|
|
self.$tooltip.options({
|
2012-03-14 10:35:46 +00:00
|
|
|
title: subtitle
|
|
|
|
? '<span class=\'OxBright\'>' +
|
|
|
|
Ox.highlight(subtitle.text, self.options.find, 'OxHighlight').replace(/\n/g, '<br/>') +
|
|
|
|
'</span><br/>' +
|
|
|
|
Ox.formatDuration(subtitle['in'], 3) + ' - '
|
|
|
|
+ Ox.formatDuration(subtitle['out'], 3)
|
|
|
|
: Ox.formatDuration(position)
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
|
|
|
.show(e.clientX, e.clientY);
|
|
|
|
} else {
|
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCSS() {
|
|
|
|
that.css({
|
|
|
|
width: (self.options.width + self.margin) + 'px',
|
2011-05-18 16:00:29 +00:00
|
|
|
height: ((self.height + self.margin) * self.lines) + 4 + 'px'
|
|
|
|
// fixme: the + 4 represent the margin-bottom in the video editor
|
|
|
|
// is there a better way to get a proper margin-bottom?
|
2011-05-15 16:18:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-18 18:30:58 +00:00
|
|
|
function setPoint(point) {
|
|
|
|
setPointMarker(point);
|
|
|
|
self.$image.options(point, self.options[point]);
|
2011-05-19 17:58:00 +00:00
|
|
|
updateTimelines();
|
2011-05-18 18:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
function setPointMarker(point) {
|
|
|
|
var position = Math.round(self.options[point]);
|
|
|
|
self.$pointMarker[point].css({
|
|
|
|
left: (position % self.options.width) + 'px',
|
|
|
|
top: (parseInt(position / self.options.width) *
|
2011-09-02 03:28:43 +00:00
|
|
|
(self.height + self.margin) + 15) + 'px'
|
2011-05-15 16:18:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPositionMarker() {
|
2011-09-17 07:09:17 +00:00
|
|
|
var position = Math.round(self.options.position);
|
2011-05-15 16:18:58 +00:00
|
|
|
self.$positionMarker.css({
|
2011-09-17 07:09:17 +00:00
|
|
|
left: (position % self.options.width) - 1 + 'px',
|
|
|
|
top: (parseInt(position / self.options.width) *
|
2011-05-15 16:18:58 +00:00
|
|
|
(self.height + self.margin) + 2) + 'px'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-19 17:58:00 +00:00
|
|
|
function setResults() {
|
|
|
|
self.$image.options({results: self.options.results});
|
|
|
|
updateTimelines();
|
|
|
|
}
|
|
|
|
|
2012-01-04 17:27:32 +00:00
|
|
|
function setState() {
|
|
|
|
self.$image.options({state: self.options.state});
|
|
|
|
updateTimelines();
|
|
|
|
}
|
|
|
|
|
2012-02-19 18:26:57 +00:00
|
|
|
function setSubtitles() {
|
|
|
|
self.$image.options({subtitles: self.options.subtitles});
|
|
|
|
updateTimelines();
|
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
function setWidth() {
|
|
|
|
self.lines = getLines();
|
|
|
|
setCSS();
|
|
|
|
Ox.loop(self.lines, function(i) {
|
|
|
|
if (self.$lines[i]) {
|
|
|
|
self.$lines[i].css({
|
|
|
|
width: self.options.width + 'px'
|
|
|
|
});
|
|
|
|
self.$images[i].css({
|
|
|
|
marginLeft: (-i * self.options.width) + 'px'
|
|
|
|
});
|
|
|
|
self.$interfaces[i].css({
|
|
|
|
marginLeft: (-i * self.options.width) + 'px'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
addLine(i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
while (self.$lines.length > self.lines) {
|
|
|
|
self.$lines[self.$lines.length - 1].remove();
|
|
|
|
self.$lines.pop();
|
|
|
|
self.$images.pop();
|
|
|
|
}
|
|
|
|
setPositionMarker();
|
2011-10-17 10:23:16 +00:00
|
|
|
if (self.options.showPointMarkers) {
|
|
|
|
setPointMarker('in');
|
|
|
|
setPointMarker('out');
|
|
|
|
}
|
2011-05-15 16:18:58 +00:00
|
|
|
}
|
|
|
|
|
2011-05-19 17:58:00 +00:00
|
|
|
function updateTimelines() {
|
|
|
|
self.$lines.forEach(function($line, i) {
|
|
|
|
$($line.children()[0]).replaceWith(
|
|
|
|
self.$images[i] = self.$image.clone()
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
marginLeft: (-i * self.options.width) + 'px'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-05-18 18:30:58 +00:00
|
|
|
if (key == 'in' || key == 'out') {
|
2011-10-17 10:23:16 +00:00
|
|
|
self.options.showPointMarkers && setPoint(key);
|
2011-05-18 18:30:58 +00:00
|
|
|
} else if (key == 'position') {
|
2011-05-15 16:18:58 +00:00
|
|
|
setPositionMarker();
|
2011-05-19 17:58:00 +00:00
|
|
|
} else if (key == 'results') {
|
|
|
|
setResults();
|
2012-02-19 18:26:57 +00:00
|
|
|
} else if (key == 'subtitles') {
|
|
|
|
setSubtitles();
|
2012-01-04 17:27:32 +00:00
|
|
|
} else if (key == 'state') {
|
|
|
|
setState();
|
2011-05-15 16:18:58 +00:00
|
|
|
} else if (key == 'width') {
|
|
|
|
setWidth();
|
|
|
|
}
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
return that;
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|