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