PageSourceSearch

https://xn--54-6kc2e.xn--p1ai/t/images/lg-video.js

js xn--54-6kc2e.xn--p1ai collected 2026-10-07 18:18:11 UTC 13,115 bytes, 335 lines download raw bytes

vendor: 13,115 bytes, lines 1-335
1(function() {
2    
3    'use strict';
4
5    var defaults = {
6        videoMaxWidth: '855px',
7
8        autoplayFirstVideo: true,
9
10        youtubePlayerParams: false,
11        vimeoPlayerParams: false,
12        dailymotionPlayerParams: false,
13        vkPlayerParams: false,
14
15        videojs: false,
16        videojsOptions: {}
17    };
18
19    var Video = function(element) {
20
21        this.core = $(element).data('lightGallery');
22
23        this.$el = $(element);
24        this.core.s = $.extend({}, defaults, this.core.s);
25        this.videoLoaded = false;
26
27        this.init();
28
29        return this;
30    };
31
32    Video.prototype.init = function() {
33        var _this = this;
34
35        // Event triggered when video url found without poster
36        _this.core.$el.on('hasVideo.lg.tm', onHasVideo.bind(this));
37
38        // Set max width for video
39        _this.core.$el.on('onAferAppendSlide.lg.tm', onAferAppendSlide.bind(this));
40
41        if (_this.core.doCss() && (_this.core.$items.length > 1) && (_this.core.s.enableSwipe || _this.core.s.enableDrag)) {
42            _this.core.$el.on('onSlideClick.lg.tm', function() {
43                var $el = _this.core.$slide.eq(_this.core.index);
44                _this.loadVideoOnclick($el);
45            });
46        } else {
47
48            // For IE 9 and bellow
49            _this.core.$slide.on('click.lg', function() {
50                _this.loadVideoOnclick($(this));
51            });
52        }
53
54        _this.core.$el.on('onBeforeSlide.lg.tm', onBeforeSlide.bind(this));
55
56        _this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex) {
57            _this.core.$slide.eq(prevIndex).removeClass('lg-video-playing');
58        });
59        
60        if (_this.core.s.autoplayFirstVideo) {
61            _this.core.$el.on('onAferAppendSlide.lg.tm', function (e, index) {
62                if (!_this.core.lGalleryOn) {
63                    var $el = _this.core.$slide.eq(index);
64                    setTimeout(function () {
65                        _this.loadVideoOnclick($el);
66                    }, 100);
67                }
68            });
69        }
70    };
71
72    Video.prototype.loadVideo = function(src, addClass, noPoster, index, html) {
73        var _this = this;
74        var video = '';
75        var autoplay = 0;
76        var a = '';
77        var isVideo = this.core.isVideo(src, index) || {};
78        var videoTitle;
79
80        if (_this.core.s.dynamic) {
81            videoTitle = _this.core.s.dynamicEl[_this.core.index].title;
82        } else {
83            videoTitle = _this.core.$items.eq(_this.core.index).attr('title') || _this.core.$items.eq(_this.core.index).find('img').first().attr('alt');
84        }
85
86        videoTitle = videoTitle ? 'title="' + videoTitle + '"' : '';
87
88        // Enable autoplay based on setting for first video if poster doesn't exist
89        if (noPoster) {
90            if (this.videoLoaded) {
91                autoplay = 0;
92            } else {
93                autoplay = this.core.s.autoplayFirstVideo ? 1 : 0;
94            }
95        }
96
97        if (isVideo.youtube) {
98
99            a = '?wmode=opaque&autoplay=' + autoplay + '&enablejsapi=1';
100            if (this.core.s.youtubePlayerParams) {
101                a = a + '&' + $.param(this.core.s.youtubePlayerParams);
102            }
103
104            video = '<iframe allow="autoplay" class="lg-video-object lg-youtube ' + addClass + '" ' + videoTitle + ' width="560" height="315" src="//www.youtube.com/embed/' + isVideo.youtube[1] + a + '" frameborder="0" allowfullscreen></iframe>';
105
106        } else if (isVideo.vimeo) {
107
108            a = '?autoplay=' + autoplay;
109            if (this.core.s.vimeoPlayerParams) {
110                a = a + '&' + $.param(this.core.s.vimeoPlayerParams);
111            }
112
113            video = '<iframe allow="autoplay" class="lg-video-object lg-vimeo ' + addClass + '" ' + videoTitle + ' width="560" height="315"  src="//player.vimeo.com/video/' + isVideo.vimeo[1] + a + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
114
115        } else if (isVideo.dailymotion) {
116
117            a = '?wmode=opaque&autoplay=' + autoplay + '&api=postMessage';
118            if (this.core.s.dailymotionPlayerParams) {
119                a = a + '&' + $.param(this.core.s.dailymotionPlayerParams);
120            }
121
122            video = '<iframe allow="autoplay" class="lg-video-object lg-dailymotion ' + addClass + '" ' + videoTitle + ' width="560" height="315" src="//www.dailymotion.com/embed/video/' + isVideo.dailymotion[1] + a + '" frameborder="0" allowfullscreen></iframe>';
123
124        } else if (isVideo.html5) {
125            var fL = html.substring(0, 1);
126            if (fL === '.' || fL === '#') {
127                html = $(html).html();
128            }
129
130            video = html;
131
132        } else if (isVideo.vk) {
133
134            a = '&autoplay=' + autoplay;
135            if (this.core.s.vkPlayerParams) {
136                a = a + '&' + $.param(this.core.s.vkPlayerParams);
137            }
138
139            video = '<iframe allow="autoplay" class="lg-video-object lg-vk ' + addClass + '" ' + videoTitle + ' width="560" height="315" src="//vk.com/video_ext.php?' + isVideo.vk[1] + a + '" frameborder="0" allowfullscreen></iframe>';
140
141        }
142
143        return video;
144    };
145
146    Video.prototype.loadVideoOnclick = function($el){
147
148        var _this = this;
149        // check slide has poster
150        if ($el.find('.lg-object').hasClass('lg-has-poster') && $el.find('.lg-object').is(':visible')) {
151
152            // check already video element present
153            if (!$el.hasClass('lg-has-video')) {
154
155                $el.addClass('lg-video-playing lg-has-video');
156
157                var _src;
158                var _html;
159                var _loadVideo = function(_src, _html) {
160
161                    $el.find('.lg-video').append(_this.loadVideo(_src, '', false, _this.core.index, _html));
162
163                    if (_html) {
164                        if (_this.core.s.videojs) {
165                            try {
166                                videojs(_this.core.$slide.eq(_this.core.index).find('.lg-html5').get(0), _this.core.s.videojsOptions, function() {
167                                    this.play();
168                                });
169                            } catch (e) {
170                                console.error('lightGallery:- Make sure you have included videojs');
171                            }
172                        } else {
173                            _this.core.$slide.eq(_this.core.index).find('.lg-html5').get(0).play();
174                        }
175                    }
176
177                };
178
179                if (_this.core.s.dynamic) {
180
181                    _src = _this.core.s.dynamicEl[_this.core.index].src;
182                    _html = _this.core.s.dynamicEl[_this.core.index].html;
183
184                    _loadVideo(_src, _html);
185
186                } else {
187
188                    _src = _this.core.$items.eq(_this.core.index).attr('href') || _this.core.$items.eq(_this.core.index).attr('data-src');
189                    _html = _this.core.$items.eq(_this.core.index).attr('data-html');
190
191                    _loadVideo(_src, _html);
192
193                }
194
195                var $tempImg = $el.find('.lg-object');
196                $el.find('.lg-video').append($tempImg);
197
198                // @todo loading icon for html5 videos also
199                // for showing the loading indicator while loading video
200                if (!$el.find('.lg-video-object').hasClass('lg-html5')) {
201                    $el.removeClass('lg-complete');
202                    $el.find('.lg-video-object').on('load.lg error.lg', function() {
203                        $el.addClass('lg-complete');
204                    });
205                }
206
207            } else {
208
209                var youtubePlayer = $el.find('.lg-youtube').get(0);
210                var vimeoPlayer = $el.find('.lg-vimeo').get(0);
211                var dailymotionPlayer = $el.find('.lg-dailymotion').get(0);
212                var html5Player = $el.find('.lg-html5').get(0);
213                if (youtubePlayer) {
214                    youtubePlayer.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
215                } else if (vimeoPlayer) {
216                    try {
217                        new Vimeo.Player(vimeoPlayer).play().catch(function(error) {
218                            console.error('error playing the video:', error.name);
219                        });
220                    } catch (e) {
221                        console.warn('lightGallery:- Make sure you have included https://github.com/vimeo/player.js');
222                    }
223                } else if (dailymotionPlayer) {
224                    dailymotionPlayer.contentWindow.postMessage('play', '*');
225
226                } else if (html5Player) {
227                    if (_this.core.s.videojs) {
228                        try {
229                            videojs(html5Player).play();
230                        } catch (e) {
231                            console.error('lightGallery:- Make sure you have included videojs');
232                        }
233                    } else {
234                        html5Player.play();
235                    }
236                }
237
238                $el.addClass('lg-video-playing');
239
240            }
241        }
242    };
243
244    Video.prototype.destroy = function() {
245        this.videoLoaded = false;
246    };
247
248    function onHasVideo(event, index, src, html) {
249        /*jshint validthis:true */
250        var _this = this;
251        _this.core.$slide.eq(index).find('.lg-video').append(_this.loadVideo(src, 'lg-object', true, index, html));
252        if (html) {
253            if (_this.core.s.videojs) {
254                try {
255                    videojs(_this.core.$slide.eq(index).find('.lg-html5').get(0), _this.core.s.videojsOptions, function() {
256                        if (!_this.videoLoaded && _this.core.s.autoplayFirstVideo) {
257                            this.play();
258                        }
259                    });
260                } catch (e) {
261                    console.error('lightGallery:- Make sure you have included videojs');
262                }
263            } else {
264                if(!_this.videoLoaded && _this.core.s.autoplayFirstVideo) {
265                    _this.core.$slide.eq(index).find('.lg-html5').get(0).play();
266                }
267            }
268        }
269    }
270
271    function onAferAppendSlide(event, index) {
272        /*jshint validthis:true */
273        var $videoCont = this.core.$slide.eq(index).find('.lg-video-cont');
274        if (!$videoCont.hasClass('lg-has-iframe')) {
275            $videoCont.css('max-width', this.core.s.videoMaxWidth);
276            this.videoLoaded = true;
277        }
278    }
279
280    function onBeforeSlide(event, prevIndex, index) {
281        /*jshint validthis:true */
282        var _this = this;
283
284        var $videoSlide = _this.core.$slide.eq(prevIndex);
285        var youtubePlayer = $videoSlide.find('.lg-youtube').get(0);
286        var vimeoPlayer = $videoSlide.find('.lg-vimeo').get(0);
287        var dailymotionPlayer = $videoSlide.find('.lg-dailymotion').get(0);
288        var vkPlayer = $videoSlide.find('.lg-vk').get(0);
289        var html5Player = $videoSlide.find('.lg-html5').get(0);
290        if (youtubePlayer) {
291            youtubePlayer.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
292        } else if (vimeoPlayer) {
293            try {
294                new Vimeo.Player(vimeoPlayer).pause().catch(function(error) {
295                    console.error('Unable to pause the video:', error.name);
296                });
297            } catch (e) {
298                console.warn('lightGallery:- Make sure you have included https://github.com/vimeo/player.js');
299            }
300        } else if (dailymotionPlayer) {
301            dailymotionPlayer.contentWindow.postMessage('pause', '*');
302
303        } else if (html5Player) {
304            if (_this.core.s.videojs) {
305                try {
306                    videojs(html5Player).pause();
307                } catch (e) {
308                    console.error('lightGallery:- Make sure you have included videojs');
309                }
310            } else {
311                html5Player.pause();
312            }
313        } if (vkPlayer) {
314            $(vkPlayer).attr('src', $(vkPlayer).attr('src').replace('&autoplay', '&noplay'));
315        }
316
317        var _src;
318        if (_this.core.s.dynamic) {
319            _src = _this.core.s.dynamicEl[index].src;
320        } else {
321            _src = _this.core.$items.eq(index).attr('href') || _this.core.$items.eq(index).attr('data-src');
322
323        }
324
325        var _isVideo = _this.core.isVideo(_src, index) || {};
326        if (_isVideo.youtube || _isVideo.vimeo || _isVideo.dailymotion || _isVideo.vk) {
327            _this.core.$outer.addClass('lg-hide-download');
328        }
329
330    }
331
332	document.addEventListener('DOMContentLoaded', ()=>{
333	    $.fn.lightGallery.modules.video = Video;
334	})
335})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.