2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-10-20 12:59:36 +00:00
|
|
|
|
2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
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,
|
2011-10-20 13:04:04 +00:00
|
|
|
showSubtitles: false,
|
2012-01-04 17:27:32 +00:00
|
|
|
state: 'default',
|
2011-05-15 16:18:58 +00:00
|
|
|
subtitles: [],
|
|
|
|
width: 0
|
|
|
|
})
|
|
|
|
.options(options || {})
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxBlockVideoTimeline')
|
2011-05-15 16:18:58 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
})
|
|
|
|
.bind({
|
|
|
|
mousedown: mousedown,
|
|
|
|
mouseleave: mouseleave,
|
|
|
|
mousemove: mousemove
|
|
|
|
})
|
|
|
|
.bindEvent({
|
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({
|
2011-05-15 16:18:58 +00:00
|
|
|
animate: false
|
|
|
|
}).css({
|
|
|
|
textAlign: 'center'
|
|
|
|
});
|
|
|
|
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,
|
|
|
|
'in': self.options['in'],
|
|
|
|
out: self.options.out,
|
|
|
|
results: self.options.results,
|
|
|
|
subtitles: self.options.showSubtitles ? self.options.subtitles : [],
|
|
|
|
timeline: self.options.getImageURL,
|
|
|
|
width: Math.round(self.options.duration),
|
|
|
|
type: 'editor'
|
|
|
|
});
|
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',
|
|
|
|
left: (self.margin / 2) + 'px',
|
|
|
|
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',
|
|
|
|
marginLeft: (-i * self.options.width) + 'px'
|
|
|
|
})
|
|
|
|
.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',
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
return (e.offsetX ? e.offsetX : e.clientX - $(e.target).offset().left);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSubtitle(position) {
|
|
|
|
var subtitle = '';
|
|
|
|
Ox.forEach(self.options.subtitles, function(v) {
|
|
|
|
if (v['in'] <= position && v.out > position) {
|
|
|
|
subtitle = v;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return subtitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('Video', 'trigger............')
|
2011-05-15 16:18:58 +00:00
|
|
|
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({
|
|
|
|
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) :
|
2011-05-15 18:50:05 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
};
|