2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-16 08:24:46 +00:00
|
|
|
|
|
|
|
/*@
|
|
|
|
Ox.SmallTimeline <f:Ox.Element> SmallTimeline Object
|
|
|
|
() -> <f> SmallTimeline Object
|
|
|
|
(options) -> <f> SmallTimeline Object
|
|
|
|
(options, self) -> <f> SmallTimeline Object
|
|
|
|
options <o> Options object
|
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.SmallTimeline = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
|
|
|
duration: 0,
|
|
|
|
find: '',
|
|
|
|
matches: [],
|
|
|
|
points: [0, 0],
|
|
|
|
position: 0,
|
|
|
|
subtitles: [],
|
|
|
|
videoId: '',
|
|
|
|
width: 0
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
.addClass('OxTimelineSmall')
|
|
|
|
.mousedown(mousedown)
|
|
|
|
.mouseleave(mouseleave)
|
|
|
|
.mousemove(mousemove)
|
|
|
|
.bindEvent({
|
2011-09-17 11:49:29 +00:00
|
|
|
drag: function(data) {
|
|
|
|
mousedown(data);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-17 18:36:09 +00:00
|
|
|
Ox.extend(self, {
|
2011-04-22 22:03:10 +00:00
|
|
|
$images: [],
|
|
|
|
$markerPoint: [],
|
|
|
|
$subtitles: [],
|
2011-06-19 17:48:32 +00:00
|
|
|
$tooltip: Ox.Tooltip({
|
2011-04-22 22:03:10 +00:00
|
|
|
animate: false
|
|
|
|
}).css({
|
|
|
|
textAlign: 'center'
|
|
|
|
}),
|
|
|
|
hasSubtitles: self.options.subtitles.length,
|
|
|
|
height: 16,
|
|
|
|
margin: 8
|
|
|
|
});
|
|
|
|
|
|
|
|
that.css({
|
|
|
|
width: (self.options.width + self.margin) + 'px',
|
|
|
|
height: (self.height + self.margin) + 'px'
|
|
|
|
});
|
|
|
|
|
|
|
|
self.$line = $('<img>')
|
|
|
|
.addClass('OxTimelineSmallImage')
|
|
|
|
.attr({
|
2011-08-06 18:20:24 +00:00
|
|
|
src: '/' + self.options.videoId + '/timeline16p.png'
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: '4px',
|
|
|
|
top: '4px',
|
|
|
|
width: self.options.width,
|
|
|
|
height: '16px'
|
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
|
|
|
|
|
|
|
self.$markerPosition = $('<img>')
|
|
|
|
.addClass('OxMarkerPosition')
|
|
|
|
.attr({
|
2011-04-27 19:49:18 +00:00
|
|
|
src: Ox.UI.PATH + 'png/videoMarkerPlay.png'
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
width: '9px',
|
|
|
|
height: '5px',
|
|
|
|
zIndex: 10
|
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
|
|
|
|
|
|
|
setPosition();
|
|
|
|
|
|
|
|
['in', 'out'].forEach(function(v, i) {
|
|
|
|
var titleCase = Ox.toTitleCase(v);
|
|
|
|
self.$markerPoint[i] = $('<img>')
|
|
|
|
.addClass('OxMarkerPoint' + titleCase)
|
|
|
|
.attr({
|
2011-04-27 19:49:18 +00:00
|
|
|
src: Ox.UI.PATH + 'png/videoMarker' + titleCase + '.png'
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
|
|
|
setMarkerPoint(i);
|
|
|
|
});
|
|
|
|
|
|
|
|
function getPosition(e) {
|
|
|
|
return e.offsetX / self.options.width * self.options.duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSubtitle(position) {
|
|
|
|
var subtitle = null;
|
|
|
|
Ox.forEach(self.options.subtitles, function(v) {
|
|
|
|
if (v['in'] <= position && v['out'] >= position) {
|
|
|
|
subtitle = v;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return subtitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mousedown(e) {
|
|
|
|
var $target = $(e.target);
|
|
|
|
if (
|
|
|
|
$target.hasClass('OxTimelineSmallImage') ||
|
|
|
|
$target.hasClass('OxTimelineSmallSubtitles')
|
|
|
|
) {
|
|
|
|
self.options.position = getPosition(e);
|
|
|
|
setPosition();
|
|
|
|
that.triggerEvent('change', {
|
|
|
|
position: self.options.position
|
|
|
|
});
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseleave(e) {
|
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function mousemove(e) {
|
|
|
|
var $target = $(e.target),
|
|
|
|
position,
|
|
|
|
subtitle;
|
|
|
|
if (
|
|
|
|
$target.hasClass('OxTimelineSmallImage') ||
|
|
|
|
$target.hasClass('OxTimelineSmallSubtitles')
|
|
|
|
) {
|
2011-06-19 17:48:32 +00:00
|
|
|
position = getPosition(e);
|
2011-04-22 22:03:10 +00:00
|
|
|
subtitle = getSubtitle(position);
|
|
|
|
self.$tooltip.options({
|
|
|
|
title: subtitle ?
|
|
|
|
'<span class=\'OxBright\'>' +
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.highlight(subtitle.value, self.options.find, 'OxHighlight').replace(/\n/g, '<br/>') +
|
|
|
|
'</span><br/>' +
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
|
|
|
Ox.formatDuration(position, 3)
|
|
|
|
})
|
|
|
|
.show(e.clientX, e.clientY);
|
|
|
|
} else {
|
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setMarker() {
|
|
|
|
self.$markerPosition
|
|
|
|
.css({
|
|
|
|
left: parseInt(
|
|
|
|
self.options.position / self.options.duration * self.options.width
|
|
|
|
) + 'px',
|
|
|
|
top: '2px',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setMarkerPoint(i) {
|
|
|
|
var position = self.options.points[i];
|
|
|
|
self.$markerPoint[i]
|
|
|
|
.css({
|
|
|
|
left: (position % self.options.width) + 'px',
|
|
|
|
top: (parseInt(position / self.options.width) * (self.height + self.margin) + 16) + 'px',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPosition() {
|
|
|
|
self.options.position = Ox.limit(self.options.position, 0, self.options.duration);
|
|
|
|
setMarker();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setWidth() {
|
|
|
|
self.$line.css({
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
});
|
|
|
|
setMarker();
|
|
|
|
setMarkerPoint(0);
|
|
|
|
setMarkerPoint(1);
|
|
|
|
}
|
|
|
|
|
2011-04-29 12:40:51 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('Video', 'onChange:', key, value)
|
2011-04-22 22:03:10 +00:00
|
|
|
if (key == 'points') {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('Video', 'key', key, 'value', value)
|
2011-04-22 22:03:10 +00:00
|
|
|
setMarkerPoint(0);
|
|
|
|
setMarkerPoint(1);
|
|
|
|
} else if (key == 'position') {
|
|
|
|
setPosition();
|
|
|
|
} else if (key == 'width') {
|
|
|
|
setWidth();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|