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