/
website_video_preview.frontend.js
56 lines (49 loc) · 1.92 KB
/
website_video_preview.frontend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
odoo.define('website_video_preview.frontend', function (require) {
"use strict";
var registry = require('website.content.snippets.animation').registry;
registry.mediaVideo.include({
events: {
'click [data-iframe-src]': '_onPreviewClick',
'click .play_button': '_onPlayButtonClick',
},
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'));
}
},
_onPlayButtonClick: function (e) {
var $img = $(e.currentTarget);
var src = $img.parent()
.find('[data-iframe-src]').attr('data-iframe-src');
this.playVideo(src);
},
_onPreviewClick: function (e) {
var $img = $(e.currentTarget);
var src = $img.attr('data-iframe-src');
this.playVideo(src);
},
playVideo: function (src) {
var $iframe = $(
"<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 () {
this.$target.find('iframe').remove();
this.$target.find('img.video_preview').removeClass('hidden');
this.$target.find('img.play_button').removeClass('hidden');
},
});
});