* <div class="mozilla-video-control">
* <video ... />
* </div>
*
*
* @param jQuery|String container
*/
Mozilla.VideoControl = function(container)
{
if (typeof container == 'String') {
container = $('#' + container);
}
this.container = container;
// Retrieve jQuery object and the corresponding DOM element
this.video = container.find('video:first');
this._video = this.video[0];
this.semaphore = false;
/*
* Check if HTMLMediaElement exists to filter out browsers that do not
* support the video element.
*/
if ( typeof HTMLMediaElement != 'undefined'
&& this._video instanceof HTMLMediaElement
) {
this.drawControl();
this._video._control = this;
}
}
Mozilla.VideoControl.controls = [];
Mozilla.VideoControl.prototype.drawControl = function()
{
var buttonTag = '' +
' ';
this.control = $(buttonTag);
// Show the click-to-play button. In the future, this may be changed
// to show the click-to-play button based on media events like the
// hiding is done.
if (this._video.paused || this._video.ended) {
this.show();
}
var that = this;
// hide click-to-play button on these events
this.video.bind('play playing seeking waiting', function(event) {
that.hide();
});
this.control.mouseover(function(event) {
if (!that.semaphore) {
that.prelight();
}
});
this.control.mouseout(function(event) {
if (!that.semaphore) {
that.unprelight();
}
});
this.control.click(function(event) {
event.preventDefault();
if (that.semaphore || !that.videoCanPlay()) {
return;
}
that.semaphore = true;
// rewind the video
if (that._video.ended) {
that._video.currentTime = 0;
}
that._video.play();
});
this.container.append(this.control);
}
Mozilla.VideoControl.prototype.videoCanPlay = function()
{
// check if we're using an older draft version of the readyState spec
var current_data = (typeof HTMLMediaElement.CAN_PLAY == 'undefined') ?
HTMLMediaElement.HAVE_CURRENT_DATA : HTMLMediaElement.CAN_PLAY;
return (this._video.readyState >= current_data);
}
Mozilla.VideoControl.prototype.show = function()
{
var that = this;
this._video.controls = false;
// FIXME : Does not work on http://mozilla.local/en-US/firefox/video/
// this.control.show();
this.control.css('display', 'block');
this.control.stop(true).fadeTo('slow', 0.7, function() {
that.semaphore = false;
});
}
Mozilla.VideoControl.prototype.hide = function()
{
var that = this;
if (this.control.is(':visible')) {
this.semaphore = true;
this.control.stop(true).fadeTo('fast', 0, function() {
$(this).hide();
that._video.controls = true;
});
}
}
Mozilla.VideoControl.prototype.prelight = function()
{
if (this.control.is(':visible')) {
this.control.stop(true).fadeTo('fast', 1);
}
}
Mozilla.VideoControl.prototype.unprelight = function()
{
if (this.control.is(':visible')) {
this.control.stop(true).fadeTo('fast', 0.7);
}
}
// }}}
// {{{ Mozilla.VideoPlayer
/**
* Popup player using HTML5 video element with flash fallback
*
* @param String id
* @param Array sources
* @param String flv_url
* @param Booelan autoplay
*/
Mozilla.VideoPlayer = function(id, sources, flv_url, autoplay, extra_content)
{
this.id = id;
this.flv_url = flv_url;
this.sources = sources;
this.opened = false;
if (arguments.length > 3) {
this.autoplay = autoplay;
} else {
this.autoplay = true;
}
if (arguments.length > 4) {
this.extra_content = extra_content;
} else {
this.extra_content = '';
}
var that = this;
$(document).ready(function() {
that.init();
});
}
Mozilla.VideoPlayer.height = 385;
Mozilla.VideoPlayer.width = 640;
Mozilla.VideoPlayer.ie6 =
($.browser.msie && parseInt($.browser.version, 10) <= 6);
Mozilla.VideoPlayer.close_text = 'Close';
Mozilla.VideoPlayer.fallback_text =
'This video requires a browser with support for open video or the '
+ 'Adobe Flash '
+ 'Player. Alternatively, you may use the video download links '
+ 'provided.';
Mozilla.VideoPlayer.prototype.init = function()
{
var that = this;
// add overlay and preview image to document
this.overlay = $('')
.hide()
.appendTo('body')
.click(function(e) { e.preventDefault(); that.close(); });
this.video_container = $('')
.hide()
.appendTo('body');
// set video link and video preview link event handler
$('#' + this.id + ', #' + this.id + '-preview').click(function(e) {
e.preventDefault();
that.open();
});
}
Mozilla.VideoPlayer.prototype.clearVideoPlayer = function()
{
// remove event handlers
this.video_container.unbind('click');
// workaround for FF Bug #533840, manually pause all videos
this.video_container.find('video').each(function() {
$(this)[0].pause();
});
// remove all elements
this.video_container.empty();
}
Mozilla.VideoPlayer.prototype.drawVideoPlayer = function()
{
var that = this;
this.clearVideoPlayer();
// get content for player
if (typeof HTMLMediaElement != 'undefined') {
var content = this.getVideoPlayerContent();
} else if (Mozilla.VideoPlayer.flash_verison.isValid([7, 0, 0])) {
var content = this.getFlashPlayerContent();
} else {
var content = this.getFallbackContent();
}
// add download links
content += '