vendor: 15,090 bytes, lines 1-451
1(function($, window, document, undefined) { 2 3 'use strict'; 4 5 var defaults = { 6 thumbnail: true, 7 8 animateThumb: true, 9 currentPagerPosition: 'middle', 10 11 thumbWidth: 100, 12 thumbContHeight: 100, 13 thumbMargin: 5, 14 15 exThumbImage: false, 16 showThumbByDefault: true, 17 toogleThumb: true, 18 pullCaptionUp: true, 19 20 enableThumbDrag: true, 21 enableThumbSwipe: true, 22 swipeThreshold: 50, 23 24 loadYoutubeThumbnail: true, 25 youtubeThumbSize: 1, 26 27 loadVimeoThumbnail: true, 28 vimeoThumbSize: 'thumbnail_small', 29 30 loadDailymotionThumbnail: true 31 }; 32 33 var Thumbnail = function(element) { 34 35 // get lightGallery core plugin data 36 this.core = $(element).data('lightGallery'); 37 38 // extend module default settings with lightGallery core settings 39 this.core.s = $.extend({}, defaults, this.core.s); 40 41 this.$el = $(element); 42 this.$thumbOuter = null; 43 this.thumbOuterWidth = 0; 44 this.thumbTotalWidth = (this.core.$items.length * (this.core.s.thumbWidth + this.core.s.thumbMargin)); 45 this.thumbIndex = this.core.index; 46 47 // Thumbnail animation value 48 this.left = 0; 49 50 this.init(); 51 52 return this; 53 }; 54 55 Thumbnail.prototype.init = function() { 56 var _this = this; 57 if (this.core.s.thumbnail && this.core.$items.length > 1) { 58 if (this.core.s.showThumbByDefault) { 59 setTimeout(function(){ 60 _this.core.$outer.addClass('lg-thumb-open'); 61 }, 700); 62 } 63 64 if (this.core.s.pullCaptionUp) { 65 this.core.$outer.addClass('lg-pull-caption-up'); 66 } 67 68 this.build(); 69 if (this.core.s.animateThumb) { 70 if (this.core.s.enableThumbDrag && !this.core.isTouch && this.core.doCss()) { 71 this.enableThumbDrag(); 72 } 73 74 if (this.core.s.enableThumbSwipe && this.core.isTouch && this.core.doCss()) { 75 this.enableThumbSwipe(); 76 } 77 78 this.thumbClickable = false; 79 } else { 80 this.thumbClickable = true; 81 } 82 83 this.toogle(); 84 this.thumbkeyPress(); 85 } 86 }; 87 88 Thumbnail.prototype.build = function() { 89 var _this = this; 90 var thumbList = ''; 91 var vimeoErrorThumbSize = ''; 92 var $thumb; 93 var html = '<div class="lg-thumb-outer">' + 94 '<div class="lg-thumb group">' + 95 '</div>' + 96 '</div>'; 97 98 switch (this.core.s.vimeoThumbSize) { 99 case 'thumbnail_large': 100 vimeoErrorThumbSize = '640'; 101 break; 102 case 'thumbnail_medium': 103 vimeoErrorThumbSize = '200x150'; 104 break; 105 case 'thumbnail_small': 106 vimeoErrorThumbSize = '100x75'; 107 } 108 109 _this.core.$outer.addClass('lg-has-thumb'); 110 111 _this.core.$outer.find('.lg').append(html); 112 113 _this.$thumbOuter = _this.core.$outer.find('.lg-thumb-outer'); 114 _this.thumbOuterWidth = _this.$thumbOuter.width(); 115 116 if (_this.core.s.animateThumb) { 117 _this.core.$outer.find('.lg-thumb').css({ 118 width: _this.thumbTotalWidth + 'px', 119 position: 'relative' 120 }); 121 } 122 123 if (this.core.s.animateThumb) { 124 _this.$thumbOuter.css('height', _this.core.s.thumbContHeight + 'px'); 125 } 126 127 function getThumb(src, thumb, index) { 128 var isVideo = _this.core.isVideo(src, index) || {}; 129 var thumbImg; 130 var vimeoId = ''; 131 132 if (isVideo.youtube || isVideo.vimeo || isVideo.dailymotion) { 133 if (isVideo.youtube) { 134 if (_this.core.s.loadYoutubeThumbnail) { 135 thumbImg = '//img.youtube.com/vi/' + isVideo.youtube[1] + '/' + _this.core.s.youtubeThumbSize + '.jpg'; 136 } else { 137 thumbImg = thumb; 138 } 139 } else if (isVideo.vimeo) { 140 if (_this.core.s.loadVimeoThumbnail) { 141 thumbImg = '//i.vimeocdn.com/video/error_' + vimeoErrorThumbSize + '.jpg'; 142 vimeoId = isVideo.vimeo[1]; 143 } else { 144 thumbImg = thumb; 145 } 146 } else if (isVideo.dailymotion) { 147 if (_this.core.s.loadDailymotionThumbnail) { 148 thumbImg = '//www.dailymotion.com/thumbnail/video/' + isVideo.dailymotion[1]; 149 } else { 150 thumbImg = thumb; 151 } 152 } 153 } else { 154 thumbImg = thumb; 155 } 156 157 thumbList += '<div data-vimeo-id="' + vimeoId + '" class="lg-thumb-item" style="width:' + _this.core.s.thumbWidth + 'px; margin-right: ' + _this.core.s.thumbMargin + 'px"><img src="' + thumbImg + '" /></div>'; 158 vimeoId = ''; 159 } 160 161 if (_this.core.s.dynamic) { 162 for (var i = 0; i < _this.core.s.dynamicEl.length; i++) { 163 getThumb(_this.core.s.dynamicEl[i].src, _this.core.s.dynamicEl[i].thumb, i); 164 } 165 } else { 166 _this.core.$items.each(function(i) { 167 168 if (!_this.core.s.exThumbImage) { 169 getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).find('img').attr('src'), i); 170 } else { 171 getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).attr(_this.core.s.exThumbImage), i); 172 } 173 174 }); 175 } 176 177 _this.core.$outer.find('.lg-thumb').html(thumbList); 178 179 $thumb = _this.core.$outer.find('.lg-thumb-item'); 180 181 // Load vimeo thumbnails 182 $thumb.each(function() { 183 var $this = $(this); 184 var vimeoVideoId = $this.attr('data-vimeo-id'); 185 186 if (vimeoVideoId) { 187 $.getJSON('//www.vimeo.com/api/v2/video/' + vimeoVideoId + '.json?callback=?', { 188 format: 'json' 189 }, function(data) { 190 $this.find('img').attr('src', data[0][_this.core.s.vimeoThumbSize]); 191 }); 192 } 193 }); 194 195 // manage active class for thumbnail 196 $thumb.eq(_this.core.index).addClass('active'); 197 _this.core.$el.on('onBeforeSlide.lg.tm', function() { 198 $thumb.removeClass('active'); 199 $thumb.eq(_this.core.index).addClass('active'); 200 }); 201 202 $thumb.on('click.lg touchend.lg', function() { 203 var _$this = $(this); 204 setTimeout(function() { 205 206 // In IE9 and bellow touch does not support 207 // Go to slide if browser does not support css transitions 208 if ((_this.thumbClickable && !_this.core.lgBusy) || !_this.core.doCss()) { 209 _this.core.index = _$this.index(); 210 _this.core.slide(_this.core.index, false, true); 211 } 212 }, 50); 213 }); 214 215 _this.core.$el.on('onBeforeSlide.lg.tm', function() { 216 _this.animateThumb(_this.core.index); 217 }); 218 219 $(window).on('resize.lg.thumb orientationchange.lg.thumb', function() { 220 setTimeout(function() { 221 _this.animateThumb(_this.core.index); 222 _this.thumbOuterWidth = _this.$thumbOuter.width(); 223 }, 200); 224 }); 225 226 }; 227 228 Thumbnail.prototype.setTranslate = function(value) { 229 // jQuery supports Automatic CSS prefixing since jQuery 1.8.0 230 this.core.$outer.find('.lg-thumb').css({ 231 transform: 'translate3d(-' + (value) + 'px, 0px, 0px)' 232 }); 233 }; 234 235 Thumbnail.prototype.animateThumb = function(index) { 236 var $thumb = this.core.$outer.find('.lg-thumb'); 237 if (this.core.s.animateThumb) { 238 var position; 239 switch (this.core.s.currentPagerPosition) { 240 case 'left': 241 position = 0; 242 break; 243 case 'middle': 244 position = (this.thumbOuterWidth / 2) - (this.core.s.thumbWidth / 2); 245 break; 246 case 'right': 247 position = this.thumbOuterWidth - this.core.s.thumbWidth; 248 } 249 this.left = ((this.core.s.thumbWidth + this.core.s.thumbMargin) * index - 1) - position; 250 if (this.left > (this.thumbTotalWidth - this.thumbOuterWidth)) { 251 this.left = this.thumbTotalWidth - this.thumbOuterWidth; 252 } 253 254 if (this.left < 0) { 255 this.left = 0; 256 } 257 258 if (this.core.lGalleryOn) { 259 if (!$thumb.hasClass('on')) { 260 this.core.$outer.find('.lg-thumb').css('transition-duration', this.core.s.speed + 'ms'); 261 } 262 263 if (!this.core.doCss()) { 264 $thumb.animate({ 265 left: -this.left + 'px' 266 }, this.core.s.speed); 267 } 268 } else { 269 if (!this.core.doCss()) { 270 $thumb.css('left', -this.left + 'px'); 271 } 272 } 273 274 this.setTranslate(this.left); 275 276 } 277 }; 278 279 // Enable thumbnail dragging and swiping 280 Thumbnail.prototype.enableThumbDrag = function() { 281 282 var _this = this; 283 var startCoords = 0; 284 var endCoords = 0; 285 var isDraging = false; 286 var isMoved = false; 287 var tempLeft = 0; 288 289 _this.$thumbOuter.addClass('lg-grab'); 290 291 _this.core.$outer.find('.lg-thumb').on('mousedown.lg.thumb', function(e) { 292 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 293 // execute only on .lg-object 294 e.preventDefault(); 295 startCoords = e.pageX; 296 isDraging = true; 297 298 // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723 299 _this.core.$outer.scrollLeft += 1; 300 _this.core.$outer.scrollLeft -= 1; 301 302 // * 303 _this.thumbClickable = false; 304 _this.$thumbOuter.removeClass('lg-grab').addClass('lg-grabbing'); 305 } 306 }); 307 308 $(window).on('mousemove.lg.thumb', function(e) { 309 if (isDraging) { 310 tempLeft = _this.left; 311 isMoved = true; 312 endCoords = e.pageX; 313 314 _this.$thumbOuter.addClass('lg-dragging'); 315 316 tempLeft = tempLeft - (endCoords - startCoords); 317 318 if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) { 319 tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth; 320 } 321 322 if (tempLeft < 0) { 323 tempLeft = 0; 324 } 325 326 // move current slide 327 _this.setTranslate(tempLeft); 328 329 } 330 }); 331 332 $(window).on('mouseup.lg.thumb', function() { 333 if (isMoved) { 334 isMoved = false; 335 _this.$thumbOuter.removeClass('lg-dragging'); 336 337 _this.left = tempLeft; 338 339 if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) { 340 _this.thumbClickable = true; 341 } 342 343 } else { 344 _this.thumbClickable = true; 345 } 346 347 if (isDraging) { 348 isDraging = false; 349 _this.$thumbOuter.removeClass('lg-grabbing').addClass('lg-grab'); 350 } 351 }); 352 353 }; 354 355 Thumbnail.prototype.enableThumbSwipe = function() { 356 var _this = this; 357 var startCoords = 0; 358 var endCoords = 0; 359 var isMoved = false; 360 var tempLeft = 0; 361 362 _this.core.$outer.find('.lg-thumb').on('touchstart.lg', function(e) { 363 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 364 e.preventDefault(); 365 startCoords = e.originalEvent.targetTouches[0].pageX; 366 _this.thumbClickable = false; 367 } 368 }); 369 370 _this.core.$outer.find('.lg-thumb').on('touchmove.lg', function(e) { 371 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 372 e.preventDefault(); 373 endCoords = e.originalEvent.targetTouches[0].pageX; 374 isMoved = true; 375 376 _this.$thumbOuter.addClass('lg-dragging'); 377 378 tempLeft = _this.left; 379 380 tempLeft = tempLeft - (endCoords - startCoords); 381 382 if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) { 383 tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth; 384 } 385 386 if (tempLeft < 0) { 387 tempLeft = 0; 388 } 389 390 // move current slide 391 _this.setTranslate(tempLeft); 392 393 } 394 }); 395 396 _this.core.$outer.find('.lg-thumb').on('touchend.lg', function() { 397 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 398 399 if (isMoved) { 400 isMoved = false; 401 _this.$thumbOuter.removeClass('lg-dragging'); 402 if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) { 403 _this.thumbClickable = true; 404 } 405 406 _this.left = tempLeft; 407 } else { 408 _this.thumbClickable = true; 409 } 410 } else { 411 _this.thumbClickable = true; 412 } 413 }); 414 415 }; 416 417 Thumbnail.prototype.toogle = function() { 418 var _this = this; 419 if (_this.core.s.toogleThumb) { 420 _this.core.$outer.addClass('lg-can-toggle'); 421 _this.$thumbOuter.append('<span class="lg-toogle-thumb lg-icon"></span>'); 422 _this.core.$outer.find('.lg-toogle-thumb').on('click.lg', function() { 423 _this.core.$outer.toggleClass('lg-thumb-open'); 424 }); 425 } 426 }; 427 428 Thumbnail.prototype.thumbkeyPress = function() { 429 var _this = this; 430 $(window).on('keydown.lg.thumb', function(e) { 431 if (e.keyCode === 38) { 432 e.preventDefault(); 433 _this.core.$outer.addClass('lg-thumb-open'); 434 } else if (e.keyCode === 40) { 435 e.preventDefault(); 436 _this.core.$outer.removeClass('lg-thumb-open'); 437 } 438 }); 439 }; 440 441 Thumbnail.prototype.destroy = function() { 442 if (this.core.s.thumbnail && this.core.$items.length > 1) { 443 $(window).off('resize.lg.thumb orientationchange.lg.thumb keydown.lg.thumb'); 444 this.$thumbOuter.remove(); 445 this.core.$outer.removeClass('lg-has-thumb'); 446 } 447 }; 448 449 $.fn.lightGallery.modules.Thumbnail = Thumbnail; 450 451})(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.