2014-08-19 12:10:09 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - JS Description object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Hadi Nategh <hn[at]stylite.de>
|
|
|
|
* @copyright Stylite AG
|
2016-02-29 21:40:43 +01:00
|
|
|
* @version $Id$
|
2014-08-19 12:10:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
|
|
|
et2_core_interfaces;
|
|
|
|
et2_core_baseWidget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-02-29 21:40:43 +01:00
|
|
|
* This widget represents the HTML5 video tag with all its optional attributes
|
|
|
|
*
|
2014-08-19 12:10:09 +02:00
|
|
|
* The widget can be created in the following ways:
|
|
|
|
* <code>
|
|
|
|
* var videoTag = et2_createWidget("video", {
|
|
|
|
* video_src: "../../test.mp4",
|
|
|
|
* src_type: "video/mp4",
|
|
|
|
* muted: true,
|
|
|
|
* autoplay: true,
|
|
|
|
* controls: true,
|
|
|
|
* poster: "../../poster.jpg",
|
|
|
|
* loop: true,
|
|
|
|
* height: 100,
|
|
|
|
* width: 200,
|
|
|
|
* });
|
|
|
|
* </code>
|
|
|
|
* Or by adding XET-tag in your template (.xet) file:
|
|
|
|
* <code>
|
|
|
|
* <video [attributes...]/>
|
|
|
|
* </code>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "video" XET-Tag
|
|
|
|
*
|
|
|
|
* @augments et2_baseWidget
|
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_video = (function(){ "use strict"; return et2_baseWidget.extend(et2_IDOMNode,
|
2014-08-19 12:10:09 +02:00
|
|
|
{
|
|
|
|
attributes: {
|
|
|
|
"video_src": {
|
|
|
|
"name": "Video",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Source of video to display"
|
|
|
|
},
|
|
|
|
"src_type": {
|
|
|
|
"name": "Source type",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Defines the type the stream source provided"
|
|
|
|
},
|
|
|
|
"muted": {
|
|
|
|
"name": "Audio control",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "Defines that the audio output of the video should be muted"
|
|
|
|
},
|
|
|
|
"autoplay": {
|
|
|
|
"name": "Autoply",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "Defines if Video will start playing as soon as it is ready"
|
|
|
|
},
|
|
|
|
"controls": {
|
|
|
|
"name": "Control buttons",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "Defines if Video controls, play/pause buttons should be displayed"
|
|
|
|
},
|
|
|
|
"poster": {
|
|
|
|
"name": "Video Poster",
|
|
|
|
"type": "string",
|
|
|
|
"default": "",
|
|
|
|
"description": "Specifies an image to be shown while video is loading or before user play it"
|
|
|
|
},
|
|
|
|
loop: {
|
|
|
|
"name": "Video loop",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "Defines if the video should be played repeatedly"
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @memberOf et2_video
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
//Create Video tag
|
|
|
|
this.video = jQuery(document.createElement("video"));
|
|
|
|
if (this.options.controls)
|
|
|
|
{
|
|
|
|
this.video.attr("controls",true);
|
|
|
|
}
|
|
|
|
if (this.options.autoplay)
|
|
|
|
{
|
|
|
|
this.video.attr("autoplay",true);
|
|
|
|
}
|
|
|
|
if (this.options.muted)
|
|
|
|
{
|
|
|
|
this.video.attr("muted",true);
|
|
|
|
}
|
|
|
|
if (this.options.video_src)
|
|
|
|
{
|
|
|
|
this.set_src(this.options.video_src);
|
|
|
|
}
|
|
|
|
if (this.options.loop)
|
|
|
|
{
|
|
|
|
this.video.attr("loop",true);
|
|
|
|
}
|
|
|
|
this.setDOMNode(this.video[0]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set video src
|
|
|
|
*
|
|
|
|
* @param {string} _value url
|
|
|
|
*/
|
|
|
|
set_src: function(_value) {
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
if (_value)
|
|
|
|
{
|
|
|
|
var source = jQuery(document.createElement('source'))
|
|
|
|
.attr('src',_value)
|
|
|
|
.appendTo(this.video);
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
if (this.options.src_type)
|
|
|
|
{
|
|
|
|
source.attr('type',this.options.src_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
/**
|
|
|
|
* Set autoplay option for video
|
|
|
|
* -If autoplay is set, video would be played automatically after the page is loaded
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2014-08-19 12:10:09 +02:00
|
|
|
* @param {string} _value true set the autoplay and false not to set
|
|
|
|
*/
|
|
|
|
set_autoplay: function (_value)
|
|
|
|
{
|
|
|
|
if (_value)
|
|
|
|
{
|
|
|
|
this.video.attr("autoplay",_value);
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
/**
|
|
|
|
* Set controls option for video
|
|
|
|
*
|
|
|
|
* @param {string} _value true set the autoplay and false not to set
|
|
|
|
*/
|
|
|
|
set_controls: function (_value)
|
|
|
|
{
|
|
|
|
if (_value)
|
|
|
|
{
|
|
|
|
this.video.attr("controls",_value);
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-08-19 12:10:09 +02:00
|
|
|
/**
|
2016-02-29 21:40:43 +01:00
|
|
|
* Set poster attribute in order to specify
|
2014-08-19 12:10:09 +02:00
|
|
|
* an image to be shown while video is loading or before user play it
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2014-08-19 12:10:09 +02:00
|
|
|
* @param {type} _url
|
|
|
|
*/
|
|
|
|
set_poster: function (_url)
|
|
|
|
{
|
|
|
|
if (_url)
|
|
|
|
{
|
|
|
|
this.video.attr("poster", _url);
|
|
|
|
}
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
|
|
|
|
});}).call(this);
|
2014-08-19 12:10:09 +02:00
|
|
|
|
|
|
|
et2_register_widget(et2_video, ["video"]);
|