core-cde
Version:
90 lines • 2.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideoWidget = void 0;
const BaseWidget_1 = require("../BaseWidget");
const Errors_1 = require("../Errors");
/**
* Video widget
*/
class VideoWidget extends BaseWidget_1.BaseWidget {
constructor(type, id) {
super(type, id);
this.width = 560;
this.height = 315;
this.maxHeight = 405;
this.maxWidth = 720;
}
get idVideo() {
if (!this._idVideo) {
return null;
}
return `https://www.youtube.com/embed/${this._idVideo}`;
}
set idVideo(value) {
this._idVideo = value;
}
get value() {
return this._value || null;
}
set value(value) {
const params = new URLSearchParams(value.split('?')[1]);
const id = params.get('v');
this.idVideo = id;
this._value = value;
}
get width() {
return this._width;
}
set width(value) {
this._width = value;
}
get height() {
return this._height;
}
set height(value) {
this._height = value;
}
get maxWidth() {
return this._maxWidth;
}
set maxWidth(value) {
this._maxWidth = value;
}
get maxHeight() {
return this._maxHeight;
}
set maxHeight(value) {
this._maxHeight = value;
}
/**
* Получить объект класса VideoWidget из json
* @param json валидная json строка
* @returns объект класса VideoWidget
*/
static fromJSON(json) {
try {
return Object.assign(new VideoWidget(null, null), JSON.parse(json));
}
catch (error) {
throw new Errors_1.JsonParseError('VideoWidget widget');
}
}
/**
* Получить объект для сериализации
* @returns Объект для сериализации
*/
toJSON() {
return Object.assign({}, null, {
id: this.id,
type: this.type,
_height: this._height,
_width: this._width,
_idVideo: this._idVideo,
_maxHeight: this._maxHeight,
_maxWidth: this._maxWidth,
_value: this._value,
});
}
}
exports.VideoWidget = VideoWidget;
//# sourceMappingURL=Video.js.map