Convert et2_video widget to TS

This commit is contained in:
Hadi Nategh 2020-01-21 16:14:45 +01:00
parent 61a5505ec3
commit fb94b13a89
2 changed files with 325 additions and 149 deletions

View File

@ -1,3 +1,4 @@
"use strict";
/** /**
* EGroupware eTemplate2 - JS Description object * EGroupware eTemplate2 - JS Description object
* *
@ -9,13 +10,28 @@
* @copyright Stylite AG * @copyright Stylite AG
* @version $Id$ * @version $Id$
*/ */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
/*egw:uses /*egw:uses
/vendor/bower-asset/jquery/dist/jquery.js; /vendor/bower-asset/jquery/dist/jquery.js;
et2_core_interfaces; et2_core_interfaces;
et2_core_baseWidget; et2_core_baseWidget;
*/ */
var et2_core_baseWidget_1 = require("./et2_core_baseWidget");
var et2_core_inheritance_1 = require("./et2_core_inheritance");
var et2_core_DOMWidget_1 = require("./et2_core_DOMWidget");
/** /**
* This widget represents the HTML5 video tag with all its optional attributes * This widget represents the HTML5 video tag with all its optional attributes
* *
@ -38,152 +54,124 @@
* <video [attributes...]/> * <video [attributes...]/>
* </code> * </code>
*/ */
/** /**
* Class which implements the "video" XET-Tag * Class which implements the "video" XET-Tag
* *
* @augments et2_baseWidget * @augments et2_baseWidget
*/ */
var et2_video = (function(){ "use strict"; return et2_baseWidget.extend(et2_IDOMNode, var et2_video = /** @class */ (function (_super) {
{ __extends(et2_video, _super);
attributes: { function et2_video(_parent, _attrs, _child) {
"video_src": { var _this = _super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_core_DOMWidget_1.et2_DOMWidget._attributes, _child || {})) || this;
"name": "Video", _this.video = null;
"type": "string", //Create Video tag
"description": "Source of video to display" _this.video = jQuery(document.createElement("video"));
}, if (_this.options.controls) {
"src_type": { _this.video.attr("controls", 1);
"name": "Source type", }
"type": "string", if (_this.options.autoplay) {
"description": "Defines the type the stream source provided" _this.video.attr("autoplay", 1);
}, }
"muted": { if (_this.options.muted) {
"name": "Audio control", _this.video.attr("muted", 1);
"type": "boolean", }
"default": false, if (_this.options.video_src) {
"description": "Defines that the audio output of the video should be muted" _this.set_src(_this.options.video_src);
}, }
"autoplay": { if (_this.options.loop) {
"name": "Autoply", _this.video.attr("loop", 1);
"type": "boolean", }
"default": false, _this.setDOMNode(_this.video[0]);
"description": "Defines if Video will start playing as soon as it is ready" return _this;
}, }
"controls": { /**
"name": "Control buttons", * Set video src
"type": "boolean", *
"default": false, * @param {string} _value url
"description": "Defines if Video controls, play/pause buttons should be displayed" */
}, et2_video.prototype.set_src = function (_value) {
"poster": { if (_value) {
"name": "Video Poster", var source = jQuery(document.createElement('source'))
"type": "string", .attr('src', _value)
"default": "", .appendTo(this.video);
"description": "Specifies an image to be shown while video is loading or before user play it" if (this.options.src_type) {
}, source.attr('type', this.options.src_type);
loop: { }
"name": "Video loop", }
"type": "boolean", };
"default": false, /**
"description": "Defines if the video should be played repeatedly" * Set autoplay option for video
} * -If autoplay is set, video would be played automatically after the page is loaded
}, *
* @param {string} _value true set the autoplay and false not to set
*/
/** et2_video.prototype.set_autoplay = function (_value) {
* Constructor if (_value) {
* this.video.attr("autoplay", _value);
* @memberOf et2_video }
*/ };
init: function() { /**
this._super.apply(this, arguments); * Set controls option for video
*
//Create Video tag * @param {string} _value true set the autoplay and false not to set
this.video = jQuery(document.createElement("video")); */
if (this.options.controls) et2_video.prototype.set_controls = function (_value) {
{ if (_value) {
this.video.attr("controls",true); this.video.attr("controls", _value);
} }
if (this.options.autoplay) };
{ /**
this.video.attr("autoplay",true); * Set poster attribute in order to specify
} * an image to be shown while video is loading or before user play it
if (this.options.muted) *
{ * @param {string} _url
this.video.attr("muted",true); */
} et2_video.prototype.set_poster = function (_url) {
if (this.options.video_src) if (_url) {
{ this.video.attr("poster", _url);
this.set_src(this.options.video_src); }
} };
if (this.options.loop) et2_video._attributes = {
{ "video_src": {
this.video.attr("loop",true); "name": "Video",
} "type": "string",
this.setDOMNode(this.video[0]); "description": "Source of video to display"
}, },
"src_type": {
/** "name": "Source type",
* Set video src "type": "string",
* "description": "Defines the type the stream source provided"
* @param {string} _value url },
*/ "muted": {
set_src: function(_value) { "name": "Audio control",
"type": "boolean",
if (_value) "default": false,
{ "description": "Defines that the audio output of the video should be muted"
var source = jQuery(document.createElement('source')) },
.attr('src',_value) "autoplay": {
.appendTo(this.video); "name": "Autoply",
"type": "boolean",
if (this.options.src_type) "default": false,
{ "description": "Defines if Video will start playing as soon as it is ready"
source.attr('type',this.options.src_type); },
} "controls": {
} "name": "Control buttons",
}, "type": "boolean",
"default": false,
/** "description": "Defines if Video controls, play/pause buttons should be displayed"
* Set autoplay option for video },
* -If autoplay is set, video would be played automatically after the page is loaded "poster": {
* "name": "Video Poster",
* @param {string} _value true set the autoplay and false not to set "type": "string",
*/ "default": "",
set_autoplay: function (_value) "description": "Specifies an image to be shown while video is loading or before user play it"
{ },
if (_value) "loop": {
{ "name": "Video loop",
this.video.attr("autoplay",_value); "type": "boolean",
} "default": false,
}, "description": "Defines if the video should be played repeatedly"
}
/** };
* Set controls option for video return et2_video;
* }(et2_core_baseWidget_1.et2_baseWidget));
* @param {string} _value true set the autoplay and false not to set
*/
set_controls: function (_value)
{
if (_value)
{
this.video.attr("controls",_value);
}
},
/**
* Set poster attribute in order to specify
* an image to be shown while video is loading or before user play it
*
* @param {type} _url
*/
set_poster: function (_url)
{
if (_url)
{
this.video.attr("poster", _url);
}
}
});}).call(this);
et2_register_widget(et2_video, ["video"]);

View File

@ -0,0 +1,188 @@
/**
* 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
* @version $Id$
*/
/*egw:uses
/vendor/bower-asset/jquery/dist/jquery.js;
et2_core_interfaces;
et2_core_baseWidget;
*/
import { et2_baseWidget } from './et2_core_baseWidget'
import {ClassWithAttributes} from "./et2_core_inheritance";
import {et2_DOMWidget} from "./et2_core_DOMWidget";
import {WidgetConfig} from "./et2_core_widget";
/**
* This widget represents the HTML5 video tag with all its optional attributes
*
* 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
*/
class et2_video extends et2_baseWidget implements et2_IDOMNode
{
static readonly _attributes: any = {
"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"
}
};
video: JQuery = null;
constructor(_parent, _attrs? : WidgetConfig, _child? : object)
{
super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_DOMWidget._attributes, _child || {}));
//Create Video tag
this.video = jQuery(document.createElement("video"));
if (this.options.controls)
{
this.video.attr("controls", 1);
}
if (this.options.autoplay)
{
this.video.attr("autoplay", 1);
}
if (this.options.muted)
{
this.video.attr("muted", 1);
}
if (this.options.video_src)
{
this.set_src(this.options.video_src);
}
if (this.options.loop)
{
this.video.attr("loop", 1);
}
this.setDOMNode(this.video[0]);
}
/**
* Set video src
*
* @param {string} _value url
*/
set_src(_value: string) {
if (_value)
{
let source = jQuery(document.createElement('source'))
.attr('src',_value)
.appendTo(this.video);
if (this.options.src_type)
{
source.attr('type', this.options.src_type);
}
}
}
/**
* Set autoplay option for video
* -If autoplay is set, video would be played automatically after the page is loaded
*
* @param {string} _value true set the autoplay and false not to set
*/
set_autoplay(_value: string)
{
if (_value)
{
this.video.attr("autoplay", _value);
}
}
/**
* Set controls option for video
*
* @param {string} _value true set the autoplay and false not to set
*/
set_controls(_value: string)
{
if (_value)
{
this.video.attr("controls", _value);
}
}
/**
* Set poster attribute in order to specify
* an image to be shown while video is loading or before user play it
*
* @param {string} _url
*/
set_poster(_url: string)
{
if (_url)
{
this.video.attr("poster", _url);
}
}
}