2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-17 08:58:03 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.LargeVideoTimeline <f> LargeTimeline Object
|
|
|
|
([options[, self]]) -> <o:Ox.Element> LargeTimeline Object
|
2011-05-17 08:58:03 +00:00
|
|
|
options <o> Options object
|
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
|
|
|
Ox.LargeVideoTimeline = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2011-05-17 08:58:03 +00:00
|
|
|
.defaults({
|
|
|
|
cuts: [],
|
|
|
|
duration: 0,
|
|
|
|
find: '',
|
|
|
|
getImageURL: null,
|
|
|
|
'in': 0,
|
|
|
|
matches: [],
|
|
|
|
out: 0,
|
|
|
|
position: 0,
|
|
|
|
subtitles: [],
|
2012-04-18 07:43:32 +00:00
|
|
|
type: '',
|
2011-05-17 08:58:03 +00:00
|
|
|
width: 0
|
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
|
|
|
find: setSubtitles,
|
|
|
|
'in': function() {
|
|
|
|
setPointMarker('in');
|
|
|
|
},
|
|
|
|
out: function() {
|
|
|
|
setPointMarker('out');
|
|
|
|
},
|
|
|
|
position: setPosition,
|
|
|
|
subtitles: setSubtitles,
|
|
|
|
width: setWidth
|
|
|
|
})
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxLargeVideoTimeline')
|
2011-05-17 08:58:03 +00:00
|
|
|
.mouseleave(mouseleave)
|
|
|
|
.mousemove(mousemove)
|
|
|
|
.bindEvent({
|
|
|
|
anyclick: click,
|
|
|
|
dragstart: dragstart,
|
|
|
|
drag: drag
|
|
|
|
});
|
|
|
|
|
2011-09-17 07:09:17 +00:00
|
|
|
Ox.extend(self, {
|
2011-05-17 08:58:03 +00:00
|
|
|
$cuts: [],
|
2011-05-18 18:30:58 +00:00
|
|
|
$pointMarker: {},
|
2011-05-17 08:58:03 +00:00
|
|
|
$tiles: {},
|
2011-06-19 17:48:32 +00:00
|
|
|
$tooltip: Ox.Tooltip({
|
2011-05-17 08:58:03 +00:00
|
|
|
animate: false
|
|
|
|
}),
|
|
|
|
center: parseInt(self.options.width / 2),
|
|
|
|
element: that.$element[0],
|
|
|
|
fps: 25,
|
|
|
|
height: 64,
|
|
|
|
tileWidth: 1500
|
|
|
|
});
|
|
|
|
self.tiles = self.options.duration * self.fps / self.tileWidth;
|
|
|
|
|
|
|
|
self.$timeline = $('<div>')
|
|
|
|
.css({
|
|
|
|
left: self.center + 'px'
|
|
|
|
})
|
|
|
|
.appendTo(that.$element)
|
|
|
|
|
|
|
|
setSubtitles();
|
|
|
|
|
|
|
|
self.options.cuts.forEach(function(v, i) {
|
|
|
|
self.$cuts[i] = $('<img>')
|
|
|
|
.addClass('OxCut')
|
|
|
|
.attr({
|
2011-09-02 00:32:23 +00:00
|
|
|
src: Ox.UI.getImageURL('markerCut')
|
2011-05-17 08:58:03 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
left: (v * self.fps) + 'px'
|
|
|
|
})
|
|
|
|
.appendTo(self.$timeline)
|
|
|
|
});
|
|
|
|
|
|
|
|
self.$markerPosition = $('<img>')
|
|
|
|
.addClass('OxMarkerPosition')
|
|
|
|
.attr({
|
2011-09-02 03:28:43 +00:00
|
|
|
src: Ox.UI.getImageURL('markerPosition')
|
2011-05-17 08:58:03 +00:00
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
|
|
|
setMarker();
|
|
|
|
|
|
|
|
['in', 'out'].forEach(function(point) {
|
|
|
|
var titlecase = Ox.toTitleCase(point);
|
2011-05-18 18:30:58 +00:00
|
|
|
self.$pointMarker[point] = $('<img>')
|
2011-05-17 08:58:03 +00:00
|
|
|
.addClass('OxMarkerPoint' + titlecase)
|
|
|
|
.attr({
|
2011-09-02 00:32:23 +00:00
|
|
|
src: Ox.UI.getImageURL('marker' + titlecase)
|
2011-05-17 08:58:03 +00:00
|
|
|
})
|
|
|
|
.appendTo(self.$timeline);
|
2011-05-18 18:30:58 +00:00
|
|
|
setPointMarker(point);
|
2011-05-17 08:58:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setWidth();
|
|
|
|
setPosition();
|
|
|
|
|
2011-09-17 11:49:29 +00:00
|
|
|
function click(data) {
|
2011-09-17 07:09:17 +00:00
|
|
|
self.options.position = Ox.round(Ox.limit(
|
2011-09-17 11:49:29 +00:00
|
|
|
getPosition(data), 0, self.options.duration
|
2011-09-17 07:09:17 +00:00
|
|
|
), 3);
|
2011-05-17 08:58:03 +00:00
|
|
|
setPosition();
|
|
|
|
triggerPositionEvent();
|
|
|
|
}
|
|
|
|
|
2011-09-17 11:49:29 +00:00
|
|
|
function dragstart(data) {
|
|
|
|
self.drag = {x: data.clientX};
|
2011-05-17 08:58:03 +00:00
|
|
|
}
|
|
|
|
|
2011-09-17 11:49:29 +00:00
|
|
|
function drag(data) {
|
2011-09-17 07:09:17 +00:00
|
|
|
self.options.position = Ox.round(Ox.limit(
|
2011-09-17 11:49:29 +00:00
|
|
|
self.options.position + (self.drag.x - data.clientX) / self.fps,
|
2011-05-17 08:58:03 +00:00
|
|
|
0, self.options.duration
|
2011-09-17 07:09:17 +00:00
|
|
|
), 3);
|
2011-09-17 11:49:29 +00:00
|
|
|
self.drag.x = data.clientX;
|
2011-05-17 08:58:03 +00:00
|
|
|
setPosition();
|
|
|
|
triggerPositionEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPosition(e) {
|
2011-06-19 17:48:32 +00:00
|
|
|
return self.options.position + (e.clientX - that.offset().left - self.center - 1) / self.fps;
|
2011-05-17 08:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mouseleave(e) {
|
|
|
|
self.clientX = 0;
|
|
|
|
self.clientY = 0;
|
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function mousemove(e) {
|
|
|
|
self.clientX = e.clientX;
|
|
|
|
self.clientY = e.clientY;
|
|
|
|
updateTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setMarker() {
|
|
|
|
self.$markerPosition.css({
|
2012-05-26 15:48:19 +00:00
|
|
|
left: self.center + 'px'
|
2011-05-17 08:58:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-18 18:30:58 +00:00
|
|
|
function setPointMarker(point) {
|
|
|
|
self.$pointMarker[point].css({
|
|
|
|
left: (self.options[point] * self.fps) + 'px'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-17 08:58:03 +00:00
|
|
|
function setPosition() {
|
|
|
|
self.tile = parseInt(self.options.position * self.fps / self.tileWidth);
|
|
|
|
self.$timeline.css({
|
|
|
|
marginLeft: (-self.options.position * self.fps) + 'px'
|
|
|
|
});
|
|
|
|
Ox.loop(
|
|
|
|
Math.max(self.tile - 1, 0),
|
|
|
|
Math.min(self.tile + 2, self.tiles),
|
|
|
|
function(i) {
|
|
|
|
if (!self.$tiles[i]) {
|
|
|
|
self.$tiles[i] = $('<img>')
|
|
|
|
.attr({
|
2012-04-18 07:43:32 +00:00
|
|
|
src: self.options.getImageURL(self.options.type, i)
|
2011-05-17 08:58:03 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
left: (i * self.tileWidth) + 'px'
|
|
|
|
})
|
|
|
|
.appendTo(self.$timeline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (self.clientX && self.clientY) {
|
|
|
|
updateTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSubtitles() {
|
2012-02-19 18:26:57 +00:00
|
|
|
that.find('.OxSubtitle').remove();
|
2011-05-17 08:58:03 +00:00
|
|
|
self.$subtitles = [];
|
|
|
|
self.options.subtitles.forEach(function(subtitle, i) {
|
2012-01-02 14:05:14 +00:00
|
|
|
var found = self.options.find
|
|
|
|
&& subtitle.text.toLowerCase().indexOf(self.options.find.toLowerCase()) > -1;
|
2011-05-17 08:58:03 +00:00
|
|
|
self.$subtitles[i] = $('<div>')
|
2011-05-19 18:34:53 +00:00
|
|
|
.addClass('OxSubtitle' + (found ? ' OxHighlight' : ''))
|
2011-05-17 08:58:03 +00:00
|
|
|
.css({
|
|
|
|
left: (subtitle['in'] * self.fps) + 'px',
|
|
|
|
width: (((subtitle.out - subtitle['in']) * self.fps) - 2) + 'px'
|
|
|
|
})
|
|
|
|
.html(Ox.highlight(subtitle.text, self.options.find, 'OxHighlight'))
|
2011-06-19 17:48:32 +00:00
|
|
|
.appendTo(self.$timeline);
|
2011-05-17 08:58:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setWidth() {
|
|
|
|
self.center = parseInt(self.options.width / 2);
|
|
|
|
that.css({
|
|
|
|
width: self.options.width + 'px'
|
|
|
|
});
|
|
|
|
self.$timeline.css({
|
|
|
|
left: self.center + 'px'
|
|
|
|
});
|
|
|
|
setMarker();
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerPositionEvent() {
|
|
|
|
that.triggerEvent('position', {
|
|
|
|
position: self.options.position
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateTooltip() {
|
|
|
|
var position = getPosition(self);
|
|
|
|
if (position >= 0 && position <= self.options.duration) {
|
|
|
|
self.$tooltip
|
|
|
|
.options({
|
|
|
|
title: Ox.formatDuration(position, 3)
|
|
|
|
})
|
|
|
|
.show(self.clientX, self.clientY);
|
|
|
|
} else {
|
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|