diff --git a/website_video_preview/static/src/js/website_video_preview.editor.js b/website_video_preview/static/src/js/website_video_preview.editor.js
index e00322830e..587c988578 100644
--- a/website_video_preview/static/src/js/website_video_preview.editor.js
+++ b/website_video_preview/static/src/js/website_video_preview.editor.js
@@ -1,12 +1,14 @@
-odoo.define('website_video_preview.editor', function(require) {
+odoo.define('website_video_preview.editor', function (require) {
"use strict";
var VideoDialog = require('web_editor.widget').VideoDialog;
/**
- * Adds the ability to show a preview of the video instead of loading the player.
+ * Adds the ability to show a preview of the video
+ * instead of loading the player.
*
- * To extend this with other providers you simply have to add a entry in video_preview e.g.::
+ * To extend this with other providers
+ * you simply have to add a entry in video_preview e.g.::
*
* this.video_preview.vim = {
* // The location of the image of the play button you want to show
@@ -21,29 +23,29 @@ odoo.define('website_video_preview.editor', function(require) {
video_review: null,
/**
- * @constructor
+ * @class
* @override
*/
- init: function() {
+ init: function () {
this._super.apply(this, arguments);
this.video_preview = {
'yt': {
- 'button': '/website_video_preview/static/src/img/yt_button.png',
+ "button": "/website_video_preview/" +
+ "static/src/img/yt_button.png",
'getVideoId': this._getYoutubeVideoId,
- 'getPreviewImage': this._getYoutubePreviewImage
- }
- }
+ 'getPreviewImage': this._getYoutubePreviewImage,
+ },
+ };
},
/**
* @override
*/
- save: function() {
+ save: function () {
var res = this._super.apply(this, arguments);
var videoId = this.$content.attr('data-video-id');
var type = this.$content.attr('data-video-type');
if (videoId && type in this.video_preview) {
- var meta = this.video_preview[type];
// Build preview
var $media = $(res);
@@ -63,9 +65,10 @@ odoo.define('website_video_preview.editor', function(require) {
* @private
* @returns {jQuery}
*/
- _createPlayButtonNode: function(type) {
+ _createPlayButtonNode: function (type) {
var meta = this.video_preview[type];
- var $play_button = $('');
+ var $play_button = $(
+ "", {"class": "play_button", "src": meta.button});
return $play_button;
},
@@ -77,7 +80,7 @@ odoo.define('website_video_preview.editor', function(require) {
* @private
* @returns {jQuery}
*/
- _createPreviewImageNode: function(type, id) {
+ _createPreviewImageNode: function (type, id) {
var meta = this.video_preview[type];
var $preview_img = $('');
$preview_img.attr('src', meta.getPreviewImage(id));
@@ -92,7 +95,7 @@ odoo.define('website_video_preview.editor', function(require) {
* @private
* @returns {String}
*/
- _getYoutubePreviewImage: function(id) {
+ _getYoutubePreviewImage: function (id) {
return 'https://img.youtube.com/vi/' + id + '/0.jpg';
},
@@ -103,8 +106,10 @@ odoo.define('website_video_preview.editor', function(require) {
* @private
* @returns {String} The video ID
*/
- _getYoutubeVideoId: function(url) {
- var regex = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
+ _getYoutubeVideoId: function (url) {
+ var regex = new RegExp(["^(?:(?:https?:)?//)?(?:www.)?",
+ "(?:youtu.be/|youtube.com/(?:embed/|v/|",
+ "watch?v=|watch?.+&v=))((w|-){11})(?:S+)?$"].join(""));
var matches = url.match(regex);
return matches[1];
},
@@ -112,7 +117,7 @@ odoo.define('website_video_preview.editor', function(require) {
/**
* @override
*/
- _createVideoNode: function(url, options) {
+ _createVideoNode: function (url, options) {
var res = this._super(url, options);
if (res.type in this.video_preview) {
@@ -121,6 +126,6 @@ odoo.define('website_video_preview.editor', function(require) {
res.$video.attr('data-video-id', meta.getVideoId(url));
}
return res;
- }
+ },
});
});
diff --git a/website_video_preview/static/src/js/website_video_preview.frontend.js b/website_video_preview/static/src/js/website_video_preview.frontend.js
index 37de1a3839..bdb50955b2 100644
--- a/website_video_preview/static/src/js/website_video_preview.frontend.js
+++ b/website_video_preview/static/src/js/website_video_preview.frontend.js
@@ -1,4 +1,4 @@
-odoo.define('website_video_preview.frontend', function(require) {
+odoo.define('website_video_preview.frontend', function (require) {
"use strict";
var registry = require('website.content.snippets.animation').registry;
@@ -9,42 +9,48 @@ odoo.define('website_video_preview.frontend', function(require) {
'click .play_button': '_onPlayButtonClick',
},
- start: function() {
- var src = this.$target.find('img.video_preview').attr('data-iframe-src');
+ start: function () {
+ var src = this.$target
+ .find('img.video_preview').attr('data-iframe-src');
if (!src) {
return this._super.apply(this, arguments);
}
if (this.editableMode) {
this.stopVideo();
- } else if(src.indexOf('autoplay=1') !== -1) {
- this.playVideo(this.$target.find('img.video_preview').attr('data-iframe-src'));
+ } else if (src.indexOf('autoplay=1') !== -1) {
+ this.playVideo(
+ this.$target
+ .find('img.video_preview').attr('data-iframe-src'));
}
},
- _onPlayButtonClick: function(e) {
+ _onPlayButtonClick: function (e) {
var $img = $(e.currentTarget);
- var src = $img.parent().find('[data-iframe-src]').attr('data-iframe-src');
+ var src = $img.parent()
+ .find('[data-iframe-src]').attr('data-iframe-src');
this.playVideo(src);
},
- _onPreviewClick: function(e) {
+ _onPreviewClick: function (e) {
var $img = $(e.currentTarget);
var src = $img.attr('data-iframe-src');
this.playVideo(src);
},
- playVideo: function(src) {
- var $iframe = $('');
+ playVideo: function (src) {
+ var $iframe = $(
+ "",
+ {"class": "o_video_dialog_iframe", "frameborder": 0});
$iframe.attr('src', src.replace('autoplay=0', 'autoplay=1'));
this.$target.append($iframe);
this.$target.find('img.video_preview').addClass('hidden');
this.$target.find('img.play_button').addClass('hidden');
},
- stopVideo: function() {
+ stopVideo: function () {
this.$target.find('iframe').remove();
this.$target.find('img.video_preview').removeClass('hidden');
this.$target.find('img.play_button').removeClass('hidden');
- }
+ },
});
});