Browse Source

[FIX][11.0] website_video_preview travis warn

pull/618/merge
tbaden 1 month ago
parent
commit
eef2fd28bb

+ 24
- 19
website_video_preview/static/src/js/website_video_preview.editor.js View File

@@ -1,12 +1,14 @@
1
-odoo.define('website_video_preview.editor', function(require) {
1
+odoo.define('website_video_preview.editor', function (require) {
2 2
     "use strict";
3 3
 
4 4
     var VideoDialog = require('web_editor.widget').VideoDialog;
5 5
 
6 6
     /**
7
-     * Adds the ability to show a preview of the video instead of loading the player.
7
+     * Adds the ability to show a preview of the video
8
+     * instead of loading the player.
8 9
      *
9
-     * To extend this with other providers you simply have to add a entry in video_preview e.g.::
10
+     * To extend this with other providers
11
+     * you simply have to add a entry in video_preview e.g.::
10 12
      *
11 13
      *     this.video_preview.vim = {
12 14
      *         // 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) {
21 23
         video_review: null,
22 24
 
23 25
         /**
24
-         * @constructor
26
+         * @class
25 27
          * @override
26 28
          */
27
-        init: function() {
29
+        init: function () {
28 30
             this._super.apply(this, arguments);
29 31
             this.video_preview = {
30 32
                 'yt': {
31
-                    'button': '/website_video_preview/static/src/img/yt_button.png',
33
+                    "button": "/website_video_preview/" +
34
+                        "static/src/img/yt_button.png",
32 35
                     'getVideoId': this._getYoutubeVideoId,
33
-                    'getPreviewImage': this._getYoutubePreviewImage
34
-                }
35
-            }
36
+                    'getPreviewImage': this._getYoutubePreviewImage,
37
+                },
38
+            };
36 39
         },
37 40
 
38 41
         /**
39 42
          * @override
40 43
          */
41
-        save: function() {
44
+        save: function () {
42 45
             var res = this._super.apply(this, arguments);
43 46
             var videoId = this.$content.attr('data-video-id');
44 47
             var type = this.$content.attr('data-video-type');
45 48
             if (videoId && type in this.video_preview) {
46
-                var meta = this.video_preview[type];
47 49
 
48 50
                 // Build preview
49 51
                 var $media = $(res);
@@ -63,9 +65,10 @@ odoo.define('website_video_preview.editor', function(require) {
63 65
          * @private
64 66
          * @returns {jQuery}
65 67
          */
66
-        _createPlayButtonNode: function(type) {
68
+        _createPlayButtonNode: function (type) {
67 69
             var meta = this.video_preview[type];
68
-            var $play_button = $('<img class="play_button" src="' + meta.button + '"/>');
70
+            var $play_button = $(
71
+                "<img/>", {"class": "play_button", "src": meta.button});
69 72
             return $play_button;
70 73
         },
71 74
 
@@ -77,7 +80,7 @@ odoo.define('website_video_preview.editor', function(require) {
77 80
          * @private
78 81
          * @returns {jQuery}
79 82
          */
80
-        _createPreviewImageNode: function(type, id) {
83
+        _createPreviewImageNode: function (type, id) {
81 84
             var meta = this.video_preview[type];
82 85
             var $preview_img = $('<img class="video_preview" />');
83 86
             $preview_img.attr('src', meta.getPreviewImage(id));
@@ -92,7 +95,7 @@ odoo.define('website_video_preview.editor', function(require) {
92 95
          * @private
93 96
          * @returns {String}
94 97
          */
95
-        _getYoutubePreviewImage: function(id) {
98
+        _getYoutubePreviewImage: function (id) {
96 99
             return 'https://img.youtube.com/vi/' + id + '/0.jpg';
97 100
         },
98 101
 
@@ -103,8 +106,10 @@ odoo.define('website_video_preview.editor', function(require) {
103 106
          * @private
104 107
          * @returns {String} The video ID
105 108
          */
106
-        _getYoutubeVideoId: function(url) {
107
-            var regex = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
109
+        _getYoutubeVideoId: function (url) {
110
+            var regex = new RegExp(["^(?:(?:https?:)?//)?(?:www.)?",
111
+                "(?:youtu.be/|youtube.com/(?:embed/|v/|",
112
+                "watch?v=|watch?.+&v=))((w|-){11})(?:S+)?$"].join(""));
108 113
             var matches = url.match(regex);
109 114
             return matches[1];
110 115
         },
@@ -112,7 +117,7 @@ odoo.define('website_video_preview.editor', function(require) {
112 117
         /**
113 118
          * @override
114 119
          */
115
-        _createVideoNode: function(url, options) {
120
+        _createVideoNode: function (url, options) {
116 121
             var res = this._super(url, options);
117 122
 
118 123
             if (res.type in this.video_preview) {
@@ -121,6 +126,6 @@ odoo.define('website_video_preview.editor', function(require) {
121 126
                 res.$video.attr('data-video-id', meta.getVideoId(url));
122 127
             }
123 128
             return res;
124
-        }
129
+        },
125 130
     });
126 131
 });

+ 18
- 12
website_video_preview/static/src/js/website_video_preview.frontend.js View File

@@ -1,4 +1,4 @@
1
-odoo.define('website_video_preview.frontend', function(require) {
1
+odoo.define('website_video_preview.frontend', function (require) {
2 2
     "use strict";
3 3
 
4 4
     var registry = require('website.content.snippets.animation').registry;
@@ -9,42 +9,48 @@ odoo.define('website_video_preview.frontend', function(require) {
9 9
             'click .play_button': '_onPlayButtonClick',
10 10
         },
11 11
 
12
-        start: function() {
13
-            var src = this.$target.find('img.video_preview').attr('data-iframe-src');
12
+        start: function () {
13
+            var src = this.$target
14
+                .find('img.video_preview').attr('data-iframe-src');
14 15
             if (!src) {
15 16
                 return this._super.apply(this, arguments);
16 17
             }
17 18
             if (this.editableMode) {
18 19
                 this.stopVideo();
19
-            } else if(src.indexOf('autoplay=1') !== -1) {
20
-                this.playVideo(this.$target.find('img.video_preview').attr('data-iframe-src'));
20
+            } else if (src.indexOf('autoplay=1') !== -1) {
21
+                this.playVideo(
22
+                    this.$target
23
+                        .find('img.video_preview').attr('data-iframe-src'));
21 24
             }
22 25
         },
23 26
 
24
-        _onPlayButtonClick: function(e) {
27
+        _onPlayButtonClick: function (e) {
25 28
             var $img = $(e.currentTarget);
26
-            var src = $img.parent().find('[data-iframe-src]').attr('data-iframe-src');
29
+            var src = $img.parent()
30
+                .find('[data-iframe-src]').attr('data-iframe-src');
27 31
             this.playVideo(src);
28 32
         },
29 33
 
30
-        _onPreviewClick: function(e) {
34
+        _onPreviewClick: function (e) {
31 35
             var $img = $(e.currentTarget);
32 36
             var src = $img.attr('data-iframe-src');
33 37
             this.playVideo(src);
34 38
         },
35 39
 
36
-        playVideo: function(src) {
37
-            var $iframe = $('<iframe class="o_video_dialog_iframe" frameborder="0"></iframe>');
40
+        playVideo: function (src) {
41
+            var $iframe = $(
42
+                "<iframe/>",
43
+                {"class": "o_video_dialog_iframe", "frameborder": 0});
38 44
             $iframe.attr('src', src.replace('autoplay=0', 'autoplay=1'));
39 45
             this.$target.append($iframe);
40 46
             this.$target.find('img.video_preview').addClass('hidden');
41 47
             this.$target.find('img.play_button').addClass('hidden');
42 48
         },
43 49
 
44
-        stopVideo: function() {
50
+        stopVideo: function () {
45 51
             this.$target.find('iframe').remove();
46 52
             this.$target.find('img.video_preview').removeClass('hidden');
47 53
             this.$target.find('img.play_button').removeClass('hidden');
48
-        }
54
+        },
49 55
     });
50 56
 });

Loading…
Cancel
Save