2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-01-10 14:49:28 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.SmallVideoTimeline <f> Small video timeline
|
2012-07-04 11:29:18 +00:00
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
2012-05-31 10:32:54 +00:00
|
|
|
([options[, self]]) -> <o:Ox.Element> Small video timeline
|
2012-06-17 22:38:26 +00:00
|
|
|
position <!> position
|
2012-01-10 14:49:28 +00:00
|
|
|
@*/
|
2011-05-15 16:18:58 +00:00
|
|
|
Ox.SmallVideoTimeline = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
2012-01-10 14:49:28 +00:00
|
|
|
// _offset is a hack for cases where all these position: absolute
|
|
|
|
// elements have to go into a float: left
|
2013-02-15 05:19:33 +00:00
|
|
|
// FIXME: possibly unused and unneeded
|
2012-01-10 14:49:28 +00:00
|
|
|
_offset: 0,
|
2011-12-19 21:13:11 +00:00
|
|
|
disabled: false,
|
2011-05-15 16:18:58 +00:00
|
|
|
duration: 0,
|
2011-05-17 18:04:26 +00:00
|
|
|
find: '',
|
2012-04-18 07:43:32 +00:00
|
|
|
imageURL: '',
|
2011-05-15 16:18:58 +00:00
|
|
|
'in': 0,
|
2013-02-12 06:28:52 +00:00
|
|
|
invertHighlight: false,
|
2012-04-18 07:43:32 +00:00
|
|
|
mode: 'player',
|
2011-05-15 16:18:58 +00:00
|
|
|
out: 0,
|
2011-05-15 18:50:05 +00:00
|
|
|
paused: false,
|
2011-12-28 21:22:51 +00:00
|
|
|
results: [],
|
2013-02-15 05:19:33 +00:00
|
|
|
showInToOut: false,
|
2011-05-15 18:50:05 +00:00
|
|
|
showMilliseconds: 0,
|
2012-01-09 20:25:38 +00:00
|
|
|
state: 'default',
|
2012-02-19 18:26:57 +00:00
|
|
|
subtitles: [],
|
2011-05-15 18:50:05 +00:00
|
|
|
width: 256
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
|
|
|
duration: function() {
|
|
|
|
self.$image.options({duration: self.options.duration});
|
|
|
|
},
|
|
|
|
'in': function() {
|
|
|
|
self.$image.options({'in': self.options['in']});
|
|
|
|
self.options.mode == 'editor' && setPointMarker('in');
|
|
|
|
},
|
|
|
|
out: function() {
|
|
|
|
self.$image.options({out: self.options.out});
|
|
|
|
self.options.mode == 'editor' && setPointMarker('out');
|
|
|
|
},
|
|
|
|
paused: function() {
|
|
|
|
self.$positionMarker[
|
|
|
|
self.options.paused ? 'addClass' : 'removeClass'
|
|
|
|
]('OxPaused');
|
|
|
|
},
|
|
|
|
position: function() {
|
|
|
|
setPositionMarker();
|
|
|
|
},
|
|
|
|
results: function() {
|
|
|
|
self.$image.options({results: self.options.results});
|
|
|
|
},
|
|
|
|
state: function() {
|
|
|
|
self.$image.options({state: self.options.state});
|
|
|
|
},
|
|
|
|
subtitles: function() {
|
|
|
|
self.$image.options({subtitles: self.options.subtitles});
|
|
|
|
},
|
|
|
|
width: function() {
|
|
|
|
setWidth();
|
|
|
|
}
|
|
|
|
})
|
2011-05-15 16:18:58 +00:00
|
|
|
.addClass('OxSmallVideoTimeline')
|
2011-05-15 18:50:05 +00:00
|
|
|
.css(Ox.extend({
|
2011-05-15 16:18:58 +00:00
|
|
|
width: self.options.width + 'px'
|
2012-04-18 07:43:32 +00:00
|
|
|
}, self.options.mode == 'player' ? {
|
2011-05-15 18:50:05 +00:00
|
|
|
background: 'rgb(0, 0, 0)',
|
|
|
|
borderRadius: '8px'
|
|
|
|
} : {}));
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2012-04-18 07:43:32 +00:00
|
|
|
self.height = self.options.mode == 'player' ? 16 : 24;
|
|
|
|
self.imageLeft = self.options.mode == 'player' ? 8 : 4;
|
2011-05-15 18:50:05 +00:00
|
|
|
self.imageWidth = self.options.width -
|
2012-04-18 07:43:32 +00:00
|
|
|
(self.options.mode == 'player' ? 16 : 8)
|
|
|
|
self.imageHeight = self.options.mode == 'player' ? 16 : 18;
|
|
|
|
self.interfaceLeft = self.options.mode == 'player' ? 0 : 4;
|
|
|
|
self.interfaceTop = self.options.mode == 'player' ? 0 : 2;
|
|
|
|
self.interfaceWidth = self.options.mode == 'player' ? self.options.width : self.imageWidth;
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
that.css({
|
|
|
|
height: self.height + 'px'
|
|
|
|
});
|
|
|
|
|
2011-05-16 07:03:37 +00:00
|
|
|
self.$image = getTimelineImage().appendTo(that);
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2011-05-17 18:44:53 +00:00
|
|
|
self.$interface = Ox.Element({
|
|
|
|
tooltip: getTooltip
|
|
|
|
})
|
2011-05-15 18:50:05 +00:00
|
|
|
.addClass('OxInterface')
|
|
|
|
.css({
|
|
|
|
left: self.interfaceLeft + 'px',
|
|
|
|
top: self.interfaceTop + 'px',
|
|
|
|
width: self.interfaceWidth + 'px',
|
2012-05-26 15:48:19 +00:00
|
|
|
height: '20px'
|
2011-05-15 18:50:05 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
2011-09-17 11:49:29 +00:00
|
|
|
drag: function(data) {
|
|
|
|
mousedown(data);
|
2011-05-17 18:01:40 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
dragend: function(data) {
|
2011-05-17 18:01:40 +00:00
|
|
|
self.triggered = false;
|
2011-09-17 11:49:29 +00:00
|
|
|
mousedown(data);
|
2012-01-10 14:49:28 +00:00
|
|
|
},
|
|
|
|
mousedown: mousedown
|
2011-05-15 18:50:05 +00:00
|
|
|
})
|
|
|
|
.appendTo(that);
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2011-05-17 18:44:53 +00:00
|
|
|
self.$interface.$tooltip.css({
|
|
|
|
textAlign: 'center'
|
|
|
|
});
|
|
|
|
|
2012-04-18 07:43:32 +00:00
|
|
|
if (self.options.mode == 'player') {
|
2011-05-15 18:50:05 +00:00
|
|
|
self.$positionMarker = $('<div>')
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxMarkerPlay' + (self.options.paused ? ' OxPaused' : ''))
|
|
|
|
.append($('<div>').append($('<div>')))
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 18:50:05 +00:00
|
|
|
} else {
|
|
|
|
self.$positionMarker = $('<img>')
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxMarkerPosition')
|
2011-05-15 16:18:58 +00:00
|
|
|
.attr({
|
2011-09-02 03:28:43 +00:00
|
|
|
src: Ox.UI.getImageURL('markerPosition')
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 18:50:05 +00:00
|
|
|
}
|
|
|
|
setPositionMarker();
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2012-04-18 07:43:32 +00:00
|
|
|
if (self.options.mode == 'editor') {
|
2011-05-15 18:50:05 +00:00
|
|
|
self.$pointMarker = {};
|
|
|
|
['in', 'out'].forEach(function(point) {
|
2011-09-02 00:32:23 +00:00
|
|
|
var titlecase = Ox.toTitleCase(point);
|
2011-05-15 18:50:05 +00:00
|
|
|
self.$pointMarker[point] = $('<img>')
|
2011-09-02 03:28:43 +00:00
|
|
|
.addClass('OxMarkerPoint' + titlecase)
|
2011-05-15 18:50:05 +00:00
|
|
|
.attr({
|
2011-09-02 00:32:23 +00:00
|
|
|
src: Ox.UI.getImageURL('marker' + titlecase)
|
2011-05-15 18:50:05 +00:00
|
|
|
})
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 18:50:05 +00:00
|
|
|
setPointMarker(point);
|
|
|
|
});
|
|
|
|
}
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2013-02-15 05:19:33 +00:00
|
|
|
function getLeft() {
|
|
|
|
return (
|
|
|
|
self.options.showInToOut
|
|
|
|
? self.options.position - self.options['in']
|
|
|
|
: self.options.position
|
|
|
|
) * self.imageWidth / self.options.duration;
|
|
|
|
}
|
|
|
|
|
2011-05-15 18:50:05 +00:00
|
|
|
function getPosition(e) {
|
2011-11-03 15:42:41 +00:00
|
|
|
var position = (
|
2012-01-17 17:56:26 +00:00
|
|
|
(e.offsetX ? e.offsetX : e.clientX - $(e.target).offset().left)
|
2012-04-18 07:43:32 +00:00
|
|
|
- (self.options.mode == 'player' ? 8 : 0)
|
2011-05-15 18:50:05 +00:00
|
|
|
) * self.options.duration / self.imageWidth;
|
2013-02-15 05:19:33 +00:00
|
|
|
position = Ox.limit(position, 0, self.options.duration);
|
|
|
|
if (self.options.showInToOut) {
|
|
|
|
position += self.options['in'];
|
|
|
|
}
|
|
|
|
return position;
|
2011-05-15 18:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSubtitle(position) {
|
|
|
|
var subtitle = '';
|
|
|
|
Ox.forEach(self.options.subtitles, function(v) {
|
|
|
|
if (v['in'] <= position && v.out > position) {
|
|
|
|
subtitle = v;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-05-15 18:50:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return subtitle;
|
|
|
|
}
|
|
|
|
|
2011-05-16 07:03:37 +00:00
|
|
|
function getTimelineImage() {
|
2013-07-13 13:58:10 +00:00
|
|
|
return (self.options.imageURL ? Ox.SmallVideoTimelineImage({
|
2011-05-16 07:03:37 +00:00
|
|
|
duration: self.options.duration,
|
2012-04-18 07:43:32 +00:00
|
|
|
imageURL: self.options.imageURL,
|
2011-05-16 07:03:37 +00:00
|
|
|
'in': self.options['in'],
|
2013-02-12 07:03:43 +00:00
|
|
|
invertHighlight: self.options.invertHighlight,
|
2012-04-18 07:43:32 +00:00
|
|
|
mode: self.options.mode,
|
2011-05-16 07:03:37 +00:00
|
|
|
out: self.options.out,
|
|
|
|
results: self.options.results,
|
2013-02-15 05:19:33 +00:00
|
|
|
showInToOut: self.options.showInToOut,
|
2011-05-16 07:03:37 +00:00
|
|
|
subtitles: self.options.subtitles,
|
2012-01-09 20:25:38 +00:00
|
|
|
state: self.options.state,
|
2012-04-18 07:43:32 +00:00
|
|
|
type: self.options.type,
|
|
|
|
width: self.imageWidth
|
2013-07-13 13:58:10 +00:00
|
|
|
}) : Ox.Element()).css({
|
2011-05-16 07:03:37 +00:00
|
|
|
position: 'absolute',
|
|
|
|
left: self.imageLeft + 'px',
|
|
|
|
width: self.imageWidth + 'px'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-17 18:44:53 +00:00
|
|
|
function getTooltip(e) {
|
|
|
|
var position = getPosition(e),
|
|
|
|
subtitle = getSubtitle(position);
|
2012-01-17 17:56:26 +00:00
|
|
|
return subtitle
|
|
|
|
? '<span class=\'OxBright\'>' + Ox.highlight(
|
|
|
|
subtitle.text, self.options.find, 'OxHighlight'
|
2012-06-03 08:41:18 +00:00
|
|
|
).replace(/\n/g, '<br/>') + '</span><br/>' + Ox.formatDuration(
|
2012-01-17 17:56:26 +00:00
|
|
|
subtitle['in'], self.options.showMilliseconds
|
|
|
|
) + ' - ' + Ox.formatDuration(
|
|
|
|
subtitle['out'], self.options.showMilliseconds
|
|
|
|
)
|
|
|
|
: Ox.formatDuration(position, self.options.showMilliseconds);
|
2011-05-17 18:44:53 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 18:50:05 +00:00
|
|
|
function mousedown(e) {
|
2011-12-19 21:13:11 +00:00
|
|
|
if (!self.options.disabled && $(e.target).is('.OxInterface')) {
|
2011-05-15 18:50:05 +00:00
|
|
|
self.options.position = getPosition(e);
|
|
|
|
setPositionMarker();
|
|
|
|
if (!self.triggered) {
|
|
|
|
that.triggerEvent('position', {
|
|
|
|
position: self.options.position
|
|
|
|
});
|
|
|
|
self.triggered = true;
|
|
|
|
setTimeout(function() {
|
|
|
|
self.triggered = false;
|
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPointMarker(point) {
|
|
|
|
self.$pointMarker[point].css({
|
2013-02-15 05:19:33 +00:00
|
|
|
left: self.imageLeft + Math.round(getLeft()) + 'px'
|
2011-05-15 18:50:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPositionMarker() {
|
|
|
|
self.$positionMarker.css({
|
2013-02-15 05:19:33 +00:00
|
|
|
left: self.interfaceLeft + Math.round(getLeft())
|
|
|
|
- (self.options.mode == 'editor' ? 5 : 0)
|
|
|
|
+ self.options._offset + 'px'
|
2011-05-15 18:50:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setWidth() {
|
2011-05-16 07:03:37 +00:00
|
|
|
self.imageWidth = self.options.width -
|
2012-04-18 07:43:32 +00:00
|
|
|
(self.options.mode == 'player' ? 16 : 8);
|
|
|
|
self.interfaceWidth = self.options.mode == 'player' ?
|
2011-05-16 11:29:26 +00:00
|
|
|
self.options.width : self.imageWidth;
|
2011-05-15 18:50:05 +00:00
|
|
|
that.css({
|
|
|
|
width: self.options.width + 'px'
|
|
|
|
});
|
2011-05-16 07:03:37 +00:00
|
|
|
self.$image.options({
|
|
|
|
width: self.imageWidth
|
|
|
|
}).css({
|
2011-05-15 18:50:05 +00:00
|
|
|
width: self.imageWidth + 'px'
|
|
|
|
});
|
|
|
|
self.$interface.css({
|
|
|
|
width: self.interfaceWidth + 'px'
|
|
|
|
});
|
|
|
|
setPositionMarker();
|
2012-04-18 07:43:32 +00:00
|
|
|
if (self.options.mode == 'editor') {
|
2011-05-15 18:50:05 +00:00
|
|
|
setPointMarker('in');
|
|
|
|
setPointMarker('out');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
return that;
|
|
|
|
|
2011-12-28 21:22:51 +00:00
|
|
|
};
|