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